source: framspy/evolalg/run_numerical_islands_example.py @ 1292

Last change on this file since 1292 was 1289, checked in by Maciej Komosinski, 11 months ago

fitness_set_negative_to_zero boolean (a.k.a. "only positive fitness", needed for novelty and niching diversity control) becomes a command-line flag instead of a hardcoded value

File size: 1.4 KB
Line 
1import numpy as np
2from .numerical_example.numerical_islands_example import ExperimentNumericalIslands
3from .structures.individual import Individual
4
5
6def main():
7    parsed_args = ExperimentNumericalIslands.get_args_for_parser().parse_args()
8    Individual.fitness_set_negative_to_zero = parsed_args.fitness_set_negative_to_zero # setting the "static" field once
9    print("Argument values:", ", ".join(
10        ['%s=%s' % (arg, getattr(parsed_args, arg)) for arg in vars(parsed_args)]))
11
12    initialgenotype = np.array([100, 100, 100, 100])
13    experiment = ExperimentNumericalIslands(
14        hof_size=parsed_args.hof_size,
15        popsize=parsed_args.popsize,
16        migration_interval=parsed_args.generations_migration,
17        number_of_populations=parsed_args.islands,
18        save_only_best=parsed_args.save_only_best)
19
20    hof, stats = experiment.evolve(hof_savefile=parsed_args.hof_savefile,
21                                   generations=parsed_args.generations,
22                                   initialgenotype=initialgenotype,
23                                   pmut=parsed_args.pmut,
24                                   pxov=parsed_args.pxov,
25                                   tournament_size=parsed_args.tournament)
26    print('Best individuals:')
27    for ind in hof:
28        print(ind.rawfitness, '\t-->\t', ind.genotype)
29
30
31if __name__ == "__main__":
32    main()
Note: See TracBrowser for help on using the repository browser.