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)
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 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; }
} 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));
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; }
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));