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_example.py

    r1190 r1289  
     1import numpy as np
    12from .numerical_example.numerical_example import ExperimentNumerical
     3from .structures.individual import Individual
    24
    35
    46def main():
    57    parsed_args = ExperimentNumerical.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
    69    print("Argument values:", ", ".join(
    710        ['%s=%s' % (arg, getattr(parsed_args, arg)) for arg in vars(parsed_args)]))
    811
    9     initialgenotype = [100, 100, 100, 100]
    10     print('Best individuals:')
     12    initialgenotype = np.array([100, 100, 100, 100])
    1113    experiment = ExperimentNumerical(
    1214        hof_size=parsed_args.hof_size,
     
    2022                                   pxov=parsed_args.pxov,
    2123                                   tournament_size=parsed_args.tournament)
    22     print(len(hof))
     24    print('Best individuals:')
    2325    for ind in hof:
    24         print(ind.genotype, ind.rawfitness)
     26        print(ind.rawfitness, '\t-->\t', ind.genotype)
    2527
    2628
Note: See TracChangeset for help on using the changeset viewer.