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_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.