Changeset 1195


Ignore:
Timestamp:
02/01/23 22:58:25 (22 months ago)
Author:
Maciej Komosinski
Message:

Cosmetic

Location:
framspy
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksEvolution.py

    r1191 r1195  
    2121
    2222
    23 def frams_evaluate(frams_cli, individual):
     23def frams_evaluate(frams_lib, individual):
    2424        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")
    2525        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])
    2727        # print("Evaluated '%s'" % genotype, 'evaluation is:', data)
    2828        valid = True
     
    4747
    4848
    49 def frams_crossover(frams_cli, individual1, individual2):
     49def frams_crossover(frams_lib, individual1, individual2):
    5050        geno1 = individual1[0]  # individual[0] because we can't (?) have a simple str as a deap genotype/individual, only list of str.
    5151        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)
    5454        return individual1, individual2
    5555
    5656
    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.
     57def 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.
    5959        return individual,
    6060
    6161
    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)
     62def frams_getsimplest(frams_lib, genetic_format, initial_genotype):
     63        return initial_genotype if initial_genotype is not None else frams_lib.getSimplest(genetic_format)
    6464
    6565
    66 def prepareToolbox(frams_cli, OPTIMIZATION_CRITERIA, tournament_size, genetic_format, initial_genotype):
     66def prepareToolbox(frams_lib, OPTIMIZATION_CRITERIA, tournament_size, genetic_format, initial_genotype):
    6767        creator.create("FitnessMax", base.Fitness, weights=[1.0] * len(OPTIMIZATION_CRITERIA))
    6868        creator.create("Individual", list, fitness=creator.FitnessMax)  # would be nice to have "str" instead of unnecessary "list of str"
    6969
    7070        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"
    7272        # (failed) struggle to have an individual which is a simple str, not a list of str
    7373        # toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_frams)
     
    7878        toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_simplest_genotype, 1)
    7979        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)
    8383        if len(OPTIMIZATION_CRITERIA) <= 1:
    8484                toolbox.register("select", tools.selTournament, tournsize=tournament_size)
     
    9090def parseArguments():
    9191        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 CLI without 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.')
    9494        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 ';'.")
    9595
  • framspy/README.txt

    r1190 r1195  
    55
    66"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.
     7objects in Python. You will find detailed descriptions in the source of this file,
     8but since this file is only responsible for buidling the low-level bridge between
     9Framsticks and Python, understanding and modifying it should not be necessary.
    810
    911"frams-test.py" uses "frams.py" and tests the connection between Python
    1012and 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.
     13operations, so you should run it first to ensure everything works correctly.
     14This file can also be treated as a set of examples and demonstrations on how to access
     15Framsticks genotypes, the simulation, body parts, neurons, etc.
    1216Again, read the comments in the source for more information.
    1317
    14 "FramsticksLib.py" uses "frams.py" and provides a few fundamental building blocks
     18"FramsticksLib.py" uses "frams.py" and provides a few fundamental, high-level building blocks
    1519for optimization: functions to mutate, crossover, evaluate a solution, etc.
    1620
  • framspy/evolalg/base/experiment_niching_abc.py

    r1194 r1195  
    193193                            help="What normalization use for dissimilarity matrix, max (default}, sum and none")
    194194        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")
    196196        return parser
    197197       
  • framspy/frams-test.py

    r1183 r1195  
    106106
    107107matrix = np.zeros((20, 20, 20), dtype=int)  # 3D matrix, "voxels"
    108 m = frams.ModelGeometry.forModel(frams.Model.newFromString(geno));
    109 m.geom_density = 20;
     108m = frams.ModelGeometry.forModel(frams.Model.newFromString(geno))
     109m.geom_density = 20
    110110for p in m.voxels():
    111111        # print('%f %f %f ' % (p.x._value(), p.y._value(), p.z._value()))
Note: See TracChangeset for help on using the changeset viewer.