Ignore:
Timestamp:
01/24/21 13:29:42 (3 years ago)
Author:
Maciej Komosinski
Message:

"Vectorized" mutation for better performance due to decreased time of communication py<->frams (mutate many genotypes in one call)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksEvolution.py

    r1057 r1060  
    1414
    1515def frams_evaluate(frams_cli, individual):
    16         genotype = individual[0]  # [0] because we can't (?) have a simple str as a deap genotype/individual, only list of str.
     16        genotype = individual[0]  # individual[0] because we can't (?) have a simple str as a deap genotype/individual, only list of str.
    1717        data = frams_cli.evaluate([genotype])
    1818        # print("Evaluated '%s'" % genotype, 'evaluation is:', data)
     
    2222                default_evaluation_data = evaluation_data[""]
    2323                fitness = [default_evaluation_data[crit] for crit in OPTIMIZATION_CRITERIA]
    24         except (KeyError, TypeError) as e:  # the evaluation may have failed for invalid genotypes (or some other reason)
    25                 fitness = [-1] * len(OPTIMIZATION_CRITERIA)
     24        except (KeyError, TypeError) as e:  # the evaluation may have failed for an invalid genotype (such as X[@][@] with "Don't simulate genotypes with warnings" option) or for some other reason
     25                fitness = [-1] * len(OPTIMIZATION_CRITERIA)  # fitness of -1 is intended to discourage further propagation of this genotype via selection ("this one is very poor")
    2626                print("Error '%s': could not evaluate genotype '%s', returning fitness %s" % (str(e), genotype, fitness))
    2727        return fitness
     
    2929
    3030def frams_crossover(frams_cli, individual1, individual2):
    31         geno1 = individual1[0]  # [0] because we can't (?) have a simple str as a deap genotype/individual, only list of str.
    32         geno2 = individual2[0]  # [0] because we can't (?) have a simple str as a deap genotype/individual, only list of str.
     31        geno1 = individual1[0]  # individual[0] because we can't (?) have a simple str as a deap genotype/individual, only list of str.
     32        geno2 = individual2[0]  # individual[0] because we can't (?) have a simple str as a deap genotype/individual, only list of str.
    3333        individual1[0] = frams_cli.crossOver(geno1, geno2)
    3434        individual2[0] = frams_cli.crossOver(geno1, geno2)
     
    3737
    3838def frams_mutate(frams_cli, individual):
    39         individual[0] = frams_cli.mutate(individual[0])
     39        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.
    4040        return individual,
    4141
Note: See TracChangeset for help on using the changeset viewer.