Created
October 26, 2023 17:49
-
-
Save esshka/b407fb6dbc27e9505651b653521ad71b to your computer and use it in GitHub Desktop.
base fitness function for NEAT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createFitnessFunction = (dataset, { repeat = 1, cost }) => { | |
return network => { | |
let score = 0 | |
for (let i = 0; i < repeat; i++) { | |
const result = network.test(dataset, cost) | |
if (!result || typeof result.error === 'undefined') { | |
throw new Error('The test method did not return a valid result with an error property.') | |
} | |
score -= result.error | |
} | |
score -= network.topologySize * growthPenalty | |
score = isNaN(score) ? -Infinity : score | |
return score / repeat | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment