[117] | 1 | script:
|
---|
| 2 | name:Evolve for speed vs gravity
|
---|
| 3 | help:Evolve for speed in different gravity settings
|
---|
| 4 | code:~
|
---|
[461] | 5 | function main_args(gravity,min_evaluations)
|
---|
[117] | 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)
|
---|
[480] | 10 | ExpProperties.initialgen="XX[|,1:1][N,1:1,2:1][T][G]";
|
---|
[263] | 11 |
|
---|
| 12 | //custom fitness function: velocity minus small penalty for complexity (high number of parts, joints, neurons, connections)
|
---|
| 13 | GenePools[0].fitness="""
|
---|
| 14 | function penalty(count)
|
---|
[250] | 15 | {
|
---|
[461] | 16 | var MAX_WITHOUT_PENALTY=50;
|
---|
| 17 | var toomany=count-MAX_WITHOUT_PENALTY;
|
---|
| 18 | if (toomany<=0) return 0; else return -toomany*0.001;
|
---|
[250] | 19 | }
|
---|
| 20 | return this.velocity+penalty(this.numparts)+penalty(this.numjoints)+penalty(this.numneurons)+penalty(this.numconnections);""";
|
---|
| 21 |
|
---|
[117] | 22 | Simulator.init();
|
---|
| 23 | //Simulator.print(GenePools[0][0].genotype); //ensure the initialgen is in the gene pool
|
---|
| 24 |
|
---|
| 25 | Simulator.start();
|
---|
[461] | 26 | while (Simulator.running) Simulator.step(); //runs until the experiment stops by itself (due to stagnation detected)
|
---|
| 27 |
|
---|
[117] | 28 | var best=GenePools[0].best();
|
---|
[461] | 29 | Simulator.print("Optimization ends, best: %g (x%g) %s" % best.fit % best.instances % best.genotype);
|
---|
[117] | 30 |
|
---|
[118] | 31 | // Now, since we have indeterminism (default.sim used: random initialization of neural states and random placement of creatures),
|
---|
| 32 | // we cannot trust fitness values that have not been confirmed (averaged) during multiple evaluations.
|
---|
[461] | 33 | // So we start another phase where we wait until the single best genotype is evaluated at least min_evaluations times.
|
---|
[118] | 34 | // No new genotypes are introduced in this phase.
|
---|
[461] | 35 | UserScripts.script_Find_best_genotype_on_average_args(min_evaluations,"best_%g_%u.expt" % gravity % (0+Math.time));
|
---|
[117] | 36 | }
|
---|
| 37 | ~
|
---|