[117] | 1 | script:
|
---|
| 2 | name:Evolve for speed vs gravity
|
---|
| 3 | help:Evolve for speed in different gravity settings
|
---|
| 4 | code:~
|
---|
| 5 | function main(gravity,min_evaluations)
|
---|
| 6 | {
|
---|
| 7 | Math.randomize();
|
---|
| 8 | World.wrldg=gravity;
|
---|
| 9 | Populations[0].perfperiod=100000; //fitness: velocity serves as distance (because sampling period is longer than lifespan)
|
---|
| 10 | ExpParams.initialgen="XX[|,1:1][N,1:1,2:1][T][G]";
|
---|
| 11 |
|
---|
| 12 | Simulator.init();
|
---|
| 13 | //Simulator.print(GenePools[0][0].genotype); //ensure the initialgen is in the gene pool
|
---|
| 14 |
|
---|
| 15 | Simulator.start();
|
---|
| 16 | while (Simulator.running) Simulator.step(); //runs until the experiment stops by itself
|
---|
| 17 | var best=GenePools[0].best();
|
---|
| 18 | Simulator.print("%g (x%g) %s" % best.fit % best.popsiz % best.genotype);
|
---|
| 19 |
|
---|
[118] | 20 | // Now, since we have indeterminism (default.sim used: random initialization of neural states and random placement of creatures),
|
---|
| 21 | // we cannot trust fitness values that have not been confirmed (averaged) during multiple evaluations.
|
---|
| 22 | // So we start another phase where we wait until the best genotype is evaluated at least min_evaluations times.
|
---|
| 23 | // No new genotypes are introduced in this phase.
|
---|
[117] | 24 | ExpParams.stagnation=0; //turn off stagnation detection mechanism
|
---|
| 25 | ExpParams.p_mut=0; //we don't want evolution and new genotypes anymore. We only want to evaluate existing genotypes multiple times
|
---|
| 26 | ExpParams.p_xov=0;
|
---|
| 27 | Simulator.start();
|
---|
| 28 | while (Simulator.running && best.popsiz<min_evaluations) //repeat until the best genotype will be evaluated at least min_evaluations times
|
---|
| 29 | {
|
---|
[184] | 30 | for(var t=best.lifespan; t>0 && Simulator.running; t--)
|
---|
| 31 | Simulator.step(); // simulate 'expected lifespan' steps after which 'best' may have changed. This helps avoid too frequent calls to best()
|
---|
[117] | 32 | best=GenePools[0].best();
|
---|
| 33 | }
|
---|
| 34 | Simulator.stop();
|
---|
| 35 | Simulator.print("%g (x%g) %s" % best.fit % best.popsiz % best.genotype);
|
---|
| 36 | }
|
---|
| 37 | ~
|
---|
| 38 |
|
---|