Changeset 1195 for framspy/FramsticksEvolution.py
- Timestamp:
- 02/01/23 22:58:25 (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/FramsticksEvolution.py
r1191 r1195 21 21 22 22 23 def frams_evaluate(frams_ cli, individual):23 def frams_evaluate(frams_lib, individual): 24 24 BAD_FITNESS = [-1] * len(OPTIMIZATION_CRITERIA) # fitness of -1 is intended to discourage further propagation of this genotype via selection ("this genotype is very poor") 25 25 genotype = individual[0] # individual[0] because we can't (?) have a simple str as a deap genotype/individual, only list of str. 26 data = frams_ cli.evaluate([genotype])26 data = frams_lib.evaluate([genotype]) 27 27 # print("Evaluated '%s'" % genotype, 'evaluation is:', data) 28 28 valid = True … … 47 47 48 48 49 def frams_crossover(frams_ cli, individual1, individual2):49 def frams_crossover(frams_lib, individual1, individual2): 50 50 geno1 = individual1[0] # individual[0] because we can't (?) have a simple str as a deap genotype/individual, only list of str. 51 51 geno2 = individual2[0] # individual[0] because we can't (?) have a simple str as a deap genotype/individual, only list of str. 52 individual1[0] = frams_ cli.crossOver(geno1, geno2)53 individual2[0] = frams_ cli.crossOver(geno1, geno2)52 individual1[0] = frams_lib.crossOver(geno1, geno2) 53 individual2[0] = frams_lib.crossOver(geno1, geno2) 54 54 return individual1, individual2 55 55 56 56 57 def frams_mutate(frams_ cli, individual):58 individual[0] = frams_ cli.mutate([individual[0]])[0] # individual[0] because we can't (?) have a simple str as a deap genotype/individual, only list of str.57 def frams_mutate(frams_lib, individual): 58 individual[0] = frams_lib.mutate([individual[0]])[0] # individual[0] because we can't (?) have a simple str as a deap genotype/individual, only list of str. 59 59 return individual, 60 60 61 61 62 def frams_getsimplest(frams_ cli, genetic_format, initial_genotype):63 return initial_genotype if initial_genotype is not None else frams_ cli.getSimplest(genetic_format)62 def frams_getsimplest(frams_lib, genetic_format, initial_genotype): 63 return initial_genotype if initial_genotype is not None else frams_lib.getSimplest(genetic_format) 64 64 65 65 66 def prepareToolbox(frams_ cli, OPTIMIZATION_CRITERIA, tournament_size, genetic_format, initial_genotype):66 def prepareToolbox(frams_lib, 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" 69 69 70 70 toolbox = base.Toolbox() 71 toolbox.register("attr_simplest_genotype", frams_getsimplest, frams_ cli, genetic_format, initial_genotype) # "Attribute generator"71 toolbox.register("attr_simplest_genotype", frams_getsimplest, frams_lib, genetic_format, initial_genotype) # "Attribute generator" 72 72 # (failed) struggle to have an individual which is a simple str, not a list of str 73 73 # toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_frams) … … 78 78 toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_simplest_genotype, 1) 79 79 toolbox.register("population", tools.initRepeat, list, toolbox.individual) 80 toolbox.register("evaluate", frams_evaluate, frams_ cli)81 toolbox.register("mate", frams_crossover, frams_ cli)82 toolbox.register("mutate", frams_mutate, frams_ cli)80 toolbox.register("evaluate", frams_evaluate, frams_lib) 81 toolbox.register("mate", frams_crossover, frams_lib) 82 toolbox.register("mutate", frams_mutate, frams_lib) 83 83 if len(OPTIMIZATION_CRITERIA) <= 1: 84 84 toolbox.register("select", tools.selTournament, tournsize=tournament_size) … … 90 90 def parseArguments(): 91 91 parser = argparse.ArgumentParser(description='Run this program with "python -u %s" if you want to disable buffering of its output.' % sys.argv[0]) 92 parser.add_argument('-path', type=ensureDir, required=True, help='Path to Framsticks CLIwithout trailing slash.')93 parser.add_argument('-lib', required=False, help='Library name. If not given, "frams-objects.dll" or "frams-objects.so"is assumed depending on the platform.')92 parser.add_argument('-path', type=ensureDir, required=True, help='Path to Framsticks library without trailing slash.') 93 parser.add_argument('-lib', required=False, help='Library name. If not given, "frams-objects.dll" (or .so or .dylib) is assumed depending on the platform.') 94 94 parser.add_argument('-sim', required=False, default="eval-allcriteria.sim", help="The name of the .sim file with settings for evaluation, mutation, crossover, and similarity estimation. If not given, \"eval-allcriteria.sim\" is assumed by default. Must be compatible with the \"standard-eval\" expdef. If you want to provide more files, separate them with a semicolon ';'.") 95 95
Note: See TracChangeset
for help on using the changeset viewer.