Ignore:
Timestamp:
01/15/24 05:43:37 (4 months ago)
Author:
Maciej Komosinski
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/evolalg/run_numerical_islands_example.py

    r1190 r1289  
    1 from .numerical_example.numerical_islands_example import \
    2     ExperimentNumericalIslands
     1import numpy as np
     2from .numerical_example.numerical_islands_example import ExperimentNumericalIslands
     3from .structures.individual import Individual
    34
    45
    56def main():
    67    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
    79    print("Argument values:", ", ".join(
    810        ['%s=%s' % (arg, getattr(parsed_args, arg)) for arg in vars(parsed_args)]))
    911
    10     initialgenotype = [100, 100, 100, 100]
    11     print('Best individuals:')
     12    initialgenotype = np.array([100, 100, 100, 100])
    1213    experiment = ExperimentNumericalIslands(
    1314        hof_size=parsed_args.hof_size,
     
    2324                                   pxov=parsed_args.pxov,
    2425                                   tournament_size=parsed_args.tournament)
    25     print(len(hof))
     26    print('Best individuals:')
    2627    for ind in hof:
    27         print(ind.genotype, ind.rawfitness)
     28        print(ind.rawfitness, '\t-->\t', ind.genotype)
    2829
    2930
Note: See TracChangeset for help on using the changeset viewer.