Changeset 1195
- Timestamp:
- 02/01/23 22:58:25 (21 months ago)
- Location:
- framspy
- Files:
-
- 4 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 -
framspy/README.txt
r1190 r1195 5 5 6 6 "frams.py" is the most fundamental file. It allows to access Framsticks script 7 objects in Python. You will find detailed descriptions in the source of this file. 7 objects in Python. You will find detailed descriptions in the source of this file, 8 but since this file is only responsible for buidling the low-level bridge between 9 Framsticks and Python, understanding and modifying it should not be necessary. 8 10 9 11 "frams-test.py" uses "frams.py" and tests the connection between Python 10 12 and the native Framsticks library by performing a number of simple yet diversified 11 operations, so you should run it first to ensure everything works correctly. 13 operations, so you should run it first to ensure everything works correctly. 14 This file can also be treated as a set of examples and demonstrations on how to access 15 Framsticks genotypes, the simulation, body parts, neurons, etc. 12 16 Again, read the comments in the source for more information. 13 17 14 "FramsticksLib.py" uses "frams.py" and provides a few fundamental building blocks18 "FramsticksLib.py" uses "frams.py" and provides a few fundamental, high-level building blocks 15 19 for optimization: functions to mutate, crossover, evaluate a solution, etc. 16 20 -
framspy/evolalg/base/experiment_niching_abc.py
r1194 r1195 193 193 help="What normalization use for dissimilarity matrix, max (default}, sum and none") 194 194 parser.add_argument("-knn",type= int, default= 0, 195 help="Nearest neighbors parameter for local novelty/niching, if knn==0 global is performed. Default:0")195 help="Nearest neighbors parameter for local novelty/niching, if knn==0 global is performed. Default: 0") 196 196 return parser 197 197 -
framspy/frams-test.py
r1183 r1195 106 106 107 107 matrix = np.zeros((20, 20, 20), dtype=int) # 3D matrix, "voxels" 108 m = frams.ModelGeometry.forModel(frams.Model.newFromString(geno)) ;109 m.geom_density = 20 ;108 m = frams.ModelGeometry.forModel(frams.Model.newFromString(geno)) 109 m.geom_density = 20 110 110 for p in m.voxels(): 111 111 # print('%f %f %f ' % (p.x._value(), p.y._value(), p.z._value()))
Note: See TracChangeset
for help on using the changeset viewer.