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

Method trainC

JSAT/src/jsat/parameters/RandomSearch.java:229–348  ·  view source on GitHub ↗
(final ClassificationDataSet dataSet, final ExecutorService threadPool)

Source from the content-addressed store, hash-verified

227 }
228
229 @Override
230 public void trainC(final ClassificationDataSet dataSet, final ExecutorService threadPool)
231 {
232 final PriorityQueue<ClassificationModelEvaluation> bestModels =
233 new PriorityQueue<ClassificationModelEvaluation>(folds,
234 new Comparator<ClassificationModelEvaluation>()
235 {
236 @Override
237 public int compare(ClassificationModelEvaluation t, ClassificationModelEvaluation t1)
238 {
239 double v0 = t.getScoreStats(classificationTargetScore).getMean();
240 double v1 = t1.getScoreStats(classificationTargetScore).getMean();
241 int order = classificationTargetScore.lowerIsBetter() ? 1 : -1;
242 return order*Double.compare(v0, v1);
243 }
244 });
245
246 /**
247 * Each model is set to have different combination of parameters. We
248 * then train each model to determine the best one.
249 */
250 final List<Classifier> paramsToEval = new ArrayList<Classifier>();
251
252 Random rand = RandomUtil.getRandom();
253 for(int trial = 0; trial < trials; trial++)
254 {
255 for(int i = 0; i < searchParams.size(); i++)
256 {
257 double sampledValue = searchValues.get(i).invCdf(rand.nextDouble());
258
259 Parameter param = searchParams.get(i);
260 if(param instanceof DoubleParameter)
261 ((DoubleParameter)param).setValue(sampledValue);
262 else if(param instanceof IntParameter)
263 ((IntParameter)param).setValue((int) Math.round(sampledValue));
264 }
265
266 paramsToEval.add(baseClassifier.clone());
267 }
268
269 /*
270 * This is the Executor used for training the models in parallel. If we
271 * are not supposed to do that, it will be an executor that executes
272 * them sequentually.
273 */
274 final ExecutorService modelService;
275 if(trainModelsInParallel && threadPool != null)
276 modelService = threadPool;
277 else
278 modelService = new FakeExecutor();
279
280 //if we are doing our CV splits ahead of time, get them done now
281 final List<ClassificationDataSet> preFolded;
282
283 /**
284 * Pre-combine our training combinations so that any caching can be
285 * re-used
286 */

Callers 3

testClassificationMethod · 0.95
testClassificationExMethod · 0.95

Calls 15

getRandomMethod · 0.95
comineAllButMethod · 0.95
trainCMethod · 0.95
cvSetMethod · 0.80
submitMethod · 0.80
getClassifierMethod · 0.80
peekMethod · 0.80
sizeMethod · 0.65
cloneMethod · 0.65
invCdfMethod · 0.45
getMethod · 0.45
nextDoubleMethod · 0.45

Tested by 3

testClassificationMethod · 0.76
testClassificationExMethod · 0.76