@@ -30,16 +30,21 @@ var Neuroevolution = function(options){
3030 } ,
3131
3232 // various factors and parameters (along with default values).
33- population :50 , // population size
34- elitism :0.2 , // elitism factor
35- randomBehaviour :0.2 , // random behaviour factor
36- mutationRate :0.1 , // mutation rate
37- mutationRange :0.5 , // mutation range
38- network :[ 1 , [ 1 ] , 1 ] , // network architecture (1 unit hidden layer)
39- historic :0 , // historic factor
40- lowHistoric :false , // low historic flag
41- scoreSort :- 1 , // score sort value
42- nbChild :1 // number of children
33+ network :[ 1 , [ 1 ] , 1 ] , // Perceptron network structure (1 hidden
34+ // layer).
35+ population :50 , // Population by generation.
36+ elitism :0.2 , // Best networks kepts unchanged for the next
37+ // generation (rate).
38+ randomBehaviour :0.2 , // New random networks for the next generation
39+ // (rate).
40+ mutationRate :0.1 , // Mutation rate on the weights of synapses.
41+ mutationRange :0.5 , // Interval of the mutation changes on the
42+ // synapse weight.
43+ historic :0 , // Latest generations saved.
44+ lowHistoric :false , // Only save score (not the network).
45+ scoreSort :- 1 , // Sort order (-1 = desc, 1 = asc).
46+ nbChild :1 // Number of children by breeding.
47+
4348 }
4449
4550 /**
@@ -298,11 +303,12 @@ var Neuroevolution = function(options){
298303 // Locate position to insert Genome into.
299304 // The gnomes should remain sorted.
300305 for ( var i = 0 ; i < this . genomes . length ; i ++ ) {
301- // Depending on if the sorting ascending or descending.
306+ // Sort in descending order .
302307 if ( self . options . scoreSort < 0 ) {
303308 if ( genome . score > this . genomes [ i ] . score ) {
304309 break ;
305310 }
311+ // Sort in ascending order.
306312 } else {
307313 if ( genome . score < this . genomes [ i ] . score ) {
308314 break ;
@@ -340,9 +346,9 @@ var Neuroevolution = function(options){
340346 for ( var i in data . network . weights ) {
341347 if ( Math . random ( ) <= self . options . mutationRate ) {
342348 data . network . weights [ i ] += Math . random ( )
343- * self . options . mutationRange
344- * 2
345- - self . options . mutationRange ;
349+ * self . options . mutationRange
350+ * 2
351+ - self . options . mutationRange ;
346352 }
347353 }
348354 datas . push ( data ) ;
@@ -387,8 +393,8 @@ var Neuroevolution = function(options){
387393 for ( var c in childs ) {
388394 nexts . push ( childs [ c ] . network ) ;
389395 if ( nexts . length >= self . options . population ) {
390- // Return once number of children is equal to the population
391- // factor .
396+ // Return once number of children is equal to the
397+ // population by generatino value .
392398 return nexts ;
393399 }
394400 }
@@ -429,8 +435,9 @@ var Neuroevolution = function(options){
429435 for ( var i = 0 ; i < self . options . population ; i ++ ) {
430436 // Generate the Network and save it.
431437 var nn = new Network ( ) ;
432- nn . perceptronGeneration ( self . options . network [ 0 ] , self . options . network [ 1 ] ,
433- self . options . network [ 2 ] ) ;
438+ nn . perceptronGeneration ( self . options . network [ 0 ] ,
439+ self . options . network [ 1 ] ,
440+ self . options . network [ 2 ] ) ;
434441 out . push ( nn . getSave ( ) ) ;
435442 }
436443
@@ -510,7 +517,8 @@ var Neuroevolution = function(options){
510517 // Remove old Networks.
511518 if ( self . generations . generations . length >= 2 ) {
512519 var genomes =
513- self . generations . generations [ self . generations . generations . length - 2 ]
520+ self . generations
521+ . generations [ self . generations . generations . length - 2 ]
514522 . genomes ;
515523 for ( var i in genomes ) {
516524 delete genomes [ i ] . network ;
0 commit comments