Created
December 3, 2016 19:28
-
-
Save prabod/73e3a8b0c1dbbadfc9d2b9edb34c3670 to your computer and use it in GitHub Desktop.
Fitness Function
This file contains 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
/** | |
* 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