Skip to content

Instantly share code, notes, and snippets.

@prabod prabod/fitness.js
Created Dec 3, 2016

Embed
What would you like to do?
Fitness Function
/**
* Fitness Function
* fitness = 1 - (Square of pixel difference between chromosome and reference Image)
* ____________________________________________________________________
* ( Resolution of the Image * count(RGBA) * Number of Possible Values)
*
* This fitness function stays inside [0,1]
* */
fitness(width,height){
//Draw the Chromosome First
this.draw(this.ctx,width,height);
var fit = 0;
var imagedata = this.ctx.getImageData(0,0,width,height).data;
for (var i = 0; i < workingData.length;i++){
var dist = workingData[i] - imagedata[i];
fit += dist * dist;
}
this.fitnessValue = 1 - fit / (75 * 75 * 4 * 256 * 256);
return this.fitnessValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.