Skip to content

Instantly share code, notes, and snippets.

@esshka
Created March 23, 2023 22:24
Show Gist options
  • Save esshka/e4b96ffbf748ae0aeff1b21bd1d099b9 to your computer and use it in GitHub Desktop.
Save esshka/e4b96ffbf748ae0aeff1b21bd1d099b9 to your computer and use it in GitHub Desktop.
function calculateFitness(network, data) {
let fitness = 0;
for (const { input, output } of data) {
const prediction = network.propagate(input);
const error = output[0] - prediction[0];
fitness += 1 - Math.abs(error * error);
}
// Normalize the fitness value by dividing it by the number of data points
return fitness / data.length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment