operators.add(new CDCrossover(crosspnts));
operators.add(new CDMutation(mutrate, mutrange, mutprec));
EvolutionPipeline<CDRule> pipeline = new EvolutionPipeline<CDRule>(operators);
// 75 % of the dataset is dedicated to training
DatasetSplit split = new DatasetSplit(0.75);
// Fitness Evaluator (defaults to training)
FitnessEvaluator<? super CDRule> evaluator = new CDFitnessEvaluator(dataset, target, split);
// Selection Strategy
SelectionStrategy<? super CDRule> selection = new RouletteWheelSelection();
EvolutionEngine<CDRule> engine =
new SequentialEvolutionEngine<CDRule>(factory, pipeline, evaluator, selection, RandomUtils.getRandom());
engine.addEvolutionObserver(new EvolutionObserver<CDRule>() {
@Override
public void populationUpdate(PopulationData<? extends CDRule> data) {
log.info("Generation {}", data.getGenerationNumber());
}
});
// evolve the rules over the training set
Rule solution = engine.evolve(popSize, 1, new GenerationCount(genCount));
Path output = new Path("output");
// fitness over the training set
CDFitness bestTrainFit = CDMahoutEvaluator.evaluate(solution, target, inpath, output, split);
// fitness over the testing set
split.setTraining(false);
CDFitness bestTestFit = CDMahoutEvaluator.evaluate(solution, target, inpath, output, split);
// evaluate the solution over the testing set
log.info("Best solution fitness (train set) : {}", bestTrainFit);
log.info("Best solution fitness (test set) : {}", bestTestFit);