1 | script:
|
---|
2 | name:Evolve for speed vs gravity
|
---|
3 | help:Evolve for speed in different gravity settings
|
---|
4 | code:~
|
---|
5 | function main_args(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 | ExpProperties.initialgen="XX[|,1:1][N,1:1,2:1][T][G]";
|
---|
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)
|
---|
15 | {
|
---|
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 | }
|
---|
20 | return this.velocity+penalty(this.numparts)+penalty(this.numjoints)+penalty(this.numneurons)+penalty(this.numconnections);""";
|
---|
21 |
|
---|
22 | Simulator.init();
|
---|
23 | //Simulator.print(GenePools[0][0].genotype); //ensure the initialgen is in the gene pool
|
---|
24 |
|
---|
25 | Simulator.start();
|
---|
26 | while (Simulator.running) Simulator.step(); //runs until the experiment stops by itself (due to stagnation detected)
|
---|
27 |
|
---|
28 | var best=GenePools[0].best();
|
---|
29 | Simulator.print("Optimization ends, best: %g (x%g) %s" % best.fit % best.instances % best.genotype);
|
---|
30 |
|
---|
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.
|
---|
33 | // So we start another phase where we wait until the single best genotype is evaluated at least min_evaluations times.
|
---|
34 | // No new genotypes are introduced in this phase.
|
---|
35 | UserScripts.script_Find_best_genotype_on_average_args(min_evaluations,"best_%g_%u.expt" % gravity % (0+Math.time));
|
---|
36 | }
|
---|
37 | ~
|
---|