Skip to content

Commit

Permalink
preserve sum when inverting scores
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Cheng committed Feb 13, 2013
1 parent c208ec1 commit 8bd290c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/genetic/Task.js
Expand Up @@ -173,12 +173,11 @@ Task.prototype.reproduction = function (callback) {
} }
, function (callback) { , function (callback) {
// invert scores, if we minimize fitness // invert scores, if we minimize fitness
var maxScore = Math.abs(self.statistics.maxScore) var avg = self.statistics.avg
if (self.minimize) { if (self.minimize) {
async.forEach(self.parents async.forEach(self.parents
, function (item, cb) { , function (item, cb) {
item.score*=-1 item.score = avg * 2 - item.score
item.score+=maxScore
process.nextTick(function () {cb()}) process.nextTick(function () {cb()})
} }
, function (err) { , function (err) {
Expand Down

0 comments on commit 8bd290c

Please sign in to comment.