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

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

File:
1 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])
Note: See TracChangeset for help on using the changeset viewer.