Changeset 1290 for framspy/evolalg


Ignore:
Timestamp:
01/15/24 05:45:10 (12 months ago)
Author:
Maciej Komosinski
Message:

Better mutation, crossover, and evaluation function for a simple minimalistic numerical optimization example

Location:
framspy/evolalg/numerical_example
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • framspy/evolalg/numerical_example/numerical_example.py

    r1190 r1290  
    22
    33from ..base.experiment_abc import ExperimentABC
    4 from ..structures.hall_of_fame import HallOfFame
    54
    65
     
    1110                               save_only_best=save_only_best)
    1211
    13     def mutate(self, gen1):
    14         return list(gen1 + np.random.randint(-10, 10, len(gen1)))
     12    def mutate(self, gen):
     13        return gen + np.random.normal(0, 15, len(gen))
    1514
    1615    def cross_over(self, gen1, gen2):
    17         return gen1
     16        a = np.random.uniform()
     17        return a * gen1 + (1.0-a) * gen2
    1818
    19     def evaluate(self, genotype):
    20         return 1/sum([x*x for x in genotype])
     19    def evaluate(self, gen):
     20        return -sum([x*x for x in gen])
  • framspy/evolalg/numerical_example/numerical_islands_example.py

    r1190 r1290  
    1313                                save_only_best=save_only_best)
    1414
    15     def mutate(self, gen1):
    16         return gen1 + np.random.randint(-10, 10, len(gen1))
     15    def mutate(self, gen):
     16        return gen + np.random.normal(0, 15, len(gen))
    1717
    1818    def cross_over(self, gen1, gen2):
    19         return gen1
     19        a = np.random.uniform()
     20        return a * gen1 + (1.0-a) * gen2
    2021
    21     def evaluate(self, genotype):
    22         return 1/sum([x*x for x in genotype])
     22    def evaluate(self, gen):
     23        return -sum([x*x for x in gen])
Note: See TracChangeset for help on using the changeset viewer.