| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void trainC(final ClassificationDataSet dataSet, final ExecutorService threadPool) |
| 111 | { |
| 112 | oneVone = new Classifier[dataSet.getClassSize()][]; |
| 113 | |
| 114 | List<List<DataPoint>> dataByCategory = new ArrayList<List<DataPoint>>(dataSet.getClassSize()); |
| 115 | for(int i = 0; i < dataSet.getClassSize(); i++) |
| 116 | dataByCategory.add(dataSet.getSamples(i)); |
| 117 | |
| 118 | final CountDownLatch latch = new CountDownLatch(oneVone.length*(oneVone.length-1)/2); |
| 119 | |
| 120 | for(int i = 0; i < oneVone.length; i++) |
| 121 | { |
| 122 | oneVone[i] = new Classifier[oneVone.length-i-1]; |
| 123 | |
| 124 | for(int j = 0; j < oneVone.length-i-1; j++) |
| 125 | { |
| 126 | final Classifier curClassifier = baseClassifier.clone(); |
| 127 | |
| 128 | oneVone[i][j] = curClassifier; |
| 129 | final int otherClass = j+i+1; |
| 130 | CategoricalData subPred = new CategoricalData(2); |
| 131 | subPred.setOptionName(dataSet.getPredicting().getOptionName(i), 0); |
| 132 | subPred.setOptionName(dataSet.getPredicting().getOptionName(otherClass), 1); |
| 133 | |
| 134 | final ClassificationDataSet subDataSet = new ClassificationDataSet(dataSet.getNumNumericalVars(), dataSet.getCategories(), subPred); |
| 135 | |
| 136 | //Fill sub data set with the two classes |
| 137 | for(DataPoint dp : dataByCategory.get(i)) |
| 138 | subDataSet.addDataPoint(dp.getNumericalValues(), dp.getCategoricalValues(), 0); |
| 139 | for(DataPoint dp : dataByCategory.get(otherClass)) |
| 140 | subDataSet.addDataPoint(dp.getNumericalValues(), dp.getCategoricalValues(), 1); |
| 141 | |
| 142 | if(!concurrentTrain) |
| 143 | { |
| 144 | if(threadPool != null && !(threadPool instanceof FakeExecutor)) |
| 145 | curClassifier.trainC(subDataSet, threadPool); |
| 146 | else |
| 147 | curClassifier.trainC(subDataSet); |
| 148 | continue; |
| 149 | } |
| 150 | //Else, concurrent |
| 151 | threadPool.submit(new Runnable() { |
| 152 | |
| 153 | @Override |
| 154 | public void run() |
| 155 | { |
| 156 | curClassifier.trainC(subDataSet); |
| 157 | latch.countDown(); |
| 158 | } |
| 159 | }); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if(concurrentTrain) |
| 164 | try |
| 165 | { |
| 166 | latch.await(); |