liquidcarrot / carrot

🥕 Evolutionary Neural Networks in JavaScript
https://liquidcarrot.io/carrot/
MIT License
295 stars 34 forks source link

Moved: mutate() must skip elitist genomes #153

Closed christianechevarria closed 5 years ago

christianechevarria commented 5 years ago

Description

This suggestion has been moved from Neataptic: https://github.com/wagenaartje/neataptic/issues/160

neataptic version: 1.4.7 As commented in the source (neat.js) // Elitist genomes should not be included but code on next line does for (var i = 0; i < this.population.length; i++) {

(includes elitist genomes to roll for mutation) Fixing this improves network performance for me.

I will create a pull request to patch this

It seems like @egtzori already added a pull request so it's something we may want to incorporate into the codebase

Files

Neat.js

christianechevarria commented 5 years ago

The comment that mentions including elitist genomes is misleading as this would most likely refer to .evolve which excludes elitist genomes from mutation for the generation. The relevant code being linked below

''' // Elitism, assumes population is sorted by fitness const elitists = [] for (let i = 0; i < self.elitism; i++) elitists.push(population[i].clone())

// Provenance
const new_population = []
for(let i = 0; i < self.provenance; i++) new_population.push(self.template.clone())

// Breed the next individuals
for (let i = 0; i < self.population_size - self.elitism - self.provenance; i++) {
  new_population.push(self.getOffspring())
}

// Replace the old population with the new population
population = self.population = new_population // not purely functional yet so resorting to this

// Mutate the new population
self.mutate()

// Add the elitists
for (let i = 0; i < elitists.length; i++) population.push(elitists[i])

'''

We may consider adding some type of flag for elitist genomes that may confer some trans-generational survivability (with a decay rate before they are mutated / re-evaluated), but for now will not be implementing changes to the .mutate for loop start index as proposed in the pull-request

Closing this for now