source: experiments/frams/evolve-speed-vs-gravity/data/scripts/evolve-speed-vs-gravity.script @ 599

Last change on this file since 599 was 543, checked in by Maciej Komosinski, 8 years ago

Improved description

File size: 1.7 KB
RevLine 
[117]1script:
2name:Evolve for speed vs gravity
3help:Evolve for speed in different gravity settings
4code:~
[461]5function 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       
[543]31        // Now, since we have indeterminism (default settings used: random initialization of neural states and random placement of creatures),
[118]32        // we cannot trust fitness values that have not been confirmed (averaged) during multiple evaluations.
[543]33        // So we start another phase where we keep evaluating until the single best genotype is evaluated at least min_evaluations times.
[118]34        // No new genotypes are introduced in this phase.
[542]35        UserScripts.script_Find_best_genotype_on_average_args(min_evaluations,"best_%g_%u.expt" % gravity % int(Math.time));
[117]36}
37~
Note: See TracBrowser for help on using the repository browser.