Changeset 461 for experiments/frams/evolve-speed-vs-gravity
- Timestamp:
- 02/03/16 23:10:26 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
experiments/frams/evolve-speed-vs-gravity/data/scripts/evolve-speed-vs-gravity.script
r263 r461 3 3 help:Evolve for speed in different gravity settings 4 4 code:~ 5 function main (gravity,min_evaluations)5 function main_args(gravity,min_evaluations) 6 6 { 7 7 Math.randomize(); … … 12 12 //custom fitness function: velocity minus small penalty for complexity (high number of parts, joints, neurons, connections) 13 13 GenePools[0].fitness=""" 14 var MAX_WITHOUT_PENALTY=50;15 14 function penalty(count) 16 15 { 17 var toomany=count-MAX_WITHOUT_PENALTY; 18 if (toomany<=0) return 0; else return -toomany*0.001; 16 var MAX_WITHOUT_PENALTY=50; 17 var toomany=count-MAX_WITHOUT_PENALTY; 18 if (toomany<=0) return 0; else return -toomany*0.001; 19 19 } 20 20 return this.velocity+penalty(this.numparts)+penalty(this.numjoints)+penalty(this.numneurons)+penalty(this.numconnections);"""; … … 24 24 25 25 Simulator.start(); 26 while (Simulator.running) Simulator.step(); //runs until the experiment stops by itself 26 while (Simulator.running) Simulator.step(); //runs until the experiment stops by itself (due to stagnation detected) 27 27 28 var best=GenePools[0].best(); 28 Simulator.print(" %g (x%g) %s" % best.fit % best.popsiz% best.genotype);29 Simulator.print("Optimization ends, best: %g (x%g) %s" % best.fit % best.instances % best.genotype); 29 30 30 31 // Now, since we have indeterminism (default.sim used: random initialization of neural states and random placement of creatures), 31 32 // we cannot trust fitness values that have not been confirmed (averaged) during multiple evaluations. 32 // So we start another phase where we wait until the best genotype is evaluated at least min_evaluations times.33 // So we start another phase where we wait until the single best genotype is evaluated at least min_evaluations times. 33 34 // No new genotypes are introduced in this phase. 34 ExpParams.stagnation=0; //turn off stagnation detection mechanism 35 ExpParams.p_mut=0; //we don't want evolution and new genotypes anymore. We only want to evaluate existing genotypes multiple times 36 ExpParams.p_xov=0; 37 Simulator.start(); 38 while (Simulator.running && best.popsiz<min_evaluations) //repeat until the best genotype will be evaluated at least min_evaluations times 39 { 40 for(var t=best.lifespan; t>0 && Simulator.running; t--) // simulate 'expected lifespan' steps after which 'best' may have changed. This helps avoid frequent unnecessary calls to best() 41 Simulator.step(); 42 best=GenePools[0].best(); 43 } 44 Simulator.stop(); 45 Simulator.print("%g (x%g) %s" % best.fit % best.popsiz % best.genotype); 46 47 GenePools[0].clear(); //remove all... 48 best.moveTo(GenePools[0]); //...then restore best... 49 Simulator.save("best_%g_%u.expt" % gravity % (0+Math.time)); //...and save it in a file just in case we want to see all of its data 35 UserScripts.script_Find_best_genotype_on_average_args(min_evaluations,"best_%g_%u.expt" % gravity % (0+Math.time)); 50 36 } 51 37 ~ 52
Note: See TracChangeset
for help on using the changeset viewer.