Changeset 1149 for framspy


Ignore:
Timestamp:
09/25/21 01:02:06 (3 years ago)
Author:
Maciej Komosinski
Message:

Added support for loading multiple .sim files where each can overwrite selected settings

Location:
framspy
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksLib.py

    r1119 r1149  
    2424
    2525        GENOTYPE_INVALID = "/*invalid*/"  # this is how genotype invalidity is represented in Framsticks
    26         EVALUATION_SETTINGS_FILE = "eval-allcriteria.sim"  # MUST be compatible with the standard-eval expdef
     26        EVALUATION_SETTINGS_FILE = [  # all files MUST be compatible with the standard-eval expdef. The order they are loaded in is important!
     27                "eval-allcriteria.sim",  # a good trade-off in performance sampling period ("perfperiod") for vertpos and velocity
     28                # "deterministic.sim",  # turns off random noise (added for robustness) so that each evaluation yields identical performance values (causes "overfitting")
     29                # "sample-period-2.sim", # short performance sampling period so performance (e.g. vertical position) is sampled more often
     30                # "sample-period-longest.sim",  # increased performance sampling period so distance and velocity are measured rectilinearly
     31        ]
    2732
    2833
     
    3540        #       return frams
    3641
    37         def __init__(self, frams_path, frams_lib_name, simsettings):
     42        def __init__(self, frams_path, frams_lib_name, sim_settings_files):
    3843                if frams_lib_name is None:
    3944                        frams.init(frams_path)  # could add support for setting alternative directories using -D and -d
     
    5459                        frams.Math.randomize();
    5560                frams.Simulator.expdef = "standard-eval"  # this expdef (or fully compatible) must be used by EVALUATION_SETTINGS_FILE
    56                 if simsettings is not None:
    57                         self.EVALUATION_SETTINGS_FILE = simsettings
    58                 frams.Simulator.ximport(self.EVALUATION_SETTINGS_FILE, 4 + 8 + 16)
     61                if sim_settings_files is not None:
     62                        self.EVALUATION_SETTINGS_FILE = sim_settings_files
     63                print('Using settings:', self.EVALUATION_SETTINGS_FILE)
     64                assert isinstance(self.EVALUATION_SETTINGS_FILE, list)  # ensure settings file(s) are provided as a list
     65                for simfile in self.EVALUATION_SETTINGS_FILE:
     66                        frams.Simulator.ximport(simfile, 4 + 8 + 16)
    5967
    6068
  • framspy/eval-allcriteria.sim

    r1114 r1149  
    33# Other important parameters are "Energy0" and "perfperiod".
    44# Put this file in the "data" subdirectory within the Framsticks distribution.
     5
    56sim_params:
    67stop_on:2
     
    361362name:Genotypes
    362363fitness:return 0.0+this.velocity*1.0;
     364fitness_step_limit:0
     365fitness_time_limit:0.0
     366fitness_allowed_objs:
    363367fitfun:0
    364368fitm:2.0
  • framspy/evolalg/examples/multicriteria.py

    r1148 r1149  
    6666                        help='Genetic format for the demo run, for example 4, 9, or B. If not given, f1 is assumed.')
    6767    parser.add_argument('-sim', required=False, default="eval-allcriteria.sim",
    68                         help="Name of the .sim file with all parameter values")
     68                        help="Name of the .sim file with all parameter values. If you want to provide more files, separate them with a semicolon ';'.")
    6969    parser.add_argument('-dissim', required=False, type=Dissim, default=Dissim.frams,
    7070                        help='Dissimilarity measure, default: frams', choices=list(Dissim))
     
    168168def create_experiment():
    169169    parsed_args = parseArguments()
    170     frams_lib = FramsticksLib(parsed_args.path, parsed_args.lib, parsed_args.sim)
     170    frams_lib = FramsticksLib(parsed_args.path, parsed_args.lib, parsed_args.sim.split(";"))
    171171
    172172    opt_dissim = []
     
    311311    if parsed_args.checkpoint_path is not None and os.path.exists(parsed_args.checkpoint_path):
    312312        experiment = load_experiment(parsed_args.checkpoint_path)
    313         FramsticksLib(parsed_args.path, parsed_args.lib, parsed_args.sim)
    314313    else:
    315314        experiment = create_experiment()
  • framspy/evolalg/examples/niching_novelty.py

    r1146 r1149  
    6363    parser.add_argument('-genformat', required=False, default="1",
    6464                        help='Genetic format for the demo run, for example 4, 9, or B. If not given, f1 is assumed.')
    65     parser.add_argument('-sim', required=False, default="eval-allcriteria.sim", help="Name of the .sim file with all parameter values")
     65    parser.add_argument('-sim', required=False, default="eval-allcriteria.sim", help="Name of the .sim file with all parameter values. If you want to provide more files, separate them with a semicolon ';'.")
    6666    parser.add_argument('-fit', required=False, default=Fitness.raw, type=Fitness,
    6767                        help=' Fitness criteria, default: raw', choices=list(Fitness))
     
    166166    parsed_args = parseArguments()
    167167    frams_lib = FramsticksLib(parsed_args.path, parsed_args.lib,
    168                           parsed_args.sim)
     168                          parsed_args.sim.split(";"))
    169169    # Steps for generating first population
    170170    init_stages = [
     
    332332    if parsed_args.checkpoint_path is not None and os.path.exists(parsed_args.checkpoint_path):
    333333        experiment = load_experiment(parsed_args.checkpoint_path)
    334         FramsticksLib(parsed_args.path, parsed_args.lib,
    335                       parsed_args.sim)
    336334    else:
    337335        experiment = create_experiment()
    338336        experiment.init()  # init is mandatory
    339 
    340337
    341338    experiment.run(parsed_args.generations)
  • framspy/evolalg/examples/standard.py

    r1146 r1149  
    4646    parser.add_argument('-genformat', required=False, default="1",
    4747                        help='Genetic format for the demo run, for example 4, 9, or B. If not given, f1 is assumed.')
    48     parser.add_argument('-sim', required=False, default="eval-allcriteria.sim", help="Name of the .sim file with all parameter values")
     48    parser.add_argument('-sim', required=False, default="eval-allcriteria.sim", help="Name of the .sim file with all parameter values. If you want to provide more files, separate them with a semicolon ';'.")
    4949    parser.add_argument("-popsize", type=int, default=50, help="Population size, default 50.")
    5050    parser.add_argument('-generations', type=int, default=5, help="Number of generations, default 5.")
     
    6666def main():
    6767    parsed_args = parseArguments()
    68     frams_lib = FramsticksLib(parsed_args.path, parsed_args.lib, parsed_args.sim)
     68    frams_lib = FramsticksLib(parsed_args.path, parsed_args.lib, parsed_args.sim.split(";"))
    6969
    7070    hall_of_fame = HallOfFameStatistics(parsed_args.hof_size, "fitness")
  • framspy/run-evolalg-examples.cmd

    r1147 r1149  
    1 rem To learn about all available options of each .py algorithm, add "-h" to its parameters.
     1rem To learn about all available options of each .py algorithm below, add "-h" to its parameters.
    22rem Use the source code of the examples as a starting point for your customizations.
    33rem Example usage:
     
    66
    77
     8
     9rem simple one-criterion evolution
    810python -m evolalg.examples.standard          -path %DIR_WITH_FRAMS_LIBRARY%   -opt numneurons
    911
     12
     13rem "chaining" .sim files, subsequent files overwrite selected parameters
     14python -m evolalg.examples.standard          -path %DIR_WITH_FRAMS_LIBRARY%   -sim eval-allcriteria.sim;deterministic.sim;sample-period-longest.sim    -opt velocity
     15
     16
     17rem hard limit on the number of parts
    1018python -m evolalg.examples.niching_novelty   -path %DIR_WITH_FRAMS_LIBRARY%   -opt velocity   -max_numparts 6   -debug
    1119
     20
     21rem "local" niching
    1222python -m evolalg.examples.niching_novelty   -path %DIR_WITH_FRAMS_LIBRARY%   -opt vertpos    -fit knn_niching  -knn 3    -max_numjoints 8 -popsize 10 -generations 30
    1323
    14 rem '-dissim ...' can be used to include dissimilarity as one of the criteria
     24
     25rem two criteria, '-dissim ...' can also be used to include dissimilarity as one of the criteria
    1526python -m evolalg.examples.multicriteria     -path %DIR_WITH_FRAMS_LIBRARY%   -popsize 40 -generations 10 -opt velocity,vertpos
Note: See TracChangeset for help on using the changeset viewer.