def test_best(): problem = Counter() pop = evolution.Population(lambda: ClassicGRN(), problem.nin, problem.nout) pop.evaluate(problem) assert problem.count == config.POPULATION_SIZE pop.speciation() best_fit, best_ind = pop.get_best() assert problem.count == config.POPULATION_SIZE assert best_fit > 0
def test_speciation(): problem = Counter() config.INITIALIZATION_DUPLICATION = 8 pop = evolution.Population(lambda: ClassicGRN(), problem.nin, problem.nout) pop.evaluate(problem) pop.speciation() assert len(pop.offspring) == 0 assert len(pop.species) > 0 print([len(sp.individuals) for sp in pop.species]) assert problem.count == config.POPULATION_SIZE
def test_fit_increase(): problem = Counter() problem.cacheable = True evo = Evolution(problem, lambda: ClassicGRN()) evo.step() assert np.any([sp.sum_adjusted_fitness > 0.0 for sp in evo.population.species]) best_fit, best_ind = evo.population.get_best() evo.run(10) new_best_fit, new_best_ind = evo.population.get_best() assert np.any([sp.sum_adjusted_fitness > 0.0 for sp in evo.population.species]) assert new_best_fit >= best_fit
def test_make_offspring(): problem = Counter() config.INITIALIZATION_DUPLICATION = 8 pop = evolution.Population(lambda: ClassicGRN(), problem.nin, problem.nout) pop.evaluate(problem) pop.speciation() pop.adjust_thresholds() pop.set_offspring_count() pop.make_offspring() assert problem.count == config.POPULATION_SIZE assert len(pop.offspring) == config.POPULATION_SIZE assert np.any([ind.evaluated for ind in pop.offspring]) assert np.any([~ind.evaluated for ind in pop.offspring])
def test_noncacheable_counter(): problem = Counter() problem.cacheable = False evo = Evolution(problem, lambda: ClassicGRN()) evo.step() assert np.any([sp.sum_adjusted_fitness > 0.0 for sp in evo.population.species]) assert problem.count == config.POPULATION_SIZE evo.step() assert np.any([sp.sum_adjusted_fitness > 0.0 for sp in evo.population.species]) assert problem.count == 2 * config.POPULATION_SIZE evo.step() assert np.any([sp.sum_adjusted_fitness > 0.0 for sp in evo.population.species]) assert problem.count == 3 * config.POPULATION_SIZE
def test_init(): problem = Counter() pop = evolution.Population(lambda: ClassicGRN(), problem.nin, problem.nout) assert len(pop.offspring) == config.POPULATION_SIZE assert len(pop.species) == 0
def test_evaluation(): problem = Counter() pop = evolution.Population(lambda: ClassicGRN(), problem.nin, problem.nout) pop.evaluate(problem) assert problem.count == config.POPULATION_SIZE