final CalculateScore score = new TrainingSetScore(new BasicMLDataSet(FAKE_DATA, FAKE_DATA));
// create a new random population and train it
NEATPopulation pop = new NEATPopulation(FAKE_DATA[0].length, 1, 50);
pop.reset();
EvolutionaryAlgorithm training1 = NEATUtil.constructNEATTrainer(pop, score);
training1.iteration();
// enough training for now, backup current population to continue later
final ByteArrayOutputStream serialized1 = new ByteArrayOutputStream();
new PersistNEATPopulation().save(serialized1, training1.getPopulation());
// reload initial backup and continue training
EvolutionaryAlgorithm training2 = NEATUtil.constructNEATTrainer(
(NEATPopulation)new PersistNEATPopulation().read(new ByteArrayInputStream(serialized1.toByteArray())),
score);
training2.iteration();
// enough training, backup the reloaded population to continue later
final ByteArrayOutputStream serialized2 = new ByteArrayOutputStream();
new PersistNEATPopulation().save(serialized2, training2.getPopulation());
// NEATTraining.init() randomly fails with a NPE in NEATGenome.getCompatibilityScore()
EvolutionaryAlgorithm training3 = NEATUtil.constructNEATTrainer(
(NEATPopulation)new PersistNEATPopulation().read(new ByteArrayInputStream(serialized2.toByteArray())),
score);
training3.iteration();
final ByteArrayOutputStream serialized3 = new ByteArrayOutputStream();
new PersistNEATPopulation().save(serialized3, training3.getPopulation());
}