public static void init(int poolSize) { singleton = new MyThreadPool(poolSize); } public int size()
public WorkerThread[] execute(final WorkerThread worker, final int nTasks) { final MyThreadPool p = MyThreadPool.getInstance(); final int[] partition = p.partition(nTasks); final WorkerThread[] workers = new WorkerThread[partition.length - 1]; for (int i = 0; i < partition.length - 1; i++) { final WorkerThread w = worker.clone(); w.set(partition[i], partition[i + 1] - 1); workers[i] = w; p.execute(w); } await(); return workers; }
public static MyThreadPool getInstance() { if (singleton == null) { init(Runtime.getRuntime().availableProcessors()); } return singleton; }
protected void update(final double[] labels) { sumResponse = 0; sqSumResponse = 0; final MyThreadPool p = MyThreadPool.getInstance(); if (p.size() == 1) { update(labels, 0, features.length - 1); } else { p.execute(new Worker(this, labels), features.length); } }
nThread = Runtime.getRuntime().availableProcessors(); MyThreadPool.init(nThread); MyThreadPool.getInstance().shutdown();
protected void update(double[] labels) { sumResponse = 0; sqSumResponse = 0; MyThreadPool p = MyThreadPool.getInstance(); if(p.size() == 1) update(labels, 0, features.length-1); else p.execute(new Worker(this, labels), features.length); } protected void update(double[] labels, int start, int end)
MyThreadPool.init(nThread); MyThreadPool.getInstance().shutdown();
public WorkerThread[] execute(WorkerThread worker, int nTasks) { MyThreadPool p = MyThreadPool.getInstance(); int[] partition = p.partition(nTasks); WorkerThread[] workers = new WorkerThread[partition.length-1]; for(int i=0;i<partition.length-1;i++) { WorkerThread w = worker.clone(); w.set(partition[i], partition[i+1]-1); workers[i] = w; p.execute(w); } await(); return workers; }
public void construct(final DataPoint[] samples, final double[] labels, final int[][] sampleSortedIdx, final int[] features, final float[][] thresholds, final double[] impacts) { this.features = features; this.thresholds = thresholds; this.impacts = impacts; sumResponse = 0; sqSumResponse = 0; sum = new double[features.length][]; count = new int[features.length][]; sampleToThresholdMap = new int[features.length][]; final MyThreadPool p = MyThreadPool.getInstance(); if (p.size() == 1) { construct(samples, labels, sampleSortedIdx, thresholds, 0, features.length - 1); } else { p.execute(new Worker(this, samples, labels, sampleSortedIdx, thresholds), features.length); } }
public static MyThreadPool getInstance() { if(singleton == null) init(Runtime.getRuntime().availableProcessors()); return singleton; }
public static void init(final int poolSize) { singleton = new MyThreadPool(poolSize); }
protected void computePseudoResponses() { Arrays.fill(pseudoResponses, 0F); Arrays.fill(weights, 0); final MyThreadPool p = MyThreadPool.getInstance(); if (p.size() == 1) { computePseudoResponses(0, samples.size() - 1, 0); } else //multi-threading { final List<LambdaComputationWorker> workers = new ArrayList<>(); //divide the entire dataset into chunks of equal size for each worker thread final int[] partition = p.partition(samples.size()); int current = 0; for (int i = 0; i < partition.length - 1; i++) { //execute the worker final LambdaComputationWorker wk = new LambdaComputationWorker(this, partition[i], partition[i + 1] - 1, current); workers.add(wk);//keep it so we can get back results from it later on p.execute(wk); if (i < partition.length - 2) { for (int j = partition[i]; j <= partition[i + 1] - 1; j++) { current += samples.get(j).size(); } } } //wait for all workers to complete before we move on to the next stage p.await(); } }
public void construct(FeatureHistogram parent, int[] soi, double[] labels) { this.features = parent.features; this.thresholds = parent.thresholds; sumResponse = 0; sqSumResponse = 0; sum = new double[features.length][]; count = new int[features.length][]; sampleToThresholdMap = parent.sampleToThresholdMap; MyThreadPool p = MyThreadPool.getInstance(); if(p.size() == 1) construct(parent, soi, labels, 0, features.length-1); else p.execute(new Worker(this, parent, soi, labels), features.length); } protected void construct(FeatureHistogram parent, int[] soi, double[] labels, int start, int end)
protected void computePseudoResponses() { Arrays.fill(pseudoResponses, 0F); Arrays.fill(weights, 0); MyThreadPool p = MyThreadPool.getInstance(); if(p.size() == 1)//single-thread computePseudoResponses(0, samples.size()-1, 0); else //multi-threading { List<LambdaComputationWorker> workers = new ArrayList<LambdaMART.LambdaComputationWorker>(); //divide the entire dataset into chunks of equal size for each worker thread int[] partition = p.partition(samples.size()); int current = 0; for(int i=0;i<partition.length-1;i++) { //execute the worker LambdaComputationWorker wk = new LambdaComputationWorker(this, partition[i], partition[i+1]-1, current); workers.add(wk);//keep it so we can get back results from it later on p.execute(wk); if(i < partition.length-2) for(int j=partition[i]; j<=partition[i+1]-1;j++) current += samples.get(j).size(); } //wait for all workers to complete before we move on to the next stage p.await(); } } protected void computePseudoResponses(int start, int end, int current)
public void construct(final FeatureHistogram parent, final int[] soi, final double[] labels) { this.features = parent.features; this.thresholds = parent.thresholds; this.impacts = parent.impacts; sumResponse = 0; sqSumResponse = 0; sum = new double[features.length][]; count = new int[features.length][]; sampleToThresholdMap = parent.sampleToThresholdMap; final MyThreadPool p = MyThreadPool.getInstance(); if (p.size() == 1) { construct(parent, soi, labels, 0, features.length - 1); } else { p.execute(new Worker(this, parent, soi, labels), features.length); } }
final MyThreadPool p = MyThreadPool.getInstance(); if (p.size() == 1) { sortSamplesByFeature(0, features.length - 1); } else//multi-thread final int[] partition = p.partition(features.length); for (int i = 0; i < partition.length - 1; i++) { p.execute(new SortWorker(this, partition[i], partition[i + 1] - 1)); p.await();
public void construct(DataPoint[] samples, double[] labels, int[][] sampleSortedIdx, int[] features, float[][] thresholds) { this.features = features; this.thresholds = thresholds; sumResponse = 0; sqSumResponse = 0; sum = new double[features.length][]; count = new int[features.length][]; sampleToThresholdMap = new int[features.length][]; MyThreadPool p = MyThreadPool.getInstance(); if(p.size() == 1) construct(samples, labels, sampleSortedIdx, thresholds, 0, features.length-1); else p.execute(new Worker(this, samples, labels, sampleSortedIdx, thresholds), features.length); } protected void construct(DataPoint[] samples, double[] labels, int[][] sampleSortedIdx, float[][] thresholds, int start, int end)
MyThreadPool p = MyThreadPool.getInstance(); if(p.size() == 1)//single-thread sortSamplesByFeature(0, features.length-1); else//multi-thread int[] partition = p.partition(features.length); for(int i=0;i<partition.length-1;i++) p.execute(new SortWorker(this, partition[i], partition[i+1]-1)); p.await();
public void construct(final FeatureHistogram parent, final FeatureHistogram leftSibling, final boolean reuseParent) { this.reuseParent = reuseParent; this.features = parent.features; this.thresholds = parent.thresholds; this.impacts = parent.impacts; sumResponse = parent.sumResponse - leftSibling.sumResponse; sqSumResponse = parent.sqSumResponse - leftSibling.sqSumResponse; if (reuseParent) { sum = parent.sum; count = parent.count; } else { sum = new double[features.length][]; count = new int[features.length][]; } sampleToThresholdMap = parent.sampleToThresholdMap; final MyThreadPool p = MyThreadPool.getInstance(); if (p.size() == 1) { construct(parent, leftSibling, 0, features.length - 1); } else { p.execute(new Worker(this, parent, leftSibling), features.length); } }
public void construct(FeatureHistogram parent, FeatureHistogram leftSibling, boolean reuseParent) { this.reuseParent = reuseParent; this.features = parent.features; this.thresholds = parent.thresholds; sumResponse = parent.sumResponse - leftSibling.sumResponse; sqSumResponse = parent.sqSumResponse - leftSibling.sqSumResponse; if(reuseParent) { sum = parent.sum; count = parent.count; } else { sum = new double[features.length][]; count = new int[features.length][]; } sampleToThresholdMap = parent.sampleToThresholdMap; MyThreadPool p = MyThreadPool.getInstance(); if(p.size() == 1) construct(parent, leftSibling, 0, features.length-1); else p.execute(new Worker(this, parent, leftSibling), features.length); } protected void construct(FeatureHistogram parent, FeatureHistogram leftSibling, int start, int end)