| 179 | } |
| 180 | |
| 181 | private void doTraining(ExecutorService threadPool, DataSet dataSet) throws FailedToFitException |
| 182 | { |
| 183 | forrest = new ExtraTree[forrestSize]; |
| 184 | int chunkSize = forrestSize/SystemInfo.LogicalCores; |
| 185 | int extra = forrestSize%SystemInfo.LogicalCores; |
| 186 | |
| 187 | int planted = 0; |
| 188 | |
| 189 | CountDownLatch latch = new CountDownLatch(SystemInfo.LogicalCores); |
| 190 | while(planted < forrestSize) |
| 191 | { |
| 192 | int start = planted; |
| 193 | int end = start+chunkSize; |
| 194 | if(extra-- > 0) |
| 195 | end++; |
| 196 | planted = end; |
| 197 | threadPool.submit(new ForrestPlanter(start, end, dataSet, latch)); |
| 198 | } |
| 199 | |
| 200 | try |
| 201 | { |
| 202 | latch.await(); |
| 203 | } |
| 204 | catch (InterruptedException ex) |
| 205 | { |
| 206 | throw new FailedToFitException(ex); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | private class ForrestPlanter implements Runnable |
| 211 | { |