MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / trainC

Method trainC

JSAT/src/jsat/classifiers/OneVSOne.java:109–175  ·  view source on GitHub ↗
(final ClassificationDataSet dataSet, final ExecutorService threadPool)

Source from the content-addressed store, hash-verified

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

Callers 1

testCloneMethod · 0.95

Calls 15

setOptionNameMethod · 0.95
addDataPointMethod · 0.95
trainCMethod · 0.95
getClassSizeMethod · 0.80
getOptionNameMethod · 0.80
getPredictingMethod · 0.80
getNumNumericalVarsMethod · 0.80
getCategoriesMethod · 0.80
getNumericalValuesMethod · 0.80
getCategoricalValuesMethod · 0.80
submitMethod · 0.80
logMethod · 0.80

Tested by 1

testCloneMethod · 0.76