- Timestamp:
- 12/11/22 16:07:08 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/FramsticksEvolution.py
r1163 r1191 64 64 65 65 66 def prepareToolbox(frams_cli, tournament_size, genetic_format, initial_genotype):66 def prepareToolbox(frams_cli, OPTIMIZATION_CRITERIA, tournament_size, genetic_format, initial_genotype): 67 67 creator.create("FitnessMax", base.Fitness, weights=[1.0] * len(OPTIMIZATION_CRITERIA)) 68 68 creator.create("Individual", list, fitness=creator.FitnessMax) # would be nice to have "str" instead of unnecessary "list of str" … … 134 134 135 135 136 if __name__ == "__main__": 136 def main(): 137 global parsed_args, OPTIMIZATION_CRITERIA # needed in frams_evaluate(), so made global to avoid passing as arguments 138 137 139 # random.seed(123) # see FramsticksLib.DETERMINISTIC below, set to True if you want full determinism 138 140 FramsticksLib.DETERMINISTIC = False # must be set before FramsticksLib() constructor call 139 141 parsed_args = parseArguments() 140 142 print("Argument values:", ", ".join(['%s=%s' % (arg, getattr(parsed_args, arg)) for arg in vars(parsed_args)])) 141 142 143 OPTIMIZATION_CRITERIA = parsed_args.opt.split(",") 143 144 framsLib = FramsticksLib(parsed_args.path, parsed_args.lib, parsed_args.sim.split(";")) 144 145 toolbox = prepareToolbox(framsLib, parsed_args.tournament, '1' if parsed_args.genformat is None else parsed_args.genformat, parsed_args.initialgenotype) 146 145 toolbox = prepareToolbox(framsLib, OPTIMIZATION_CRITERIA, parsed_args.tournament, '1' if parsed_args.genformat is None else parsed_args.genformat, parsed_args.initialgenotype) 147 146 pop = toolbox.population(n=parsed_args.popsize) 148 147 hof = tools.HallOfFame(parsed_args.hof_size) … … 152 151 stats.register("min", np.min) 153 152 stats.register("max", np.max) 154 155 153 pop, log = algorithms.eaSimple(pop, toolbox, cxpb=parsed_args.pxov, mutpb=parsed_args.pmut, ngen=parsed_args.generations, stats=stats, halloffame=hof, verbose=True) 156 154 print('Best individuals:') 157 155 for ind in hof: 158 156 print(ind.fitness, '\t-->\t', ind[0]) 159 160 157 if parsed_args.hof_savefile is not None: 161 158 save_genotypes(parsed_args.hof_savefile, OPTIMIZATION_CRITERIA, hof) 159 160 161 if __name__ == "__main__": 162 main()
Note: See TracChangeset
for help on using the changeset viewer.