From 3104ee9d4febbca9968de5f6f8db1ac7334e937d Mon Sep 17 00:00:00 2001 From: Karine Date: Tue, 6 Aug 2019 19:50:32 +0200 Subject: [PATCH 01/45] plasticoding turtle changes --- experiments/karines_experiments/manager_pop.py | 4 +--- .../karines_experiments/manager_pop_lava.py | 4 +--- .../karines_experiments/watch_best_robots.py | 4 +++- pyrevolve/evolution/individual.py | 2 +- pyrevolve/genotype/plasticoding/plasticoding.py | 14 ++++++++++---- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/experiments/karines_experiments/manager_pop.py b/experiments/karines_experiments/manager_pop.py index 31f8c91f69..de8095bae7 100755 --- a/experiments/karines_experiments/manager_pop.py +++ b/experiments/karines_experiments/manager_pop.py @@ -28,9 +28,7 @@ async def run(): population_size = 100 offspring_size = 50 - genotype_conf = PlasticodingConfig( - max_structural_modules=100, - ) + genotype_conf = PlasticodingConfig() mutation_conf = MutationConfig( mutation_prob=0.8, diff --git a/experiments/karines_experiments/manager_pop_lava.py b/experiments/karines_experiments/manager_pop_lava.py index 442889dcca..457bce29e6 100755 --- a/experiments/karines_experiments/manager_pop_lava.py +++ b/experiments/karines_experiments/manager_pop_lava.py @@ -28,9 +28,7 @@ async def run(): population_size = 100 offspring_size = 50 - genotype_conf = PlasticodingConfig( - max_structural_modules=100, - ) + genotype_conf = PlasticodingConfig() mutation_conf = MutationConfig( mutation_prob=0.8, diff --git a/experiments/karines_experiments/watch_best_robots.py b/experiments/karines_experiments/watch_best_robots.py index cf926fc5e9..6783433897 100755 --- a/experiments/karines_experiments/watch_best_robots.py +++ b/experiments/karines_experiments/watch_best_robots.py @@ -76,13 +76,15 @@ async def run(): # define a criteria here #values.append(ind.fitness) values.append(ind.phenotype._behavioural_measurements.contacts) + # values.append(ind.phenotype._behavioural_measurements.displacement_velocity_hill) values = np.array(values) ini = len(population.individuals)-max_best fin = len(population.individuals) population.individuals = np.array(population.individuals) - population.individuals = population.individuals[np.argsort(values)[ini:fin]] + #population.individuals = population.individuals[np.argsort(values)[ini:fin]] + population.individuals = population.individuals[np.argsort(values)[0:max_best]] for ind in population.individuals: print(ind.phenotype.id) diff --git a/pyrevolve/evolution/individual.py b/pyrevolve/evolution/individual.py index cd79d0d444..b5e81da85b 100644 --- a/pyrevolve/evolution/individual.py +++ b/pyrevolve/evolution/individual.py @@ -33,7 +33,7 @@ def id(self): return _id def export_genotype(self, folder): - self.genotype.export_genotype(f'{folder}/genotypes/genotype_{self.phenotype.id}') + self.genotype.export_genotype(f'{folder}/genotypes/genotype_{self.phenotype.id}.txt') def export_phenotype(self, folder): if self.phenotype is not None: diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index 5cd314997d..621dd13391 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -513,8 +513,12 @@ def new_module(self, slot, new_module_type, symbol): if not intersection: self.mounting_reference.children[slot] = module self.morph_mounting_container = None - self.mounting_reference_stack.append(self.mounting_reference) - self.mounting_reference = module + + # moves turtle to new module + if self.conf.move_to_new: + self.mounting_reference_stack.append(self.mounting_reference) + self.mounting_reference = module + if new_module_type == Alphabet.JOINT_HORIZONTAL \ or new_module_type == Alphabet.JOINT_VERTICAL: self.decode_brain_node(symbol, module.id) @@ -676,7 +680,7 @@ def __init__(self): class PlasticodingConfig: def __init__(self, initialization_genome=initialization.random_initialization, - e_max_groups=3, + e_max_groups=4, oscillator_param_min=1, oscillator_param_max=10, weight_param_min=-1, @@ -686,7 +690,8 @@ def __init__(self, axiom_w=Alphabet.CORE_COMPONENT, i_iterations=3, max_structural_modules=100, - robot_id=0 + robot_id=0, + move_to_new=False ): self.initialization_genome = initialization_genome self.e_max_groups = e_max_groups @@ -700,3 +705,4 @@ def __init__(self, self.i_iterations = i_iterations self.max_structural_modules = max_structural_modules self.robot_id = robot_id + self.move_to_new = move_to_new From f26f044c2626e6352f9dd3e2eb2cdbef7f6df0de Mon Sep 17 00:00:00 2001 From: Karine Date: Wed, 7 Aug 2019 21:29:45 +0200 Subject: [PATCH 02/45] small fixes --- .../examples/consolidate_experiments.py | 31 ++++++++--- experiments/examples/summary_measures.R | 51 ++++++++++-------- .../consolidate_experiments.py | 29 +++++++--- .../karines_experiments/manager_pop.py | 10 +++- .../karines_experiments/manager_pop_lava.py | 10 +++- .../karines_experiments/run-experiments | 31 ++++++++++- .../karines_experiments/summary_measures.R | 53 +++++++++++-------- .../karines_experiments/watch_best_robots.py | 19 ++++--- pyrevolve/evolution/fitness.py | 29 ++++++---- ...me.world => planeobstacles.realtime.world} | 4 +- ...anobstacles.world => planeobstacles.world} | 4 +- worlds/tilted10.realtime.world | 2 +- worlds/tilted10.world | 2 +- worlds/tilted15.realtime.world | 5 +- worlds/tilted15.world | 4 +- worlds/tilted5.realtime.world | 2 +- worlds/tilted5.world | 2 +- 17 files changed, 194 insertions(+), 94 deletions(-) rename worlds/{planobstacles.realtime.world => planeobstacles.realtime.world} (99%) rename worlds/{planobstacles.world => planeobstacles.world} (99%) diff --git a/experiments/examples/consolidate_experiments.py b/experiments/examples/consolidate_experiments.py index 9ccb2df05d..6c0a5d671d 100644 --- a/experiments/examples/consolidate_experiments.py +++ b/experiments/examples/consolidate_experiments.py @@ -15,11 +15,22 @@ def build_headers(path): file_summary.write('robot_id\t') behavior_headers = [] - with open(path + '/data_fullevolution/descriptors/behavior_desc_robot_1.txt') as file: - for line in file: - measure, value = line.strip().split(' ') - behavior_headers.append(measure) - file_summary.write(measure+'\t') + behavior_headers.append('velocity') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('displacement_velocity') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('displacement_velocity_hill') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('head_balance') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('contacts') + file_summary.write(behavior_headers[-1]+'\t') + # use this instead? but what if the guy is none? + # with open(path + '/data_fullevolution/descriptors/behavior_desc_robot_1.txt') as file: + # for line in file: + # measure, value = line.strip().split(' ') + # behavior_headers.append(measure) + # file_summary.write(measure+'\t') phenotype_headers = [] with open(path + '/data_fullevolution/descriptors/phenotype_desc_robot_1.txt') as file: @@ -54,8 +65,12 @@ def build_headers(path): if os.path.isfile(bh_file): with open(bh_file) as file: for line in file: - measure, value = line.strip().split(' ') - file_summary.write(value+'\t') + if line != 'None': + measure, value = line.strip().split(' ') + file_summary.write(value+'\t') + else: + for h in behavior_headers: + file_summary.write('None'+'\t') else: for h in behavior_headers: file_summary.write('None'+'\t') @@ -85,4 +100,4 @@ def build_headers(path): if 'body' in file: id = file.split('.')[0].split('_')[-1] file_summary.write(gen+'\t'+id+'\n') - file_summary.close() + file_summary.close() \ No newline at end of file diff --git a/experiments/examples/summary_measures.R b/experiments/examples/summary_measures.R index 184eea80d9..db9f6fdd8f 100644 --- a/experiments/examples/summary_measures.R +++ b/experiments/examples/summary_measures.R @@ -134,10 +134,11 @@ for (exp in 1:length(experiments_type)) } +fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) + measures_snapshots_all = sqldf("select * from measures_snapshots_all where fitness IS NOT NULL") -fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) measures_averages_gens_1 = list() @@ -190,8 +191,6 @@ for (exp in 1:length(experiments_type)) } } - - file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") #tests trends in curves and difference between ini and fin generations @@ -328,45 +327,55 @@ for (i in 1:length(measures_names)) } # graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_median',sep='') ),size=2, color = colors_median[m]) - if(!is.na(array_mann[[m]][[i]]$p.value)) + if (length(array_mann)>0) { - if(array_mann[[m]][[i]]$p.value<=sig) + if (length(array_mann[[m]])>0) { - if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} - tests1 = paste(tests1, initials[m],direction,sep="") + if(!is.na(array_mann[[m]][[i]]$p.value)) + { + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } + } } } } - for(m in 1:length(experiments_type)) + + if (length(array_wilcoxon[[m]])>0) { - if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + for(m in 1:length(experiments_type)) { - if(array_wilcoxon[[m]][[i]]$p.value<=sig) + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) { - tests2 = paste(tests2, initials[m],'C ', sep='') + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } } } } if (length(array_wilcoxon2)>0) { - for(p in 1:length(array_wilcoxon2[[1]])) { - if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + if (length(array_wilcoxon2[[1]][[p]])>0) { - if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) { - if(nchar(tests3)>line_size && break_aux == 0){ - tests3 = paste(tests3, '\n') - break_aux = 1 + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') } - tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') } } - } - } graph = graph + @@ -378,7 +387,7 @@ for (i in 1:length(measures_names)) graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=30),axis.title=element_text(size=39), plot.subtitle=element_text(size=25 )) - ggsave(paste( output_directory,'/' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 8, width = 8) + ggsave(paste( output_directory,'/' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 8, width = 10) } diff --git a/experiments/karines_experiments/consolidate_experiments.py b/experiments/karines_experiments/consolidate_experiments.py index fd60993d9a..6fc71a08e1 100644 --- a/experiments/karines_experiments/consolidate_experiments.py +++ b/experiments/karines_experiments/consolidate_experiments.py @@ -17,11 +17,22 @@ def build_headers(path): file_summary.write('robot_id\t') behavior_headers = [] - with open(path + '/data_fullevolution/descriptors/behavior_desc_robot_1.txt') as file: - for line in file: - measure, value = line.strip().split(' ') - behavior_headers.append(measure) - file_summary.write(measure+'\t') + behavior_headers.append('velocity') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('displacement_velocity') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('displacement_velocity_hill') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('head_balance') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('contacts') + file_summary.write(behavior_headers[-1]+'\t') + # use this instead? but what if the guy is none? + # with open(path + '/data_fullevolution/descriptors/behavior_desc_robot_1.txt') as file: + # for line in file: + # measure, value = line.strip().split(' ') + # behavior_headers.append(measure) + # file_summary.write(measure+'\t') phenotype_headers = [] with open(path + '/data_fullevolution/descriptors/phenotype_desc_robot_1.txt') as file: @@ -56,8 +67,12 @@ def build_headers(path): if os.path.isfile(bh_file): with open(bh_file) as file: for line in file: - measure, value = line.strip().split(' ') - file_summary.write(value+'\t') + if line != 'None': + measure, value = line.strip().split(' ') + file_summary.write(value+'\t') + else: + for h in behavior_headers: + file_summary.write('None'+'\t') else: for h in behavior_headers: file_summary.write('None'+'\t') diff --git a/experiments/karines_experiments/manager_pop.py b/experiments/karines_experiments/manager_pop.py index d2c66d5a48..339aa4527e 100755 --- a/experiments/karines_experiments/manager_pop.py +++ b/experiments/karines_experiments/manager_pop.py @@ -15,6 +15,7 @@ from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig from pyrevolve.tol.manage import measures from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue from pyrevolve.custom_logging.logger import logger @@ -28,7 +29,9 @@ async def run(): population_size = 100 offspring_size = 50 - genotype_conf = PlasticodingConfig() + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + ) mutation_conf = MutationConfig( mutation_prob=0.8, @@ -86,7 +89,10 @@ def fitness_function(robot_manager, robot): simulator_queue = SimulatorQueue(settings.n_cores, settings, settings.port_start) await simulator_queue.start() - population = Population(population_conf, simulator_queue, next_robot_id) + analyzer_queue = AnalyzerQueue(1, settings, settings.port_start+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) if do_recovery: # loading a previous state of the experiment diff --git a/experiments/karines_experiments/manager_pop_lava.py b/experiments/karines_experiments/manager_pop_lava.py index b48d4be19e..e98623a01e 100755 --- a/experiments/karines_experiments/manager_pop_lava.py +++ b/experiments/karines_experiments/manager_pop_lava.py @@ -14,6 +14,7 @@ from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue from pyrevolve.custom_logging.logger import logger @@ -28,7 +29,9 @@ async def run(): population_size = 100 offspring_size = 50 - genotype_conf = PlasticodingConfig() + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + ) mutation_conf = MutationConfig( mutation_prob=0.8, @@ -86,7 +89,10 @@ def fitness_function(robot_manager, robot): simulator_queue = SimulatorQueue(settings.n_cores, settings, settings.port_start) await simulator_queue.start() - population = Population(population_conf, simulator_queue, next_robot_id) + analyzer_queue = AnalyzerQueue(1, settings, settings.port_start+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) if do_recovery: # loading a previous state of the experiment diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index 2499bbd4cc..74bb4b0608 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -1,10 +1,37 @@ #!/bin/bash + while true do for i in {1..10}; do - ./revolve.py --experiment_name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/manager_pop_lava.py --n-cores 5; + ./revolve.py --experiment-name karines_experiments/data/plane_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11400 --world worlds/plane.world; sleep 5s - ./revolve.py --experiment_name karines_experiments/data/plane_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 5; + done +done + + +#### others... + + +while true + do + for i in {1..10}; do + ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/manager_pop_lava.py --n-cores 3 --port-start 11700 --world worlds/plane.world; + sleep 5s + done +done + +while true + do + for i in {1..10}; do + ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11800 --world worlds/tilted15.world --z-start 0.18; + sleep 5s + done +done + +while true + do + for i in {1..10}; do + ./revolve.py --experiment-name karines_experiments/data/obstacles_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11900 --world worlds/planeobstacles.world --z-start 0.05; sleep 5s done done \ No newline at end of file diff --git a/experiments/karines_experiments/summary_measures.R b/experiments/karines_experiments/summary_measures.R index b9a396edee..7353e2e28f 100644 --- a/experiments/karines_experiments/summary_measures.R +++ b/experiments/karines_experiments/summary_measures.R @@ -133,10 +133,11 @@ for (exp in 1:length(experiments_type)) } +fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) + measures_snapshots_all = sqldf("select * from measures_snapshots_all where fitness IS NOT NULL") -fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) measures_averages_gens_1 = list() @@ -189,8 +190,6 @@ for (exp in 1:length(experiments_type)) } } - - file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") #tests trends in curves and difference between ini and fin generations @@ -206,7 +205,7 @@ array_mann = list() for (m in 1:length(experiments_type)) { - + array_wilcoxon[[m]] = list() array_mann[[m]] = list() @@ -327,45 +326,55 @@ for (i in 1:length(measures_names)) } # graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_median',sep='') ),size=2, color = colors_median[m]) - if(!is.na(array_mann[[m]][[i]]$p.value)) + if (length(array_mann)>0) { - if(array_mann[[m]][[i]]$p.value<=sig) + if (length(array_mann[[m]])>0) { - if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} - tests1 = paste(tests1, initials[m],direction,sep="") + if(!is.na(array_mann[[m]][[i]]$p.value)) + { + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } + } } } } - for(m in 1:length(experiments_type)) + + if (length(array_wilcoxon[[m]])>0) { - if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + for(m in 1:length(experiments_type)) { - if(array_wilcoxon[[m]][[i]]$p.value<=sig) + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) { - tests2 = paste(tests2, initials[m],'C ', sep='') + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } } } } if (length(array_wilcoxon2)>0) { - for(p in 1:length(array_wilcoxon2[[1]])) { - if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + if (length(array_wilcoxon2[[1]][[p]])>0) { - if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) { - if(nchar(tests3)>line_size && break_aux == 0){ - tests3 = paste(tests3, '\n') - break_aux = 1 + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') } - tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') } } - } - } graph = graph + @@ -377,7 +386,7 @@ for (i in 1:length(measures_names)) graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=30),axis.title=element_text(size=39), plot.subtitle=element_text(size=25 )) - ggsave(paste( output_directory,'/' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 8, width = 8) + ggsave(paste( output_directory,'/' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 8, width = 10) } diff --git a/experiments/karines_experiments/watch_best_robots.py b/experiments/karines_experiments/watch_best_robots.py index b80a23b35b..b4ee8265b9 100755 --- a/experiments/karines_experiments/watch_best_robots.py +++ b/experiments/karines_experiments/watch_best_robots.py @@ -25,7 +25,7 @@ async def run(): genotype_conf = PlasticodingConfig( - max_structural_modules=100, + max_structural_modules=15, ) mutation_conf = MutationConfig( @@ -64,7 +64,10 @@ async def run(): simulator_queue = SimulatorQueue(settings.n_cores, settings, settings.port_start) await simulator_queue.start() - population = Population(population_conf, simulator_queue, 0) + # analyzer_queue = AnalyzerQueue(1, settings, settings.port_start+settings.n_cores) + # await analyzer_queue.start() + + population = Population(population_conf, simulator_queue) # choose a snapshot here. and the maximum best individuals you wish to watch generation = 99 @@ -74,17 +77,19 @@ async def run(): values = [] for ind in population.individuals: # define a criteria here - #values.append(ind.fitness) - values.append(ind.phenotype._behavioural_measurements.contacts) - # values.append(ind.phenotype._behavioural_measurements.displacement_velocity_hill) + values.append(ind.fitness) + # values.append(ind.phenotype._behavioural_measurements.contacts) + #values.append(ind.phenotype._behavioural_measurements.displacement_velocity_hill) values = np.array(values) ini = len(population.individuals)-max_best fin = len(population.individuals) population.individuals = np.array(population.individuals) - #population.individuals = population.individuals[np.argsort(values)[ini:fin]] - population.individuals = population.individuals[np.argsort(values)[0:max_best]] + # best + population.individuals = population.individuals[np.argsort(values)[ini:fin]] + #worst + #population.individuals = population.individuals[np.argsort(values)[0:max_best]] for ind in population.individuals: print(ind.phenotype.id) diff --git a/pyrevolve/evolution/fitness.py b/pyrevolve/evolution/fitness.py index 44bab025be..d14a1702bd 100644 --- a/pyrevolve/evolution/fitness.py +++ b/pyrevolve/evolution/fitness.py @@ -53,20 +53,29 @@ def online_old_revolve(robot_manager): def displacement_velocity_hill(robot_manager, robot): - _displacement_velocity_hill = measures.displacement_velocity_hill(robot_manager) - if _displacement_velocity_hill < 0: - _displacement_velocity_hill /= 10 - elif _displacement_velocity_hill == 0: - _displacement_velocity_hill = -0.1 - # temp elif - # elif _displacement_velocity_hill > 0: - # _displacement_velocity_hill *= _displacement_velocity_hill + fitness = measures.displacement_velocity_hill(robot_manager) - return _displacement_velocity_hill + if fitness < 0: + fitness /= 10 + + elif fitness == 0: + fitness = -0.1 + + # if fitness >= 0: + # fitness = fitness * size_penalty + # else: + # fitness = fitness / size_penalty + + return fitness + +def size_penalty(robot_manager, robot): + _size_penalty = 1 / robot.phenotype._morphological_measurements.measurements_to_dict()['absolute_size'] + + return _size_penalty def floor_is_lava(robot_manager, robot): - _displacement_velocity_hill = measures.displacement_velocity_hill(robot_manager) + _displacement_velocity_hill = displacement_velocity_hill(robot_manager, robot) _contacts = measures.contacts(robot_manager, robot) _contacts = max(_contacts, 0.0001) diff --git a/worlds/planobstacles.realtime.world b/worlds/planeobstacles.realtime.world similarity index 99% rename from worlds/planobstacles.realtime.world rename to worlds/planeobstacles.realtime.world index 991747d10f..5b80f8a8d6 100644 --- a/worlds/planobstacles.realtime.world +++ b/worlds/planeobstacles.realtime.world @@ -6,7 +6,7 @@ 0 - 0.003 + 0.001 1000 @@ -7627,6 +7627,6 @@ model://tol_ground - + diff --git a/worlds/planobstacles.world b/worlds/planeobstacles.world similarity index 99% rename from worlds/planobstacles.world rename to worlds/planeobstacles.world index ffa4a71a82..39f29c6b3b 100644 --- a/worlds/planobstacles.world +++ b/worlds/planeobstacles.world @@ -6,7 +6,7 @@ 0 - 0.003 + 0.005 0.0 @@ -7627,6 +7627,6 @@ model://tol_ground - + diff --git a/worlds/tilted10.realtime.world b/worlds/tilted10.realtime.world index d863a30fad..4828e4da1d 100644 --- a/worlds/tilted10.realtime.world +++ b/worlds/tilted10.realtime.world @@ -36,6 +36,6 @@ model://tilted10 - + diff --git a/worlds/tilted10.world b/worlds/tilted10.world index be0e7b5695..e469720525 100644 --- a/worlds/tilted10.world +++ b/worlds/tilted10.world @@ -35,6 +35,6 @@ model://tilted10 - + diff --git a/worlds/tilted15.realtime.world b/worlds/tilted15.realtime.world index ee342f03b6..ce3c32e8d9 100644 --- a/worlds/tilted15.realtime.world +++ b/worlds/tilted15.realtime.world @@ -6,7 +6,7 @@ 0 - 0.003 + 0.001 1000 @@ -35,7 +35,6 @@ model://tilted15 - - + diff --git a/worlds/tilted15.world b/worlds/tilted15.world index caa8c554e2..5f596916f8 100644 --- a/worlds/tilted15.world +++ b/worlds/tilted15.world @@ -6,7 +6,7 @@ 0 - 0.003 + 0.005 0 @@ -35,6 +35,6 @@ model://tilted15 - + diff --git a/worlds/tilted5.realtime.world b/worlds/tilted5.realtime.world index 9324164ab7..aa995ebde1 100644 --- a/worlds/tilted5.realtime.world +++ b/worlds/tilted5.realtime.world @@ -35,6 +35,6 @@ model://tilted5 - + diff --git a/worlds/tilted5.world b/worlds/tilted5.world index 45fa5e9d45..6810efd7d2 100644 --- a/worlds/tilted5.world +++ b/worlds/tilted5.world @@ -35,6 +35,6 @@ model://tilted5 - + From 25ed54efc819e2b4ff12d8cd0d921ef3097e38b9 Mon Sep 17 00:00:00 2001 From: Karine Date: Wed, 7 Aug 2019 21:39:40 +0200 Subject: [PATCH 03/45] eval time --- experiments/karines_experiments/run-experiments | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index 74bb4b0608..dfa7d98b22 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -3,7 +3,7 @@ while true do for i in {1..10}; do - ./revolve.py --experiment-name karines_experiments/data/plane_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11400 --world worlds/plane.world; + ./revolve.py --experiment-name karines_experiments/data/plane_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11400 --world worlds/plane.world --evaluation-time 50; sleep 5s done done @@ -15,7 +15,7 @@ done while true do for i in {1..10}; do - ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/manager_pop_lava.py --n-cores 3 --port-start 11700 --world worlds/plane.world; + ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/manager_pop_lava.py --n-cores 3 --port-start 11700 --world worlds/plane.world --evaluation-time 50; sleep 5s done done @@ -23,7 +23,7 @@ done while true do for i in {1..10}; do - ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11800 --world worlds/tilted15.world --z-start 0.18; + ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11800 --world worlds/tilted15.world --z-start 0.18 --evaluation-time 50; sleep 5s done done @@ -31,7 +31,7 @@ done while true do for i in {1..10}; do - ./revolve.py --experiment-name karines_experiments/data/obstacles_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11900 --world worlds/planeobstacles.world --z-start 0.05; + ./revolve.py --experiment-name karines_experiments/data/obstacles_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11900 --world worlds/planeobstacles.world --z-start 0.05 --evaluation-time 50; sleep 5s done done \ No newline at end of file From fcbecf6185e2bcbe16487f0b419447d09cd0798b Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 9 Aug 2019 11:43:15 +0200 Subject: [PATCH 04/45] small fixes --- experiments/examples/stuck-experiments_watchman.py | 5 +++-- experiments/examples/summary_measures.R | 10 +++++++--- .../karines_experiments/stuck-experiments_watchman.py | 5 +++-- experiments/karines_experiments/summary_measures.R | 6 ++++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/experiments/examples/stuck-experiments_watchman.py b/experiments/examples/stuck-experiments_watchman.py index 6b0a2a4fc7..60f6ab1ea4 100644 --- a/experiments/examples/stuck-experiments_watchman.py +++ b/experiments/examples/stuck-experiments_watchman.py @@ -33,8 +33,9 @@ files.sort() youngest.append(files[-1]) - if files[-1] > time_ago: - some_has_been_updated = True + if len(files)>0: + if files[-1] > time_ago: + some_has_been_updated = True if not some_has_been_updated: youngest.sort() diff --git a/experiments/examples/summary_measures.R b/experiments/examples/summary_measures.R index db9f6fdd8f..be33009560 100644 --- a/experiments/examples/summary_measures.R +++ b/experiments/examples/summary_measures.R @@ -5,19 +5,19 @@ library(dplyr) library(trend) base_directory <- paste('../', sep='') - output_directory = base_directory + +#### CHANGE THE PARAMETERS HERE #### + experiments_type = c( 'default_experiment' ) - initials = c('d') experiments_labels = c('default_experiment') - runs = c(1,2,3,4,5,6,7,8,9,10) gens = 100 pop = 100 @@ -27,6 +27,10 @@ show_markers = TRUE show_legends = TRUE experiments_type_colors = c( '#009900', '#FF8000', '#BA1616', '#000099') # DARK:green, orange, red, blue +#### CHANGE THE PARAMETERS HERE #### + + + measures_names = c( 'displacement_velocity_hill', 'head_balance', diff --git a/experiments/karines_experiments/stuck-experiments_watchman.py b/experiments/karines_experiments/stuck-experiments_watchman.py index d65be96d26..a25bb7cbc2 100644 --- a/experiments/karines_experiments/stuck-experiments_watchman.py +++ b/experiments/karines_experiments/stuck-experiments_watchman.py @@ -34,8 +34,9 @@ files.sort() youngest.append(files[-1]) - if files[-1] > time_ago: - some_has_been_updated = True + if len(files)>0: + if files[-1] > time_ago: + some_has_been_updated = True if not some_has_been_updated: youngest.sort() diff --git a/experiments/karines_experiments/summary_measures.R b/experiments/karines_experiments/summary_measures.R index 7353e2e28f..373d5bd8d9 100644 --- a/experiments/karines_experiments/summary_measures.R +++ b/experiments/karines_experiments/summary_measures.R @@ -8,6 +8,9 @@ base_directory <- paste('projects/revolve/experiments/karines_experiments/data', output_directory = base_directory +#### CHANGE THE PARAMETERS HERE #### + + experiments_type = c( 'plane', 'lava' @@ -20,6 +23,9 @@ experiments_labels = c('Plane', 'Floor is lava') runs = c(1,2,3,4,5,6,7,8,9,10) gens = 100 pop = 100 + +#### CHANGE THE PARAMETERS HERE #### + sig = 0.05 line_size = 30 show_markers = TRUE From 32bf0e9aaa846fa40b611e456521116a40d763ef Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 9 Aug 2019 13:27:33 +0200 Subject: [PATCH 05/45] new fitness --- .../karines_experiments/manager_pop.py | 2 +- .../karines_experiments/manager_pop_lava.py | 2 +- .../manager_pop_lava_cost.py | 124 ++++++++++++++++++ .../karines_experiments/run-experiments | 11 ++ .../karines_experiments/watch_best_robots.py | 4 +- pyrevolve/evolution/fitness.py | 27 ++-- 6 files changed, 154 insertions(+), 16 deletions(-) create mode 100755 experiments/karines_experiments/manager_pop_lava_cost.py diff --git a/experiments/karines_experiments/manager_pop.py b/experiments/karines_experiments/manager_pop.py index 339aa4527e..2c4952a9be 100755 --- a/experiments/karines_experiments/manager_pop.py +++ b/experiments/karines_experiments/manager_pop.py @@ -63,7 +63,7 @@ async def run(): def fitness_function(robot_manager, robot): contacts = measures.contacts(robot_manager, robot) assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot) + return fitness.displacement_velocity_hill(robot_manager, robot, False) population_conf = PopulationConfig( population_size=population_size, diff --git a/experiments/karines_experiments/manager_pop_lava.py b/experiments/karines_experiments/manager_pop_lava.py index e98623a01e..afe6ef6430 100755 --- a/experiments/karines_experiments/manager_pop_lava.py +++ b/experiments/karines_experiments/manager_pop_lava.py @@ -63,7 +63,7 @@ async def run(): def fitness_function(robot_manager, robot): contacts = measures.contacts(robot_manager, robot) assert(contacts != 0) - return fitness.floor_is_lava(robot_manager, robot) + return fitness.floor_is_lava(robot_manager, robot, False) population_conf = PopulationConfig( population_size=population_size, diff --git a/experiments/karines_experiments/manager_pop_lava_cost.py b/experiments/karines_experiments/manager_pop_lava_cost.py new file mode 100755 index 0000000000..ac1b21771d --- /dev/null +++ b/experiments/karines_experiments/manager_pop_lava_cost.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.custom_logging.logger import logger + + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function(robot_manager, robot): + contacts = measures.contacts(robot_manager, robot) + assert(contacts != 0) + return fitness.floor_is_lava(robot_manager, robot, True) + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + measure_individuals=settings.measure_individuals, + ) + + settings = parser.parse_args() + simulator_queue = SimulatorQueue(settings.n_cores, settings, settings.port_start) + await simulator_queue.start() + + analyzer_queue = AnalyzerQueue(1, settings, settings.port_start+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + if gen_num >= 0: + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index dfa7d98b22..ffe89c5a1b 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -34,4 +34,15 @@ while true ./revolve.py --experiment-name karines_experiments/data/obstacles_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11900 --world worlds/planeobstacles.world --z-start 0.05 --evaluation-time 50; sleep 5s done +done + + + + + +while true + do + sleep 1800s; + kill $( ps aux | grep 'gzserver' | awk '{print $2}'); + kill $( ps aux | grep 'revolve.py' | awk '{print $2}'); done \ No newline at end of file diff --git a/experiments/karines_experiments/watch_best_robots.py b/experiments/karines_experiments/watch_best_robots.py index b4ee8265b9..4186060de8 100755 --- a/experiments/karines_experiments/watch_best_robots.py +++ b/experiments/karines_experiments/watch_best_robots.py @@ -86,9 +86,9 @@ async def run(): fin = len(population.individuals) population.individuals = np.array(population.individuals) - # best + # highest population.individuals = population.individuals[np.argsort(values)[ini:fin]] - #worst + # lowest #population.individuals = population.individuals[np.argsort(values)[0:max_best]] for ind in population.individuals: diff --git a/pyrevolve/evolution/fitness.py b/pyrevolve/evolution/fitness.py index d14a1702bd..eab12958d0 100644 --- a/pyrevolve/evolution/fitness.py +++ b/pyrevolve/evolution/fitness.py @@ -52,7 +52,13 @@ def online_old_revolve(robot_manager): return v if v <= robot_manager.conf.fitness_limit else 0.0 -def displacement_velocity_hill(robot_manager, robot): +def size_penalty(robot_manager, robot): + _size_penalty = 1 / robot.phenotype._morphological_measurements.measurements_to_dict()['absolute_size'] + + return _size_penalty + + +def displacement_velocity_hill(robot_manager, robot, cost=False): fitness = measures.displacement_velocity_hill(robot_manager) if fitness < 0: @@ -61,21 +67,18 @@ def displacement_velocity_hill(robot_manager, robot): elif fitness == 0: fitness = -0.1 - # if fitness >= 0: - # fitness = fitness * size_penalty - # else: - # fitness = fitness / size_penalty + if cost: + _size_penalty = size_penalty(robot_manager, robot) ** 2 + if fitness >= 0: + fitness = fitness * _size_penalty + else: + fitness = fitness / _size_penalty return fitness -def size_penalty(robot_manager, robot): - _size_penalty = 1 / robot.phenotype._morphological_measurements.measurements_to_dict()['absolute_size'] - - return _size_penalty - -def floor_is_lava(robot_manager, robot): - _displacement_velocity_hill = displacement_velocity_hill(robot_manager, robot) +def floor_is_lava(robot_manager, robot, cost=False): + _displacement_velocity_hill = displacement_velocity_hill(robot_manager, robot, cost) _contacts = measures.contacts(robot_manager, robot) _contacts = max(_contacts, 0.0001) From 6897c476d17a64be50cb82c518664e354fa8b471 Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 9 Aug 2019 14:04:55 +0200 Subject: [PATCH 06/45] small fixes --- experiments/karines_experiments/manager_pop_lava_cost.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/karines_experiments/manager_pop_lava_cost.py b/experiments/karines_experiments/manager_pop_lava_cost.py index ac1b21771d..499eba406b 100755 --- a/experiments/karines_experiments/manager_pop_lava_cost.py +++ b/experiments/karines_experiments/manager_pop_lava_cost.py @@ -30,7 +30,7 @@ async def run(): offspring_size = 50 genotype_conf = PlasticodingConfig( - max_structural_modules=15, + # max_structural_modules=15, ) mutation_conf = MutationConfig( From 37c9a7ee8bbc9e4109447270e15f021f5ab5a465 Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 13 Sep 2019 14:37:25 +0200 Subject: [PATCH 07/45] fix fitness --- pyrevolve/evolution/fitness.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrevolve/evolution/fitness.py b/pyrevolve/evolution/fitness.py index eab12958d0..c7249c7bdf 100644 --- a/pyrevolve/evolution/fitness.py +++ b/pyrevolve/evolution/fitness.py @@ -61,13 +61,13 @@ def size_penalty(robot_manager, robot): def displacement_velocity_hill(robot_manager, robot, cost=False): fitness = measures.displacement_velocity_hill(robot_manager) - if fitness < 0: - fitness /= 10 - - elif fitness == 0: + if fitness == 0 or robot.phenotype._morphological_measurements.measurements_to_dict()['hinge_count'] == 0: fitness = -0.1 - if cost: + elif fitness < 0: + fitness /= 10 + + if cost and fitness != None: _size_penalty = size_penalty(robot_manager, robot) ** 2 if fitness >= 0: fitness = fitness * _size_penalty From c766609ed33e08d079d8f3734d281c656968a774 Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 13 Sep 2019 17:08:00 +0200 Subject: [PATCH 08/45] small fitness change --- pyrevolve/evolution/fitness.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pyrevolve/evolution/fitness.py b/pyrevolve/evolution/fitness.py index c7249c7bdf..518a72c084 100644 --- a/pyrevolve/evolution/fitness.py +++ b/pyrevolve/evolution/fitness.py @@ -57,6 +57,23 @@ def size_penalty(robot_manager, robot): return _size_penalty +def displacement_velocity_hill2(robot_manager, robot, cost=False): + fitness = measures.displacement_velocity_hill(robot_manager) + + if fitness == 0: + fitness = -0.1 + + elif fitness < 0: + fitness /= 10 + + if cost and fitness != None: + _size_penalty = size_penalty(robot_manager, robot) ** 2 + if fitness >= 0: + fitness = fitness * _size_penalty + else: + fitness = fitness / _size_penalty + + return fitness def displacement_velocity_hill(robot_manager, robot, cost=False): fitness = measures.displacement_velocity_hill(robot_manager) From 62283398dbfc04d474ce1d03e33558469b6fb413 Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 13 Sep 2019 17:09:05 +0200 Subject: [PATCH 09/45] script best --- .../bestrobots_summary_renders.r | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 experiments/karines_experiments/bestrobots_summary_renders.r diff --git a/experiments/karines_experiments/bestrobots_summary_renders.r b/experiments/karines_experiments/bestrobots_summary_renders.r new file mode 100644 index 0000000000..1ee92c23c7 --- /dev/null +++ b/experiments/karines_experiments/bestrobots_summary_renders.r @@ -0,0 +1,94 @@ +#library(ggplot2) +#library(dplyr) +#library(viridis) +#ibrary(Interpol.T) +#library(lubridate) +#library(ggExtra) +#library(tidyr) +#library(trend) +#library(poweRlaw) +#library(plyr) +library(sqldf) +require('magick') + +##### change paths/labels/params here ##### + + +paths = c( + 'plane', + 'lava', + 'lavacost', + 'lavacostold', + 'lavaold' +) + + + +base_directory <- paste('projects/revolve/experiments/karines_experiments/data/', sep='') + +experiments = 30 +gens = 100 +pop = 100 +num_top = 3 + +analysis = '1images' + +##### change paths/labels/params here ##### + +output_directory = paste(base_directory, '/',analysis, sep='') + + +file <-file(paste(output_directory,'/best.txt',sep=''), open="w") + +# for each method +for(m in 1:length(paths)) +{ + + # for each repetition + for (exp in 1:experiments) + { + + input_directory <- paste(base_directory, paths[m],'_',exp,sep='') + + ids_gens = data.frame() + list = strsplit(list.files(paste(input_directory, '/selectedpop_',gens-1, sep='')), ' ') + for(geno in 1:pop) + { + genome = data.frame(cbind(c(gens), c(strsplit(strsplit(list [[geno]],'_')[[1]][3],'.png')[[1]][1] ))) + names(genome)<-c('generation','robot_id') + ids_gens = rbind(ids_gens,genome) + } + + measures = read.table(paste(input_directory,"/all_measures.tsv", sep=''), header = TRUE) + bests = sqldf(paste("select robot_id, fitness from measures inner join ids_gens using (robot_id) order by fitness desc limit",num_top)) + + for(b in 1:nrow(bests)) + { + + writeLines( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'fitness'] ), file ) + + phenotype= bests[b,'robot_id'] + + patha = paste(base_directory,paths[m],'_',exp,"/selectedpop_",gens-1,sep="") + + body <- list.files(patha, paste("body_robot_",phenotype,".png$",sep=""), full.names = TRUE) + body = image_read(body) + body = image_border(image_background(body, "white"), "white", "20x33") + + + if(b == 1) + { + bodies = body + }else{ + bodies = c(bodies, body) + } + } + + side_by_side = image_append(bodies, stack=F) + image_write(side_by_side, path = paste(output_directory,"/",paths[m],"_bodies_best_",exp,".pdf",sep=''), format = "pdf") + + } +} + + +close(file) From 31b8a7db340786536f3f2b759db23c512d0f0cfb Mon Sep 17 00:00:00 2001 From: Karine Date: Mon, 16 Sep 2019 17:53:11 +0200 Subject: [PATCH 10/45] fixes to script r --- .../karines_experiments/summary_measures.R | 166 +++++++++++------- pyrevolve/evolution/fitness.py | 2 +- worlds/plane.realtime.world | 2 +- worlds/planeobstacles.realtime.world | 2 +- worlds/planeobstacles.world | 2 +- worlds/tilted15.realtime.world | 2 +- 6 files changed, 108 insertions(+), 68 deletions(-) diff --git a/experiments/karines_experiments/summary_measures.R b/experiments/karines_experiments/summary_measures.R index 373d5bd8d9..5178b40145 100644 --- a/experiments/karines_experiments/summary_measures.R +++ b/experiments/karines_experiments/summary_measures.R @@ -3,10 +3,12 @@ library(sqldf) library(plyr) library(dplyr) library(trend) +library(purrr) base_directory <- paste('projects/revolve/experiments/karines_experiments/data', sep='') -output_directory = base_directory +analysis = 'test' +output_directory = paste(base_directory,'/',analysis ,sep='') #### CHANGE THE PARAMETERS HERE #### @@ -155,6 +157,7 @@ measures_fin = list() for (exp in 1:length(experiments_type)) { + measures_aux = c() query ='select run, generation' for (i in 1:length(measures_names)) { @@ -168,22 +171,36 @@ for (exp in 1:length(experiments_type)) temp = measures_averages_gens_1[[exp]] + temp$generation = as.numeric(temp$generation) + measures_ini[[exp]] = sqldf(paste("select * from temp where generation=1")) measures_fin[[exp]] = sqldf(paste("select * from temp where generation=",gens-1)) query = 'select generation' for (i in 1:length(measures_names)) { + # later renames vars _avg_SUMMARY, just to make it in the same style as the quantile variables query = paste(query,', avg(',experiments_type[exp],'_',measures_names[i],'_avg) as ',experiments_type[exp],'_',measures_names[i],'_avg', sep='') query = paste(query,', max(',experiments_type[exp],'_',measures_names[i],'_avg) as ',experiments_type[exp],'_',measures_names[i],'_max', sep='') query = paste(query,', stdev(',experiments_type[exp],'_',measures_names[i],'_avg) as ',experiments_type[exp],'_',measures_names[i],'_stdev', sep='') query = paste(query,', median(',experiments_type[exp],'_',measures_names[i],'_avg) as ',experiments_type[exp],'_',measures_names[i],'_median', sep='') + + measures_aux = c(measures_aux, paste(experiments_type[exp],'_',measures_names[i],'_avg', sep='') ) } query = paste(query,' from temp group by generation', sep="") - measures_averages_gens_2[[exp]] = sqldf(query) + temp2 = sqldf(query) + + p <- c(0.25, 0.75) + p_names <- map_chr(p, ~paste0('Q',.x*100, sep="")) + p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>% + set_names(nm = p_names) - measures_averages_gens_2[[exp]]$generation = as.numeric(measures_averages_gens_2[[exp]]$generation) + quantiles = data.frame(temp %>% + group_by(generation) %>% + summarize_at(vars(measures_aux), funs(!!!p_funs)) ) + measures_averages_gens_2[[exp]] = sqldf('select * from temp2 inner join quantiles using (generation)') + } @@ -307,92 +324,115 @@ close(file) # plots measures -for (i in 1:length(measures_names)) +for (type_summary in c('means','quants')) { - tests1 = '' - tests2 = '' - tests3 = '' - break_aux = 0 - - graph <- ggplot(data=measures_averages_gens, aes(x=generation)) - for(m in 1:length(experiments_type)) - { - graph = graph + geom_errorbar(aes_string(ymin=paste(experiments_type[m],'_',measures_names[i],'_avg','-',experiments_type[m],'_',measures_names[i],'_stdev',sep=''), - ymax=paste(experiments_type[m],'_',measures_names[i],'_avg','+',experiments_type[m],'_',measures_names[i],'_stdev',sep='') ), - color=experiments_type_colors[m], - alpha=0.35,size=0.5,width=0.001) - } + - for(m in 1:length(experiments_type)) + for (i in 1:length(measures_names)) { - if(show_legends == TRUE){ - graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) - }else{ - graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) + tests1 = '' + tests2 = '' + tests3 = '' + break_aux = 0 + + graph <- ggplot(data=measures_averages_gens, aes(x=generation)) + + for(m in 1:length(experiments_type)) + { + if(type_summary == 'means') + { + graph = graph + geom_errorbar(aes_string(ymin=paste(experiments_type[m],'_',measures_names[i],'_avg','-',experiments_type[m],'_',measures_names[i],'_stdev',sep=''), + ymax=paste(experiments_type[m],'_',measures_names[i],'_avg','+',experiments_type[m],'_',measures_names[i],'_stdev',sep='') ), + color=experiments_type_colors[m], + alpha=0.35,size=0.5,width=0.001) + }else + { + graph = graph + geom_errorbar(aes_string(ymin=paste(experiments_type[m],'_',measures_names[i],'_avg_Q25',sep=''), + ymax=paste(experiments_type[m],'_',measures_names[i],'_avg_Q75',sep='') ), + color=experiments_type_colors[m], + alpha=0.35,size=0.5,width=0.001) + } } - # graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_median',sep='') ),size=2, color = colors_median[m]) - if (length(array_mann)>0) + for(m in 1:length(experiments_type)) { - if (length(array_mann[[m]])>0) + if(type_summary == 'means') { - if(!is.na(array_mann[[m]][[i]]$p.value)) + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) + }else{ + graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) + } + + }else{ + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_median',sep='') , colour=shQuote(experiments_labels[m]) ),size=2 ) + }else{ + graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_median',sep='') ),size=2, color = experiments_type_colors[m] ) + } + } + + if (length(array_mann)>0) + { + if (length(array_mann[[m]])>0) { - if(array_mann[[m]][[i]]$p.value<=sig) + if(!is.na(array_mann[[m]][[i]]$p.value)) { - if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} - tests1 = paste(tests1, initials[m],direction,sep="") + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } } } } } - } - - if (length(array_wilcoxon[[m]])>0) - { - for(m in 1:length(experiments_type)) + + if (length(array_wilcoxon[[m]])>0) { - if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + for(m in 1:length(experiments_type)) { - if(array_wilcoxon[[m]][[i]]$p.value<=sig) + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) { - tests2 = paste(tests2, initials[m],'C ', sep='') + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } } } } - } - - if (length(array_wilcoxon2)>0) - { - for(p in 1:length(array_wilcoxon2[[1]])) + + if (length(array_wilcoxon2)>0) { - if (length(array_wilcoxon2[[1]][[p]])>0) + for(p in 1:length(array_wilcoxon2[[1]])) { - if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + if (length(array_wilcoxon2[[1]][[p]])>0) { - if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) { - if(nchar(tests3)>line_size && break_aux == 0){ - tests3 = paste(tests3, '\n') - break_aux = 1 + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') } - tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') } } } - } - } - - graph = graph + - #coord_cartesian(ylim = c(0, 1))+ - labs( y=measures_labels[i], x="Generation") - if(show_markers == TRUE){ - graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) + } + + graph = graph + + #coord_cartesian(ylim = c(0, 1))+ + labs( y=measures_labels[i], x="Generation") + if(show_markers == TRUE){ + graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) + } + graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=30),axis.title=element_text(size=39), + plot.subtitle=element_text(size=25 )) + + ggsave(paste( output_directory,'/',type_summary,'_' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 8, width = 10) } - graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=30),axis.title=element_text(size=39), - plot.subtitle=element_text(size=25 )) - - ggsave(paste( output_directory,'/' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 8, width = 10) -} - +} diff --git a/pyrevolve/evolution/fitness.py b/pyrevolve/evolution/fitness.py index 518a72c084..01ae0a22ce 100644 --- a/pyrevolve/evolution/fitness.py +++ b/pyrevolve/evolution/fitness.py @@ -60,7 +60,7 @@ def size_penalty(robot_manager, robot): def displacement_velocity_hill2(robot_manager, robot, cost=False): fitness = measures.displacement_velocity_hill(robot_manager) - if fitness == 0: + if fitness == 0: fitness = -0.1 elif fitness < 0: diff --git a/worlds/plane.realtime.world b/worlds/plane.realtime.world index 5864bebad4..3f27a33fe8 100644 --- a/worlds/plane.realtime.world +++ b/worlds/plane.realtime.world @@ -10,7 +10,7 @@ 0.001 - 800 + 5000 diff --git a/worlds/planeobstacles.realtime.world b/worlds/planeobstacles.realtime.world index 5b80f8a8d6..d91e14a26b 100644 --- a/worlds/planeobstacles.realtime.world +++ b/worlds/planeobstacles.realtime.world @@ -9,7 +9,7 @@ 0.001 - 1000 + 5000 diff --git a/worlds/planeobstacles.world b/worlds/planeobstacles.world index 39f29c6b3b..28148c0e33 100644 --- a/worlds/planeobstacles.world +++ b/worlds/planeobstacles.world @@ -6,7 +6,7 @@ 0 - 0.005 + 0.001 0.0 diff --git a/worlds/tilted15.realtime.world b/worlds/tilted15.realtime.world index ce3c32e8d9..02a4f994bb 100644 --- a/worlds/tilted15.realtime.world +++ b/worlds/tilted15.realtime.world @@ -9,7 +9,7 @@ 0.001 - 1000 + 5000 From 34503b84500b41ccf355f8b8d3eae54770365020 Mon Sep 17 00:00:00 2001 From: Karine Date: Wed, 18 Sep 2019 19:15:49 +0200 Subject: [PATCH 11/45] setting experiments and fix fitness hill --- .../karines_experiments/manager_pop.py | 124 ------------------ .../karines_experiments/manager_pop_lava.py | 124 ------------------ .../karines_experiments/run-experiments | 20 +-- pyrevolve/evolution/fitness.py | 18 --- 4 files changed, 11 insertions(+), 275 deletions(-) delete mode 100755 experiments/karines_experiments/manager_pop.py delete mode 100755 experiments/karines_experiments/manager_pop_lava.py diff --git a/experiments/karines_experiments/manager_pop.py b/experiments/karines_experiments/manager_pop.py deleted file mode 100755 index 2c4952a9be..0000000000 --- a/experiments/karines_experiments/manager_pop.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python3 -import asyncio - -from pyrevolve import parser -from pyrevolve.evolution import fitness -from pyrevolve.evolution.selection import multiple_selection, tournament_selection -from pyrevolve.evolution.population import Population, PopulationConfig -from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management -from pyrevolve.experiment_management import ExperimentManagement -from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig -from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover -from pyrevolve.genotype.plasticoding.initialization import random_initialization -from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig -from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation -from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig -from pyrevolve.tol.manage import measures -from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue -from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue -from pyrevolve.custom_logging.logger import logger - - -async def run(): - """ - The main coroutine, which is started below. - """ - - # experiment params # - num_generations = 100 - population_size = 100 - offspring_size = 50 - - genotype_conf = PlasticodingConfig( - max_structural_modules=15, - ) - - mutation_conf = MutationConfig( - mutation_prob=0.8, - genotype_conf=genotype_conf, - ) - - crossover_conf = CrossoverConfig( - crossover_prob=0.8, - ) - # experiment params # - - # Parse command line / file input arguments - settings = parser.parse_args() - experiment_management = ExperimentManagement(settings) - do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() - - logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) - - if do_recovery: - gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, offspring_size) - - if gen_num == num_generations-1: - logger.info('Experiment is already complete.') - return - else: - gen_num = 0 - next_robot_id = 1 - - def fitness_function(robot_manager, robot): - contacts = measures.contacts(robot_manager, robot) - assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) - - population_conf = PopulationConfig( - population_size=population_size, - genotype_constructor=random_initialization, - genotype_conf=genotype_conf, - fitness_function=fitness_function, - mutation_operator=standard_mutation, - mutation_conf=mutation_conf, - crossover_operator=standard_crossover, - crossover_conf=crossover_conf, - selection=lambda individuals: tournament_selection(individuals, 2), - parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection), - population_management=steady_state_population_management, - population_management_selector=tournament_selection, - evaluation_time=settings.evaluation_time, - offspring_size=offspring_size, - experiment_name=settings.experiment_name, - experiment_management=experiment_management, - measure_individuals=settings.measure_individuals, - ) - - settings = parser.parse_args() - simulator_queue = SimulatorQueue(settings.n_cores, settings, settings.port_start) - await simulator_queue.start() - - analyzer_queue = AnalyzerQueue(1, settings, settings.port_start+settings.n_cores) - await analyzer_queue.start() - - population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) - - if do_recovery: - # loading a previous state of the experiment - await population.load_snapshot(gen_num) - if gen_num >= 0: - logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') - if has_offspring: - individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) - gen_num += 1 - logger.info('Recovered unfinished offspring '+str(gen_num)) - - if gen_num == 0: - await population.init_pop(individuals) - else: - population = await population.next_gen(gen_num, individuals) - - experiment_management.export_snapshots(population.individuals, gen_num) - else: - # starting a new experiment - experiment_management.create_exp_folders() - await population.init_pop() - experiment_management.export_snapshots(population.individuals, gen_num) - - while gen_num < num_generations-1: - gen_num += 1 - population = await population.next_gen(gen_num) - experiment_management.export_snapshots(population.individuals, gen_num) - - # output result after completing all generations... diff --git a/experiments/karines_experiments/manager_pop_lava.py b/experiments/karines_experiments/manager_pop_lava.py deleted file mode 100755 index afe6ef6430..0000000000 --- a/experiments/karines_experiments/manager_pop_lava.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python3 -import asyncio - -from pyrevolve import parser -from pyrevolve.evolution import fitness -from pyrevolve.evolution.selection import multiple_selection, tournament_selection -from pyrevolve.evolution.population import Population, PopulationConfig -from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management -from pyrevolve.experiment_management import ExperimentManagement -from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig -from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover -from pyrevolve.genotype.plasticoding.initialization import random_initialization -from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig -from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation -from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig -from pyrevolve.tol.manage import measures -from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue -from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue -from pyrevolve.custom_logging.logger import logger - - -async def run(): - """ - The main coroutine, which is started below. - """ - - # experiment params # - num_generations = 100 - population_size = 100 - offspring_size = 50 - - genotype_conf = PlasticodingConfig( - max_structural_modules=15, - ) - - mutation_conf = MutationConfig( - mutation_prob=0.8, - genotype_conf=genotype_conf, - ) - - crossover_conf = CrossoverConfig( - crossover_prob=0.8, - ) - # experiment params # - - # Parse command line / file input arguments - settings = parser.parse_args() - experiment_management = ExperimentManagement(settings) - do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() - - logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) - - if do_recovery: - gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, offspring_size) - - if gen_num == num_generations-1: - logger.info('Experiment is already complete.') - return - else: - gen_num = 0 - next_robot_id = 1 - - def fitness_function(robot_manager, robot): - contacts = measures.contacts(robot_manager, robot) - assert(contacts != 0) - return fitness.floor_is_lava(robot_manager, robot, False) - - population_conf = PopulationConfig( - population_size=population_size, - genotype_constructor=random_initialization, - genotype_conf=genotype_conf, - fitness_function=fitness_function, - mutation_operator=standard_mutation, - mutation_conf=mutation_conf, - crossover_operator=standard_crossover, - crossover_conf=crossover_conf, - selection=lambda individuals: tournament_selection(individuals, 2), - parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection), - population_management=steady_state_population_management, - population_management_selector=tournament_selection, - evaluation_time=settings.evaluation_time, - offspring_size=offspring_size, - experiment_name=settings.experiment_name, - experiment_management=experiment_management, - measure_individuals=settings.measure_individuals, - ) - - settings = parser.parse_args() - simulator_queue = SimulatorQueue(settings.n_cores, settings, settings.port_start) - await simulator_queue.start() - - analyzer_queue = AnalyzerQueue(1, settings, settings.port_start+settings.n_cores) - await analyzer_queue.start() - - population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) - - if do_recovery: - # loading a previous state of the experiment - await population.load_snapshot(gen_num) - if gen_num >= 0: - logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') - if has_offspring: - individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) - gen_num += 1 - logger.info('Recovered unfinished offspring '+str(gen_num)) - - if gen_num == 0: - await population.init_pop(individuals) - else: - population = await population.next_gen(gen_num, individuals) - - experiment_management.export_snapshots(population.individuals, gen_num) - else: - # starting a new experiment - experiment_management.create_exp_folders() - await population.init_pop() - experiment_management.export_snapshots(population.individuals, gen_num) - - while gen_num < num_generations-1: - gen_num += 1 - population = await population.next_gen(gen_num) - experiment_management.export_snapshots(population.individuals, gen_num) - - # output result after completing all generations... diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index ffe89c5a1b..91ced527bf 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -2,8 +2,8 @@ while true do - for i in {1..10}; do - ./revolve.py --experiment-name karines_experiments/data/plane_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11400 --world worlds/plane.world --evaluation-time 50; + for i in {1..30}; do + ./revolve.py --experiment-name karines_experiments/data/plane_$i --run $i --manager experiments/karines_experiments/plane.py --n-cores 3 --port-start 11400 --world worlds/plane.world --evaluation-time 50; sleep 5s done done @@ -14,24 +14,24 @@ done while true do - for i in {1..10}; do - ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/manager_pop_lava.py --n-cores 3 --port-start 11700 --world worlds/plane.world --evaluation-time 50; + for i in {1..30}; do + ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/lava.py --n-cores 3 --port-start 11700 --world worlds/plane.world --evaluation-time 50; sleep 5s done done while true do - for i in {1..10}; do - ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11800 --world worlds/tilted15.world --z-start 0.18 --evaluation-time 50; + for i in {1..30}; do + ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/tilted.py --n-cores 3 --port-start 11800 --world worlds/tilted10.world --z-start 0.1 --evaluation-time 50; sleep 5s done done while true do - for i in {1..10}; do - ./revolve.py --experiment-name karines_experiments/data/obstacles_$i --run $i --manager experiments/karines_experiments/manager_pop.py --n-cores 3 --port-start 11900 --world worlds/planeobstacles.world --z-start 0.05 --evaluation-time 50; + for i in {1..30}; do + ./revolve.py --experiment-name karines_experiments/data/obstacles_$i --run $i --manager experiments/karines_experiments/obstacles.py --n-cores 3 --port-start 11900 --world worlds/planeobstacles.world --z-start 0.05 --evaluation-time 50; sleep 5s done done @@ -45,4 +45,6 @@ while true sleep 1800s; kill $( ps aux | grep 'gzserver' | awk '{print $2}'); kill $( ps aux | grep 'revolve.py' | awk '{print $2}'); -done \ No newline at end of file +done + + diff --git a/pyrevolve/evolution/fitness.py b/pyrevolve/evolution/fitness.py index 01ae0a22ce..790b409854 100644 --- a/pyrevolve/evolution/fitness.py +++ b/pyrevolve/evolution/fitness.py @@ -57,24 +57,6 @@ def size_penalty(robot_manager, robot): return _size_penalty -def displacement_velocity_hill2(robot_manager, robot, cost=False): - fitness = measures.displacement_velocity_hill(robot_manager) - - if fitness == 0: - fitness = -0.1 - - elif fitness < 0: - fitness /= 10 - - if cost and fitness != None: - _size_penalty = size_penalty(robot_manager, robot) ** 2 - if fitness >= 0: - fitness = fitness * _size_penalty - else: - fitness = fitness / _size_penalty - - return fitness - def displacement_velocity_hill(robot_manager, robot, cost=False): fitness = measures.displacement_velocity_hill(robot_manager) From ccff5cf61f0d7978344e7ea8682e0c05b808b7a2 Mon Sep 17 00:00:00 2001 From: Karine Date: Mon, 23 Sep 2019 20:01:15 +0200 Subject: [PATCH 12/45] fix environments --- .../manager_pop_lava_cost.py | 124 - .../karines_experiments/run-experiments | 8 +- worlds/plane.realtime.world | 4 +- worlds/planeobstacles.realtime.world | 2 +- worlds/planeobstacles.world | 4716 ++++++++++++++++- worlds/tilted10.realtime.world | 2 +- worlds/tilted10.world | 2 +- worlds/tilted5.realtime.world | 2 +- 8 files changed, 4724 insertions(+), 136 deletions(-) delete mode 100755 experiments/karines_experiments/manager_pop_lava_cost.py diff --git a/experiments/karines_experiments/manager_pop_lava_cost.py b/experiments/karines_experiments/manager_pop_lava_cost.py deleted file mode 100755 index 499eba406b..0000000000 --- a/experiments/karines_experiments/manager_pop_lava_cost.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python3 -import asyncio - -from pyrevolve import parser -from pyrevolve.evolution import fitness -from pyrevolve.evolution.selection import multiple_selection, tournament_selection -from pyrevolve.evolution.population import Population, PopulationConfig -from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management -from pyrevolve.experiment_management import ExperimentManagement -from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig -from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover -from pyrevolve.genotype.plasticoding.initialization import random_initialization -from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig -from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation -from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig -from pyrevolve.tol.manage import measures -from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue -from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue -from pyrevolve.custom_logging.logger import logger - - -async def run(): - """ - The main coroutine, which is started below. - """ - - # experiment params # - num_generations = 100 - population_size = 100 - offspring_size = 50 - - genotype_conf = PlasticodingConfig( - # max_structural_modules=15, - ) - - mutation_conf = MutationConfig( - mutation_prob=0.8, - genotype_conf=genotype_conf, - ) - - crossover_conf = CrossoverConfig( - crossover_prob=0.8, - ) - # experiment params # - - # Parse command line / file input arguments - settings = parser.parse_args() - experiment_management = ExperimentManagement(settings) - do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() - - logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) - - if do_recovery: - gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, offspring_size) - - if gen_num == num_generations-1: - logger.info('Experiment is already complete.') - return - else: - gen_num = 0 - next_robot_id = 1 - - def fitness_function(robot_manager, robot): - contacts = measures.contacts(robot_manager, robot) - assert(contacts != 0) - return fitness.floor_is_lava(robot_manager, robot, True) - - population_conf = PopulationConfig( - population_size=population_size, - genotype_constructor=random_initialization, - genotype_conf=genotype_conf, - fitness_function=fitness_function, - mutation_operator=standard_mutation, - mutation_conf=mutation_conf, - crossover_operator=standard_crossover, - crossover_conf=crossover_conf, - selection=lambda individuals: tournament_selection(individuals, 2), - parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection), - population_management=steady_state_population_management, - population_management_selector=tournament_selection, - evaluation_time=settings.evaluation_time, - offspring_size=offspring_size, - experiment_name=settings.experiment_name, - experiment_management=experiment_management, - measure_individuals=settings.measure_individuals, - ) - - settings = parser.parse_args() - simulator_queue = SimulatorQueue(settings.n_cores, settings, settings.port_start) - await simulator_queue.start() - - analyzer_queue = AnalyzerQueue(1, settings, settings.port_start+settings.n_cores) - await analyzer_queue.start() - - population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) - - if do_recovery: - # loading a previous state of the experiment - await population.load_snapshot(gen_num) - if gen_num >= 0: - logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') - if has_offspring: - individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) - gen_num += 1 - logger.info('Recovered unfinished offspring '+str(gen_num)) - - if gen_num == 0: - await population.init_pop(individuals) - else: - population = await population.next_gen(gen_num, individuals) - - experiment_management.export_snapshots(population.individuals, gen_num) - else: - # starting a new experiment - experiment_management.create_exp_folders() - await population.init_pop() - experiment_management.export_snapshots(population.individuals, gen_num) - - while gen_num < num_generations-1: - gen_num += 1 - population = await population.next_gen(gen_num) - experiment_management.export_snapshots(population.individuals, gen_num) - - # output result after completing all generations... diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index 91ced527bf..2712328994 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -3,7 +3,7 @@ while true do for i in {1..30}; do - ./revolve.py --experiment-name karines_experiments/data/plane_$i --run $i --manager experiments/karines_experiments/plane.py --n-cores 3 --port-start 11400 --world worlds/plane.world --evaluation-time 50; + ./revolve.py --experiment-name karines_experiments/data/plane_$i --run $i --manager experiments/karines_experiments/plane.py --n-cores 4 --port-start 11400 --world worlds/plane.world --evaluation-time 50; sleep 5s done done @@ -15,7 +15,7 @@ done while true do for i in {1..30}; do - ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/lava.py --n-cores 3 --port-start 11700 --world worlds/plane.world --evaluation-time 50; + ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/lava.py --n-cores 4 --port-start 11700 --world worlds/plane.world --evaluation-time 50; sleep 5s done done @@ -23,7 +23,7 @@ done while true do for i in {1..30}; do - ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/tilted.py --n-cores 3 --port-start 11800 --world worlds/tilted10.world --z-start 0.1 --evaluation-time 50; + ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/tilted.py --n-cores 4 --port-start 11800 --world worlds/tilted10.world --z-start 0.1 --evaluation-time 50; sleep 5s done done @@ -31,7 +31,7 @@ done while true do for i in {1..30}; do - ./revolve.py --experiment-name karines_experiments/data/obstacles_$i --run $i --manager experiments/karines_experiments/obstacles.py --n-cores 3 --port-start 11900 --world worlds/planeobstacles.world --z-start 0.05 --evaluation-time 50; + ./revolve.py --experiment-name karines_experiments/data/obstacles_$i --run $i --manager experiments/karines_experiments/obstacles.py --n-cores 4 --port-start 11900 --world worlds/planeobstacles2.world --z-start 0.05 --evaluation-time 50; sleep 5s done done diff --git a/worlds/plane.realtime.world b/worlds/plane.realtime.world index 3f27a33fe8..4a710a7b58 100644 --- a/worlds/plane.realtime.world +++ b/worlds/plane.realtime.world @@ -7,10 +7,10 @@ - 0.001 + 0.005 - 5000 + 1000 diff --git a/worlds/planeobstacles.realtime.world b/worlds/planeobstacles.realtime.world index d91e14a26b..167cbaee98 100644 --- a/worlds/planeobstacles.realtime.world +++ b/worlds/planeobstacles.realtime.world @@ -6,7 +6,7 @@ 0 - 0.001 + 0.005 5000 diff --git a/worlds/planeobstacles.world b/worlds/planeobstacles.world index 28148c0e33..d0350221f5 100644 --- a/worlds/planeobstacles.world +++ b/worlds/planeobstacles.world @@ -6,7 +6,7 @@ 0 - 0.001 + 0.005 0.0 @@ -25,7 +25,4719 @@ - + + + + + -1 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.93 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -1 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.93 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -1 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.93 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -1 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.93 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.82 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.75 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.82 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.75 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.82 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.75 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.82 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.75 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.64 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.57 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.64 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.57 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.64 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.57 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.64 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.57 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.46 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.39 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.46 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.39 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.46 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.39 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.46 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.39 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.28 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.21 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.28 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.21 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.28 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.21 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.28 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.21 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + -0.0999999999999998 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.0299999999999998 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.0999999999999998 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.0299999999999998 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.0999999999999998 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.0299999999999998 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.0999999999999998 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + -0.0299999999999998 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.0800000000000002 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.15 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.0800000000000002 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.15 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.0800000000000002 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.15 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.0800000000000002 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.15 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.26 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.33 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.26 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.33 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.26 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.33 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.26 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.33 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.44 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.51 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.44 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.51 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.44 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.51 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.44 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.51 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.62 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.69 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.62 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.69 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.62 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.69 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.62 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.69 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.8 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.87 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.8 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.87 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.8 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.87 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.8 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.87 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.03 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.03 + + + + + + + 0 + 0 + 1 + + + + 0.98 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 1.05 -0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.98 -0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 1.05 -0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.98 0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 1.05 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 0.98 0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + 1.05 0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.06 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.06 + + + + + + + 0 + 0 + 1 + + + + + + + + -1 -1 0 0 0 0 diff --git a/worlds/tilted10.realtime.world b/worlds/tilted10.realtime.world index 4828e4da1d..75ae943e00 100644 --- a/worlds/tilted10.realtime.world +++ b/worlds/tilted10.realtime.world @@ -6,7 +6,7 @@ 0 - 0.003 + 0.005 1000 diff --git a/worlds/tilted10.world b/worlds/tilted10.world index e469720525..29ee9f85bd 100644 --- a/worlds/tilted10.world +++ b/worlds/tilted10.world @@ -6,7 +6,7 @@ 0 - 0.003 + 0.005 0 diff --git a/worlds/tilted5.realtime.world b/worlds/tilted5.realtime.world index aa995ebde1..95d13320a5 100644 --- a/worlds/tilted5.realtime.world +++ b/worlds/tilted5.realtime.world @@ -6,7 +6,7 @@ 0 - 0.003 + 0.005 1000 From f265b462424be5d8a2249db8b3b58f0752ada7af Mon Sep 17 00:00:00 2001 From: Karine Date: Mon, 23 Sep 2019 20:02:01 +0200 Subject: [PATCH 13/45] new environment --- worlds/planeobstacles2.realtime.world | 2781 +++++++++++++++++++++++++ worlds/planeobstacles2.world | 2781 +++++++++++++++++++++++++ 2 files changed, 5562 insertions(+) create mode 100644 worlds/planeobstacles2.realtime.world create mode 100644 worlds/planeobstacles2.world diff --git a/worlds/planeobstacles2.realtime.world b/worlds/planeobstacles2.realtime.world new file mode 100644 index 0000000000..6ff1a76298 --- /dev/null +++ b/worlds/planeobstacles2.realtime.world @@ -0,0 +1,2781 @@ + + + + + 0 + 0 + + + 0.005 + + + 1000 + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + -0.6 -0.6 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.53 -0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.6 -0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.53 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.6 6.93889390390723e-17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.53 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.6 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.53 0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.42 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.35 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.42 -0.2 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.35 -0.05 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.42 0.1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.35 0.25 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.42 0.4 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.35 0.55 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.24 -0.6 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.17 -0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.24 -0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.17 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.24 6.93889390390723e-17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.17 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.24 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.17 0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0599999999999999 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0100000000000001 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.0599999999999999 -0.2 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0100000000000001 -0.05 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.0599999999999999 0.1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0100000000000001 0.25 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.0599999999999999 0.4 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0100000000000001 0.55 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.12 -0.6 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.19 -0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.12 -0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.19 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.12 6.93889390390723e-17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.19 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.12 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.19 0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.3 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.37 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.3 -0.2 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.37 -0.05 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.3 0.1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.37 0.25 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.3 0.4 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.37 0.55 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.48 -0.6 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.55 -0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.48 -0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.55 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.48 6.93889390390723e-17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.55 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.48 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.55 0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + + model://sun + + + model://tol_ground + + + + diff --git a/worlds/planeobstacles2.world b/worlds/planeobstacles2.world new file mode 100644 index 0000000000..c8b893892c --- /dev/null +++ b/worlds/planeobstacles2.world @@ -0,0 +1,2781 @@ + + + + + 0 + 0 + + + 0.005 + + + 0.0 + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + -0.6 -0.6 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.53 -0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.6 -0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.53 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.6 6.93889390390723e-17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.53 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.6 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.53 0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.42 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.35 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.42 -0.2 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.35 -0.05 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.42 0.1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.35 0.25 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.42 0.4 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.35 0.55 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.24 -0.6 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.17 -0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.24 -0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.17 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.24 6.93889390390723e-17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.17 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.24 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.17 0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0599999999999999 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0100000000000001 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.0599999999999999 -0.2 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0100000000000001 -0.05 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.0599999999999999 0.1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0100000000000001 0.25 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.0599999999999999 0.4 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0100000000000001 0.55 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.12 -0.6 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.19 -0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.12 -0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.19 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.12 6.93889390390723e-17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.19 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.12 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.19 0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.3 -0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.37 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.3 -0.2 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.37 -0.05 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.3 0.1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.37 0.25 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.3 0.4 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.37 0.55 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.48 -0.6 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.55 -0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.48 -0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.55 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.48 6.93889390390723e-17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.55 0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.48 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.55 0.45 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.05 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.05 0.01 + + + + + + + 0 + 0 + 1 + + + + + model://sun + + + model://tol_ground + + + + From b29d17ad9d9c93b43770439407f08307d984beec Mon Sep 17 00:00:00 2001 From: Karine Date: Mon, 30 Sep 2019 16:50:13 +0200 Subject: [PATCH 14/45] improves exportation of best robots pics --- .../karines_experiments/bestrobots_summary_renders.r | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/experiments/karines_experiments/bestrobots_summary_renders.r b/experiments/karines_experiments/bestrobots_summary_renders.r index 1ee92c23c7..40ee0ea3c3 100644 --- a/experiments/karines_experiments/bestrobots_summary_renders.r +++ b/experiments/karines_experiments/bestrobots_summary_renders.r @@ -23,7 +23,6 @@ paths = c( ) - base_directory <- paste('projects/revolve/experiments/karines_experiments/data/', sep='') experiments = 30 @@ -31,11 +30,11 @@ gens = 100 pop = 100 num_top = 3 -analysis = '1images' +analysis = 'images' ##### change paths/labels/params here ##### -output_directory = paste(base_directory, '/',analysis, sep='') +output_directory = paste(base_directory,analysis, sep='') file <-file(paste(output_directory,'/best.txt',sep=''), open="w") @@ -73,7 +72,8 @@ for(m in 1:length(paths)) body <- list.files(patha, paste("body_robot_",phenotype,".png$",sep=""), full.names = TRUE) body = image_read(body) - body = image_border(image_background(body, "white"), "white", "20x33") + body = image_scale(body, "100x100") + body = image_border(image_background(body, "white"), "white", "5x5") if(b == 1) @@ -85,7 +85,7 @@ for(m in 1:length(paths)) } side_by_side = image_append(bodies, stack=F) - image_write(side_by_side, path = paste(output_directory,"/",paths[m],"_bodies_best_",exp,".pdf",sep=''), format = "pdf") + image_write(side_by_side, path = paste(output_directory,"/",methods[m],"_bodies_best_",exp,".png",sep=''), format = "png") } } From 1e07fd15ff45f22bd74359f51b77dbaa5242bf63 Mon Sep 17 00:00:00 2001 From: Milan Jelisavcic Date: Sat, 2 Nov 2019 13:15:28 +0100 Subject: [PATCH 15/45] Add Gitpod button to README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 622636024e..f85e9f23df 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ If you want to contribute to Revolve, be sure to review the [contribution guidelines](CONTRIBUTING.md). By participating, you are expected to uphold this code. +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/ci-group/revolve) + We use [GitHub issues](https://github.com/ci-group/revolve/issues) for tracking requests and bugs. From 7bf8b3abdc6c566b45bc19a6e4095ae2434fb24d Mon Sep 17 00:00:00 2001 From: Karine Date: Thu, 5 Dec 2019 21:48:54 +0100 Subject: [PATCH 16/45] init plastic grammar + plastic early develop part 1 --- .../karines_experiments/run-experiments | 36 +- .../karines_experiments/summary_measures.R | 438 ------------------ pyrevolve/config.py | 2 + pyrevolve/evolution/individual.py | 4 +- pyrevolve/evolution/population.py | 21 +- pyrevolve/experiment_management.py | 43 +- pyrevolve/genotype/genotype.py | 14 +- .../genotype/plasticoding/initialization.py | 96 +++- .../genotype/plasticoding/plasticoding.py | 75 ++- pyrevolve/revolve_bot/revolve_bot.py | 6 +- 10 files changed, 223 insertions(+), 512 deletions(-) delete mode 100644 experiments/karines_experiments/summary_measures.R diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index 2712328994..315be852b5 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -1,40 +1,16 @@ -#!/bin/bash - -while true - do - for i in {1..30}; do - ./revolve.py --experiment-name karines_experiments/data/plane_$i --run $i --manager experiments/karines_experiments/plane.py --n-cores 4 --port-start 11400 --world worlds/plane.world --evaluation-time 50; - sleep 5s - done -done + #!/bin/bash -#### others... - +# baseline while true do - for i in {1..30}; do - ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/lava.py --n-cores 4 --port-start 11700 --world worlds/plane.world --evaluation-time 50; + for i in {1..1}; do + ./revolve.py --experiment-name karines_experiments/data/baseline_$i --run $i --manager experiments/karines_experiments/baseline.py --n-cores 4 --port-start 11400 --world worlds/plane.world --evaluation-time 50; sleep 5s done done -while true - do - for i in {1..30}; do - ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/tilted.py --n-cores 4 --port-start 11800 --world worlds/tilted10.world --z-start 0.1 --evaluation-time 50; - sleep 5s - done -done - -while true - do - for i in {1..30}; do - ./revolve.py --experiment-name karines_experiments/data/obstacles_$i --run $i --manager experiments/karines_experiments/obstacles.py --n-cores 4 --port-start 11900 --world worlds/planeobstacles2.world --z-start 0.05 --evaluation-time 50; - sleep 5s - done -done @@ -48,3 +24,7 @@ while true done + + + + #./revolve.py --experiment-name karines_experiments/data/tilted5_$i --run $i --manager experiments/karines_experiments/tilted.py --n-cores 4 --port-start 11800 --world worlds/tilted5.world --z-start 0.1 --evaluation-time 50; diff --git a/experiments/karines_experiments/summary_measures.R b/experiments/karines_experiments/summary_measures.R deleted file mode 100644 index 5178b40145..0000000000 --- a/experiments/karines_experiments/summary_measures.R +++ /dev/null @@ -1,438 +0,0 @@ -library(ggplot2) -library(sqldf) -library(plyr) -library(dplyr) -library(trend) -library(purrr) - -base_directory <- paste('projects/revolve/experiments/karines_experiments/data', sep='') - -analysis = 'test' -output_directory = paste(base_directory,'/',analysis ,sep='') - -#### CHANGE THE PARAMETERS HERE #### - - -experiments_type = c( - 'plane', - 'lava' - ) - -initials = c('p', 'l') - -experiments_labels = c('Plane', 'Floor is lava') - -runs = c(1,2,3,4,5,6,7,8,9,10) -gens = 100 -pop = 100 - -#### CHANGE THE PARAMETERS HERE #### - -sig = 0.05 -line_size = 30 -show_markers = TRUE -show_legends = TRUE -experiments_type_colors = c( '#009900', '#FF8000', '#BA1616', '#000099') # DARK:green, orange, red, blue - -measures_names = c( - 'displacement_velocity_hill', - 'head_balance', - 'contacts', - 'displacement_velocity', - 'branching', - 'branching_modules_count', - 'limbs', - 'extremities', - 'length_of_limbs', - 'extensiveness', - 'coverage', - 'joints', - 'hinge_count', - 'active_hinges_count', - 'brick_count', - 'touch_sensor_count', - 'brick_sensor_count', - 'proportion', - 'width', - 'height', - 'absolute_size', - 'sensors', - 'symmetry', - 'avg_period', - 'dev_period', - 'avg_phase_offset', - 'dev_phase_offset', - 'avg_amplitude', - 'dev_amplitude', - 'avg_intra_dev_params', - 'avg_inter_dev_params', - 'sensors_reach', - 'recurrence', - 'synaptic_reception', - 'fitness' -) - -# add proper labels soon... -measures_labels = c( - 'Speed', - 'Balance', - 'Contacts', - 'displacement_velocity', - 'branching', - 'branching_modules_count', - 'limbs', - 'extremities', - 'length_of_limbs', - 'extensiveness', - 'coverage', - 'joints', - 'hinge_count', - 'active_hinges_count', - 'brick_count', - 'touch_sensor_count', - 'brick_sensor_count', - 'proportion', - 'width', - 'height', - 'absolute_size', - 'sensors', - 'symmetry', - 'avg_period', - 'dev_period', - 'avg_phase_offset', - 'dev_phase_offset', - 'avg_amplitude', - 'dev_amplitude', - 'avg_intra_dev_params', - 'avg_inter_dev_params', - 'sensors_reach', - 'recurrence', - 'synaptic_reception', - 'Fitness' -) - - -measures_snapshots_all = NULL - -for (exp in 1:length(experiments_type)) -{ - for(run in runs) - { - input_directory <- paste(base_directory, '/', experiments_type[exp], '_', run, sep='') - measures = read.table(paste(input_directory,"/all_measures.tsv", sep=''), header = TRUE) - for( m in 1:length(measures_names)) - { - measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) - } - - snapshots = read.table(paste(input_directory,"/snapshots_ids.tsv", sep=''), header = TRUE) - measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') - - measures_snapshots$run = run - measures_snapshots$run = as.factor(measures_snapshots$run) - measures_snapshots$method = experiments_type[exp] - - if ( is.null(measures_snapshots_all)){ - measures_snapshots_all = measures_snapshots - }else{ - measures_snapshots_all = rbind(measures_snapshots_all, measures_snapshots) - } - } -} - - -fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) - - -measures_snapshots_all = sqldf("select * from measures_snapshots_all where fitness IS NOT NULL") - - - -measures_averages_gens_1 = list() -measures_averages_gens_2 = list() - -measures_ini = list() -measures_fin = list() - -for (exp in 1:length(experiments_type)) -{ - - measures_aux = c() - query ='select run, generation' - for (i in 1:length(measures_names)) - { - query = paste(query,', avg(',measures_names[i],') as ',experiments_type[exp],'_',measures_names[i],'_avg', sep='') - } - query = paste(query,' from measures_snapshots_all - where method="',experiments_type[exp],'" group by run, generation', sep='') - - - measures_averages_gens_1[[exp]] = sqldf(query) - - temp = measures_averages_gens_1[[exp]] - - temp$generation = as.numeric(temp$generation) - - measures_ini[[exp]] = sqldf(paste("select * from temp where generation=1")) - measures_fin[[exp]] = sqldf(paste("select * from temp where generation=",gens-1)) - query = 'select generation' - for (i in 1:length(measures_names)) - { - # later renames vars _avg_SUMMARY, just to make it in the same style as the quantile variables - query = paste(query,', avg(',experiments_type[exp],'_',measures_names[i],'_avg) as ',experiments_type[exp],'_',measures_names[i],'_avg', sep='') - query = paste(query,', max(',experiments_type[exp],'_',measures_names[i],'_avg) as ',experiments_type[exp],'_',measures_names[i],'_max', sep='') - query = paste(query,', stdev(',experiments_type[exp],'_',measures_names[i],'_avg) as ',experiments_type[exp],'_',measures_names[i],'_stdev', sep='') - query = paste(query,', median(',experiments_type[exp],'_',measures_names[i],'_avg) as ',experiments_type[exp],'_',measures_names[i],'_median', sep='') - - measures_aux = c(measures_aux, paste(experiments_type[exp],'_',measures_names[i],'_avg', sep='') ) - } - query = paste(query,' from temp group by generation', sep="") - - temp2 = sqldf(query) - - p <- c(0.25, 0.75) - p_names <- map_chr(p, ~paste0('Q',.x*100, sep="")) - p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>% - set_names(nm = p_names) - - quantiles = data.frame(temp %>% - group_by(generation) %>% - summarize_at(vars(measures_aux), funs(!!!p_funs)) ) - - measures_averages_gens_2[[exp]] = sqldf('select * from temp2 inner join quantiles using (generation)') - -} - - -for (exp in 1:length(experiments_type)) -{ - if(exp==1){ - measures_averages_gens = measures_averages_gens_2[[1]] - }else{ - measures_averages_gens = merge(measures_averages_gens, measures_averages_gens_2[[exp]], by = "generation") - } -} - -file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") - -#tests trends in curves and difference between ini and fin generations - - -# ini VS fin -array_wilcoxon = list() -array_wilcoxon2 = list() - -# curve -array_mann = list() - - -for (m in 1:length(experiments_type)) -{ - - array_wilcoxon[[m]] = list() - array_mann[[m]] = list() - - for (i in 1:length(measures_names)) - { - - writeLines(paste(experiments_type[m],measures_names[i],'ini avg ',as.character( - mean(c(array(measures_ini[[m]][paste(experiments_type[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) - - - writeLines(paste(experiments_type[m],measures_names[i],'fin avg ',as.character( - mean(c(array(measures_fin[[m]][paste(experiments_type[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) - - array_wilcoxon[[m]][[i]] = wilcox.test(c(array(measures_ini[[m]][paste(experiments_type[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , - c(array(measures_fin[[m]][paste(experiments_type[m],"_",measures_names[i],"_avg",sep='')]))[[1]] - ) - - writeLines(c( - paste(experiments_type[m],'iniVSfin',measures_names[i],'wilcox p: ',as.character(round(array_wilcoxon[[m]][[i]]$p.value,4)), sep=' ') - ,paste(experiments_type[m],'iniVSfin',measures_names[i],'wilcox est: ',as.character(round(array_wilcoxon[[m]][[i]]$statistic,4)), sep=' ') - - ), file) - - - #tests trends - array_mann[[m]][[i]] = mk.test(c(array(measures_averages_gens_2[[m]][paste(experiments_type[m],"_",measures_names[i],'_median',sep='')]) )[[1]], - continuity = TRUE) - - - writeLines(c( - paste(experiments_type[m],measures_names[i], ' Mann-Kendall median p', as.character(round(array_mann[[m]][[i]]$p.value,4)),sep=' '), - paste(experiments_type[m],measures_names[i], ' Mann-Kendall median s', as.character(round(array_mann[[m]][[i]]$statistic,4)),sep=' ') - ), file) - - } - -} - - - -# tests final generation among experiments_type - -aux_m = length(experiments_type) - -if (aux_m>1) -{ - - # fins - array_wilcoxon2[[1]] = list() - array_wilcoxon2[[2]] = list() - -aux_m = aux_m -1 -count_pairs = 0 -for(m in 1:aux_m) -{ - aux = m+1 - for(m2 in aux:length(experiments_type)) - { - - count_pairs = count_pairs+1 - array_wilcoxon2[[1]][[count_pairs]] = list() - - for (i in 1:length(measures_names)) - { - - writeLines(paste(experiments_type[m],measures_names[i],'fin avg ',as.character( - mean(c(array(measures_fin[[m]][paste(experiments_type[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) - - writeLines(paste(experiments_type[m2],measures_names[i],'fin avg ',as.character( - mean(c(array(measures_fin[[m2]][paste(experiments_type[m2],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) - - array_wilcoxon2[[1]][[count_pairs]][[i]] = wilcox.test(c(array(measures_fin[[m]][paste(experiments_type[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , - c(array(measures_fin[[m2]][paste(experiments_type[m2],"_",measures_names[i],"_avg",sep='')]))[[1]] - ) - - writeLines(c( - paste(experiments_type[m],'VS',experiments_type[m2],measures_names[i],'fin avg wilcox p: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$p.value,4)), sep=' ') - ,paste(experiments_type[m],'VS',experiments_type[m2],measures_names[i],'fin avg wilcox est: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$statistic,4)), sep=' ') - - ), file) - - } - - - array_wilcoxon2[[2]][[count_pairs]] = paste(initials[m],initials[m2],sep='') - - } -} - -} - -close(file) - -# plots measures - -for (type_summary in c('means','quants')) -{ - - - for (i in 1:length(measures_names)) - { - tests1 = '' - tests2 = '' - tests3 = '' - break_aux = 0 - - graph <- ggplot(data=measures_averages_gens, aes(x=generation)) - - for(m in 1:length(experiments_type)) - { - if(type_summary == 'means') - { - graph = graph + geom_errorbar(aes_string(ymin=paste(experiments_type[m],'_',measures_names[i],'_avg','-',experiments_type[m],'_',measures_names[i],'_stdev',sep=''), - ymax=paste(experiments_type[m],'_',measures_names[i],'_avg','+',experiments_type[m],'_',measures_names[i],'_stdev',sep='') ), - color=experiments_type_colors[m], - alpha=0.35,size=0.5,width=0.001) - }else - { - graph = graph + geom_errorbar(aes_string(ymin=paste(experiments_type[m],'_',measures_names[i],'_avg_Q25',sep=''), - ymax=paste(experiments_type[m],'_',measures_names[i],'_avg_Q75',sep='') ), - color=experiments_type_colors[m], - alpha=0.35,size=0.5,width=0.001) - } - } - - for(m in 1:length(experiments_type)) - { - if(type_summary == 'means') - { - if(show_legends == TRUE){ - graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) - }else{ - graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) - } - - }else{ - if(show_legends == TRUE){ - graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_median',sep='') , colour=shQuote(experiments_labels[m]) ),size=2 ) - }else{ - graph = graph + geom_line(aes_string(y=paste(experiments_type[m],'_',measures_names[i],'_median',sep='') ),size=2, color = experiments_type_colors[m] ) - } - } - - if (length(array_mann)>0) - { - if (length(array_mann[[m]])>0) - { - if(!is.na(array_mann[[m]][[i]]$p.value)) - { - if(array_mann[[m]][[i]]$p.value<=sig) - { - if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} - tests1 = paste(tests1, initials[m],direction,sep="") - } - } - } - } - } - - if (length(array_wilcoxon[[m]])>0) - { - for(m in 1:length(experiments_type)) - { - if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) - { - if(array_wilcoxon[[m]][[i]]$p.value<=sig) - { - tests2 = paste(tests2, initials[m],'C ', sep='') - } - } - } - } - - if (length(array_wilcoxon2)>0) - { - for(p in 1:length(array_wilcoxon2[[1]])) - { - if (length(array_wilcoxon2[[1]][[p]])>0) - { - if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) - { - if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) - { - if(nchar(tests3)>line_size && break_aux == 0){ - tests3 = paste(tests3, '\n') - break_aux = 1 - } - tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') - } - } - } - } - } - - graph = graph + - #coord_cartesian(ylim = c(0, 1))+ - labs( y=measures_labels[i], x="Generation") - if(show_markers == TRUE){ - graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) - } - graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=30),axis.title=element_text(size=39), - plot.subtitle=element_text(size=25 )) - - ggsave(paste( output_directory,'/',type_summary,'_' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 8, width = 10) - } - -} diff --git a/pyrevolve/config.py b/pyrevolve/config.py index 2bd29d0ad7..b9fa31f38b 100644 --- a/pyrevolve/config.py +++ b/pyrevolve/config.py @@ -384,6 +384,8 @@ def str_to_address(v): help="Name of current experiment. A folder with this name will be created." ) + + parser.add_argument( '--run', default='1', type=str, diff --git a/pyrevolve/evolution/individual.py b/pyrevolve/evolution/individual.py index c2448b3423..fbc8e6fad7 100644 --- a/pyrevolve/evolution/individual.py +++ b/pyrevolve/evolution/individual.py @@ -15,13 +15,13 @@ def __init__(self, genotype, phenotype=None): self.parents = None self.failed_eval_attempt_count = 0 - def develop(self): + def develop(self, environment): """ Develops genotype into a intermediate phenotype """ if self.phenotype is None: - self.phenotype = self.genotype.develop() + self.phenotype = self.genotype.develop(environment) @property def id(self): diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index 2c12a4faf2..84f884abba 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -7,7 +7,7 @@ import time import asyncio import os - +import sys class PopulationConfig: def __init__(self, @@ -27,6 +27,7 @@ def __init__(self, experiment_name, experiment_management, measure_individuals, + environments, offspring_size=None, next_robot_id=1): """ @@ -66,6 +67,7 @@ def __init__(self, self.measure_individuals = measure_individuals self.offspring_size = offspring_size self.next_robot_id = next_robot_id + self.environments = environments class Population: @@ -88,13 +90,15 @@ def __init__(self, conf: PopulationConfig, simulator_queue, analyzer_queue=None, self.next_robot_id = next_robot_id def _new_individual(self, genotype): + environment = 'plane' #TEMP!!! individual = Individual(genotype) - individual.develop() + individual.develop(environment) self.conf.experiment_management.export_genotype(individual) - self.conf.experiment_management.export_phenotype(individual) - self.conf.experiment_management.export_phenotype_images('data_fullevolution/phenotype_images', individual) + self.conf.experiment_management.export_phenotype(individual, environment) + self.conf.experiment_management.export_phenotype_images('data_fullevolution/' + +environment+'/phenotype_images', individual) individual.phenotype.measure_phenotype(self.conf.experiment_name) - individual.phenotype.export_phenotype_measurements(self.conf.experiment_name) + individual.phenotype.export_phenotype_measurements(self.conf.experiment_name, environment) return individual @@ -127,7 +131,7 @@ async def load_individual(self, id): if line.split(' ')[0] == 'displacement_velocity_hill': individual.phenotype._behavioural_measurements.displacement_velocity_hill = float(line.split(' ')[1]) if line.split(' ')[0] == 'head_balance': - individual.phenotype._behavioural_measurements.head_balance = float(line.split(' ')[1]) + individual.phenotype._behavioural_measurements.head_balance = None if line.split(' ')[1] == 'None\n' else float(line.split(' ')[1]) if line.split(' ')[0] == 'contacts': individual.phenotype._behavioural_measurements.contacts = float(line.split(' ')[1]) @@ -169,11 +173,12 @@ async def init_pop(self, recovered_individuals=[]): Populates the population (individuals list) with Individual objects that contains their respective genotype. """ for i in range(self.conf.population_size-len(recovered_individuals)): - individual = self._new_individual(self.conf.genotype_constructor(self.conf.genotype_conf, self.next_robot_id)) + individual = self._new_individual( + self.conf.genotype_constructor(self.conf.genotype_conf, self.next_robot_id)) self.individuals.append(individual) self.next_robot_id += 1 - await self.evaluate(self.individuals, 0) + # await self.evaluate(self.individuals, 0) self.individuals = recovered_individuals + self.individuals async def next_gen(self, gen_num, recovered_individuals=[]): diff --git a/pyrevolve/experiment_management.py b/pyrevolve/experiment_management.py index 72072e8d4e..2e817775b6 100644 --- a/pyrevolve/experiment_management.py +++ b/pyrevolve/experiment_management.py @@ -12,17 +12,20 @@ def __init__(self, settings): self.settings = settings self.dirpath = os.path.join('experiments', self.settings.experiment_name) - def create_exp_folders(self): + def create_exp_folders(self, environments): if os.path.exists(self.dirpath): shutil.rmtree(self.dirpath) os.mkdir(self.dirpath) os.mkdir(self.dirpath+'/data_fullevolution') os.mkdir(self.dirpath+'/data_fullevolution/genotypes') - os.mkdir(self.dirpath+'/data_fullevolution/phenotypes') - os.mkdir(self.dirpath+'/data_fullevolution/descriptors') - os.mkdir(self.dirpath+'/data_fullevolution/fitness') - os.mkdir(self.dirpath+'/data_fullevolution/phenotype_images') os.mkdir(self.dirpath+'/data_fullevolution/failed_eval_robots') + for environment in environments: + os.mkdir(self.dirpath+'/selectedpop_'+environment) + os.mkdir(self.dirpath+'/data_fullevolution/'+environment) + os.mkdir(self.dirpath+'/data_fullevolution/'+environment+'/phenotypes') + os.mkdir(self.dirpath+'/data_fullevolution/'+environment+'/descriptors') + os.mkdir(self.dirpath+'/data_fullevolution/'+environment+'/fitness') + os.mkdir(self.dirpath+'/data_fullevolution/'+environment+'/phenotype_images') def _experiment_folder(self): return self.dirpath @@ -34,21 +37,21 @@ def export_genotype(self, individual): if self.settings.recovery_enabled: individual.export_genotype(self._data_folder()) - def export_phenotype(self, individual): + def export_phenotype(self, individual, environment): if self.settings.export_phenotype: - individual.export_phenotype(self._data_folder()) + individual.export_phenotype(self._data_folder()+'/'+environment) - def export_fitnesses(self, individuals): + def export_fitnesses(self, individuals, environment): folder = self._data_folder() for individual in individuals: - individual.export_fitness(folder) + individual.export_fitness(folder+'/'+environment) - def export_fitness(self, individual): - folder = os.path.join(self._data_folder(),'fitness') + def export_fitness(self, individual, environment): + folder = os.path.join(self._data_folder()+'/'+environment, 'fitness') individual.export_fitness(folder) - def export_behavior_measures(self, _id, measures): - filename = os.path.join(self._data_folder(), 'descriptors', f'behavior_desc_{_id}.txt') + def export_behavior_measures(self, _id, measures, environment): + filename = os.path.join(self._data_folder()+'/'+environment, 'descriptors', f'behavior_desc_{_id}.txt') with open(filename, "w") as f: if measures is None: f.write(str(None)) @@ -57,22 +60,23 @@ def export_behavior_measures(self, _id, measures): f.write(f"{key} {val}\n") def export_phenotype_images(self, dirpath, individual): - individual.phenotype.render_body(self._experiment_folder() +'/'+dirpath+f'/body_{individual.phenotype.id}.png') - individual.phenotype.render_brain(self._experiment_folder() +'/'+dirpath+f'/brain_{individual.phenotype.id}') + individual.phenotype.render_body(self._experiment_folder()+'/'+dirpath+f'/body_{individual.phenotype.id}.png') + individual.phenotype.render_brain(self._experiment_folder()+'/'+dirpath+f'/brain_{individual.phenotype.id}') def export_failed_eval_robot(self, individual): individual.genotype.export_genotype(f'{self._data_folder()}/failed_eval_robots/genotype_{str(individual.phenotype.id)}.txt') individual.phenotype.save_file(f'{self._data_folder()}/failed_eval_robots/phenotype_{str(individual.phenotype.id)}.yaml') individual.phenotype.save_file(f'{self._data_folder()}/failed_eval_robots/phenotype_{str(individual.phenotype.id)}.sdf', conf_type='sdf') - def export_snapshots(self, individuals, gen_num): + def export_snapshots(self, individuals, gen_num, environment): if self.settings.recovery_enabled: - path = os.path.join(self._experiment_folder(), f'selectedpop_{gen_num}') + path = os.path.join(self._experiment_folder()+'/selectedpop_'+environment, f'selectedpop_{gen_num}') if os.path.exists(path): shutil.rmtree(path) os.mkdir(path) + for ind in individuals: - self.export_phenotype_images(f'selectedpop_{str(gen_num)}', ind) + self.export_phenotype_images('selectedpop_'+environment+'/'+f'selectedpop_{str(gen_num)}', ind) logger.info(f'Exported snapshot {str(gen_num)} with {str(len(individuals))} individuals') def experiment_is_new(self): @@ -90,7 +94,8 @@ def read_recovery_state(self, population_size, offspring_size): for r, d, f in os.walk(self._experiment_folder()): for dir in d: if 'selectedpop' in dir: - exported_files = len([name for name in os.listdir(os.path.join(self._experiment_folder(), dir)) if os.path.isfile(os.path.join(self._experiment_folder(), dir, name))]) + exported_files = len([name for name in os.listdir(os.path.join(self._experiment_folder(), dir)) + if os.path.isfile(os.path.join(self._experiment_folder(), dir, name))]) if exported_files == (population_size * 2): # body and brain files snapshots.append(int(dir.split('_')[1])) diff --git a/pyrevolve/genotype/genotype.py b/pyrevolve/genotype/genotype.py index 4317fad3f4..1f632f69b0 100644 --- a/pyrevolve/genotype/genotype.py +++ b/pyrevolve/genotype/genotype.py @@ -5,7 +5,7 @@ def clone(self): """ raise NotImplementedError("Method must be implemented by genome") - def develop(self): + def develop(self, environment): """ Develops the genome into a revolve_bot (proto-phenotype) @@ -23,7 +23,12 @@ def __init__(self, weight_min, weight_max, oscillator_param_min, - oscillator_param_max): + oscillator_param_max, + max_clauses, + max_terms_clause, + plastic, + environmental_conditions, + logic_operators): self.e_max_groups = e_max_groups self.axiom_w = axiom_w self.i_iterations = i_iterations @@ -31,3 +36,8 @@ def __init__(self, self.weight_max = weight_max self.oscillator_param_min = oscillator_param_min self.oscillator_param_max = oscillator_param_max + self.max_clauses = max_clauses + self.max_terms_clause = max_terms_clause + self.plastic = plastic + self.environmental_conditions = environmental_conditions + self.logic_operators = logic_operators diff --git a/pyrevolve/genotype/plasticoding/initialization.py b/pyrevolve/genotype/plasticoding/initialization.py index 7f784313f0..34c0be193b 100644 --- a/pyrevolve/genotype/plasticoding/initialization.py +++ b/pyrevolve/genotype/plasticoding/initialization.py @@ -1,7 +1,7 @@ from pyrevolve.genotype.plasticoding.plasticoding import Plasticoding from pyrevolve.genotype.plasticoding.plasticoding import Alphabet import random - +import pprint def _generate_random_grammar(conf): """ @@ -46,6 +46,94 @@ def _generate_random_grammar(conf): ]) return grammar +def _generate_random_plastic_grammar(conf): + """ + Initializing a new genotype, + :param conf: e_max_groups, maximum number of groups of symbols + :return: a random new Genome + :rtype: dictionary + """ + s_segments = random.randint(1, conf.e_max_groups) + + max_terms_clause = conf.max_terms_clause + if max_terms_clause > len(conf.environmental_conditions): + max_terms_clause = len(conf.environmental_conditions) + + grammar = {} + + for symbol in Alphabet.modules(): + + grammar[symbol[0]] = [] + + # generates clause and rule for each flavor of the letter + for flavor in range(0, conf.max_clauses): + + grammar[symbol[0]].append([]) + + if symbol[0] == conf.axiom_w: + grammar[symbol[0]][-1].extend([build_clause(conf.environmental_conditions, + conf.logic_operators, + max_terms_clause), + [[conf.axiom_w, []]]]) + else: + grammar[symbol[0]][-1].extend([build_clause(conf.environmental_conditions, + conf.logic_operators, + max_terms_clause), + []]) + + for s in range(0, s_segments): + + symbol_module = random.randint( + 1, len(Alphabet.modules()) - 1) + symbol_mounting = random.randint( + 0, len(Alphabet.morphology_mounting_commands()) - 1) + symbol_morph_moving = random.randint( + 0, len(Alphabet.morphology_moving_commands()) - 1) + symbol_contr_moving = random.randint( + 0, len(Alphabet.controller_moving_commands()) - 1) + symbol_changing = random.randint( + 0, len(Alphabet.controller_changing_commands()) - 1) + + grammar[symbol[0]][-1][1].extend([ + Plasticoding.build_symbol( + Alphabet.controller_moving_commands()[symbol_contr_moving], conf), + Plasticoding.build_symbol( + Alphabet.controller_changing_commands()[symbol_changing], conf), + Plasticoding.build_symbol( + Alphabet.morphology_mounting_commands()[symbol_mounting], conf), + Plasticoding.build_symbol( + Alphabet.modules()[symbol_module], conf), + Plasticoding.build_symbol( + Alphabet.morphology_moving_commands()[symbol_morph_moving], conf), + ]) + + return grammar + + +def build_clause(environmental_conditions, logic_operators, max_terms_clause): + + clause = [] + used_terms = [] + + num_terms_clause = random.choice(range(1, max_terms_clause+1)) + for term_idx in range(1, num_terms_clause+1): + + # selects a random term and makes a random comparison + + available_terms = [environmental_conditions[t] for t in range(0, len(environmental_conditions)) + if environmental_conditions[t] not in used_terms] + term = random.choice(available_terms) + used_terms.append(term) + value = random.choice([True, False]) + + clause.append([term, '==', value]) + + # adds logical operators if there are multiple terms + if term_idx < num_terms_clause: + clause.append([random.choice(logic_operators)]) + + return clause + def random_initialization(conf, next_robot_id): """ @@ -55,6 +143,10 @@ def random_initialization(conf, next_robot_id): :rtype: Plasticoding """ genotype = Plasticoding(conf, next_robot_id) - genotype.grammar = _generate_random_grammar(conf) + + if conf.plastic: + genotype.grammar = _generate_random_plastic_grammar(conf) + else: + genotype.grammar = _generate_random_grammar(conf) return genotype diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index 621dd13391..7bd25780cd 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -17,6 +17,8 @@ import math import copy import itertools +import pprint +import sys class Alphabet(Enum): @@ -182,15 +184,55 @@ def check_validity(self): if self.phenotype._morphological_measurements.measurement_to_dict()['hinge_count'] > 0: self.valid = True - def develop(self): - self.early_development() + def develop(self, environment): + self.early_development(environment) phenotype = self.late_development() return phenotype - def early_development(self): + def early_development(self, environment): + + if conf.plastic: + + # simulates sensing of environmental conditions + if environment == 'plane': + hill = False + hot = False + if environment == 'tilted5': + hill = True + hot = False + if environment == 'lava': + hill = False + hot = True + if environment == 'lavatilted5': + hill = True + hot = True + + print(' ###############im in the '+environment) + + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(self.grammar) + + grammar = {} + for letter in self.grammar: + + true_rules = 0 + for flavor in range(0, len(self.grammar[letter])): + print( self.grammar[letter][flavor][0]) + clause = 'True if ' + for item in self.grammar[letter][flavor][0]: + for subitem in item: + clause += str(subitem) + ' ' + # grammar[letter] = self.grammar[letter][flavor][0] + clause += 'else False' + print(clause) + print(exec(clause)) + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(grammar) + sys.exit() + else: + grammar = self.grammar self.intermediate_phenotype = [[self.conf.axiom_w, []]] - for i in range(0, self.conf.i_iterations): position = 0 @@ -201,13 +243,16 @@ def early_development(self): # removes symbol self.intermediate_phenotype.pop(position) # replaces by its production rule - for ii in range(0, len(self.grammar[symbol[self.index_symbol]])): + for ii in range(0, len(grammar[symbol[self.index_symbol]])): self.intermediate_phenotype.insert(position+ii, - self.grammar[symbol[self.index_symbol]][ii]) + grammar[symbol[self.index_symbol]][ii]) position = position+ii+1 else: position = position + 1 - # logger.info('Robot ' + str(self.id) + ' was early-developed.') + + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(self.intermediate_phenotype) + logger.info('Robot ' + str(self.id) + ' was early-developed.') def late_development(self): @@ -680,7 +725,7 @@ def __init__(self): class PlasticodingConfig: def __init__(self, initialization_genome=initialization.random_initialization, - e_max_groups=4, + e_max_groups=1,#4, oscillator_param_min=1, oscillator_param_max=10, weight_param_min=-1, @@ -688,10 +733,15 @@ def __init__(self, weight_min=-1, weight_max=1, axiom_w=Alphabet.CORE_COMPONENT, - i_iterations=3, + i_iterations=2,#3, max_structural_modules=100, robot_id=0, - move_to_new=False + move_to_new=False, + max_clauses=2, + max_terms_clause=1, + plastic=False, + environmental_conditions=['hill'], + logic_operators=['and', 'or'] ): self.initialization_genome = initialization_genome self.e_max_groups = e_max_groups @@ -706,3 +756,8 @@ def __init__(self, self.max_structural_modules = max_structural_modules self.robot_id = robot_id self.move_to_new = move_to_new + self.max_clauses = max_clauses + self.max_terms_clause = max_terms_clause + self.plastic = plastic + self.environmental_conditions = environmental_conditions + self.logic_operators = logic_operators diff --git a/pyrevolve/revolve_bot/revolve_bot.py b/pyrevolve/revolve_bot/revolve_bot.py index 848884858c..ce9dda6a53 100644 --- a/pyrevolve/revolve_bot/revolve_bot.py +++ b/pyrevolve/revolve_bot/revolve_bot.py @@ -86,10 +86,10 @@ def measure_body(self): except Exception as e: logger.exception('Failed measuring body') - def export_phenotype_measurements(self, path): - with open('experiments/' + path + '/data_fullevolution/descriptors/' + def export_phenotype_measurements(self, path, environment): + with open('experiments/' + path + '/data_fullevolution/'+environment+'/descriptors/' + 'phenotype_desc_' + str(self.id) + '.txt', 'w+') as file: - # TODO this crashes + for key, value in self._morphological_measurements.measurements_to_dict().items(): file.write('{} {}\n'.format(key, value)) for key, value in self._brain_measurements.measurements_to_dict().items(): From b09de085778f7cbee1befc9cea99680b5fff99b0 Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 6 Dec 2019 15:37:51 +0100 Subject: [PATCH 17/45] finished plasticity capacity in lsystem --- .../genotype/plasticoding/initialization.py | 4 +- .../genotype/plasticoding/plasticoding.py | 88 +++++++++++-------- 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/pyrevolve/genotype/plasticoding/initialization.py b/pyrevolve/genotype/plasticoding/initialization.py index 34c0be193b..fa80785aeb 100644 --- a/pyrevolve/genotype/plasticoding/initialization.py +++ b/pyrevolve/genotype/plasticoding/initialization.py @@ -124,9 +124,9 @@ def build_clause(environmental_conditions, logic_operators, max_terms_clause): if environmental_conditions[t] not in used_terms] term = random.choice(available_terms) used_terms.append(term) - value = random.choice([True, False]) + state = random.choice([True, False]) - clause.append([term, '==', value]) + clause.append([term, '==', state]) # adds logical operators if there are multiple terms if term_idx < num_terms_clause: diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index 7bd25780cd..9fc78e0d67 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -152,21 +152,22 @@ def load_genotype(self, genotype_file): self.grammar[repleceable_symbol].append([symbol, params]) def export_genotype(self, filepath): - file = open(filepath, 'w+') - for key, rule in self.grammar.items(): - line = key.value + ' ' - for item_rule in range(0, len(rule)): - symbol = rule[item_rule][self.index_symbol].value - if len(rule[item_rule][self.index_params]) > 0: - params = '_' - for param in range(0, len(rule[item_rule][self.index_params])): - params += str(rule[item_rule][self.index_params][param]) - if param < len(rule[item_rule][self.index_params])-1: - params += '|' - symbol += params - line += symbol + ' ' - file.write(line+'\n') - file.close() + pass + # file = open(filepath, 'w+') + # for key, rule in self.grammar.items(): + # line = key.value + ' ' + # for item_rule in range(0, len(rule)): + # symbol = rule[item_rule][self.index_symbol].value + # if len(rule[item_rule][self.index_params]) > 0: + # params = '_' + # for param in range(0, len(rule[item_rule][self.index_params])): + # params += str(rule[item_rule][self.index_params][param]) + # if param < len(rule[item_rule][self.index_params])-1: + # params += '|' + # symbol += params + # line += symbol + ' ' + # file.write(line+'\n') + # file.close() def load_and_develop(self, load, genotype_path='', id_genotype=None): @@ -191,9 +192,11 @@ def develop(self, environment): def early_development(self, environment): - if conf.plastic: + if self.conf.plastic: - # simulates sensing of environmental conditions + # simulates sensing of environmental conditions + # ( it is a shortcut to save computational time, + # but imu sensors could for sure tell if it is hill or not) if environment == 'plane': hill = False hot = False @@ -207,31 +210,35 @@ def early_development(self, environment): hill = True hot = True - print(' ###############im in the '+environment) - - pp = pprint.PrettyPrinter(indent=4) - pp.pprint(self.grammar) - grammar = {} for letter in self.grammar: true_rules = 0 + clause_is_true = None for flavor in range(0, len(self.grammar[letter])): - print( self.grammar[letter][flavor][0]) - clause = 'True if ' + clause = '' for item in self.grammar[letter][flavor][0]: for subitem in item: clause += str(subitem) + ' ' - # grammar[letter] = self.grammar[letter][flavor][0] - clause += 'else False' - print(clause) - print(exec(clause)) - pp = pprint.PrettyPrinter(indent=4) - pp.pprint(grammar) - sys.exit() + + clause_is_true = eval(clause) + if clause_is_true: + grammar[letter] = self.grammar[letter][flavor][1] + true_rules += 1 + + # one and only one rule should be true, otherwise letter doesnt get expressed + if true_rules == 0 or true_rules > 1: + grammar[letter] = [] + else: + grammar = self.grammar + print('gramarrrrrrrr') + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(grammar) + + self.intermediate_phenotype = [[self.conf.axiom_w, []]] for i in range(0, self.conf.i_iterations): @@ -240,18 +247,21 @@ def early_development(self, environment): symbol = self.intermediate_phenotype[position] if [symbol[self.index_symbol], []] in Alphabet.modules(): - # removes symbol - self.intermediate_phenotype.pop(position) - # replaces by its production rule - for ii in range(0, len(grammar[symbol[self.index_symbol]])): - self.intermediate_phenotype.insert(position+ii, - grammar[symbol[self.index_symbol]][ii]) + + ii = 0 + if len(grammar[symbol[self.index_symbol]]) > 0: + # removes symbol + self.intermediate_phenotype.pop(position) + # replaces it by its production rule + for ii in range(0, len(grammar[symbol[self.index_symbol]])): + self.intermediate_phenotype.insert(position+ii, + grammar[symbol[self.index_symbol]][ii]) position = position+ii+1 else: position = position + 1 - pp = pprint.PrettyPrinter(indent=4) - pp.pprint(self.intermediate_phenotype) + + pp.pprint(self.intermediate_phenotype) logger.info('Robot ' + str(self.id) + ' was early-developed.') def late_development(self): From 2bcbc5bdc32060c5043c3f482e013ce4d1a445df Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 6 Dec 2019 18:29:27 +0100 Subject: [PATCH 18/45] loads multiple environments --- pyrevolve/evolution/individual.py | 7 +++- pyrevolve/evolution/population.py | 33 +++++++++++-------- pyrevolve/experiment_management.py | 5 +++ .../genotype/plasticoding/plasticoding.py | 23 +++---------- pyrevolve/util/supervisor/simulator_queue.py | 2 +- 5 files changed, 36 insertions(+), 34 deletions(-) diff --git a/pyrevolve/evolution/individual.py b/pyrevolve/evolution/individual.py index fbc8e6fad7..6eef1a7c76 100644 --- a/pyrevolve/evolution/individual.py +++ b/pyrevolve/evolution/individual.py @@ -1,5 +1,5 @@ # (G,P) - +import pickle class Individual: def __init__(self, genotype, phenotype=None): @@ -47,6 +47,11 @@ def export_fitness(self, folder): with open(f'{folder}/fitness_{self.id}.txt', 'w') as f: f.write(str(self.fitness)) + def export_individual(self): + f = open(f'{folder}/individuals/individual_{self.id}.pkl',"wb") + pickle.dump(self,f) + f.close() + def export(self, folder): self.export_genotype(folder) self.export_phenotype(folder) diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index 84f884abba..029e8bcd0b 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -27,7 +27,6 @@ def __init__(self, experiment_name, experiment_management, measure_individuals, - environments, offspring_size=None, next_robot_id=1): """ @@ -67,11 +66,11 @@ def __init__(self, self.measure_individuals = measure_individuals self.offspring_size = offspring_size self.next_robot_id = next_robot_id - self.environments = environments class Population: - def __init__(self, conf: PopulationConfig, simulator_queue, analyzer_queue=None, next_robot_id=1): + + def __init__(self, conf: PopulationConfig, simulator_queue_envs, analyzer_queue_envs=None, next_robot_id=1): """ Creates a Population object that initialises the individuals in the population with an empty list @@ -83,14 +82,15 @@ def __init__(self, conf: PopulationConfig, simulator_queue, analyzer_queue=None, :param analyzer_queue: connection to the analyzer simulator queue :param next_robot_id: (sequential) id of the next individual to be created """ + self.conf = conf self.individuals = [] - self.analyzer_queue = analyzer_queue - self.simulator_queue = simulator_queue + self.analyzer_queue_envs = analyzer_queue_envs + self.simulator_queue_envs = simulator_queue_envs self.next_robot_id = next_robot_id def _new_individual(self, genotype): - environment = 'plane' #TEMP!!! + environment = 'tilted5' #TEMP!!! individual = Individual(genotype) individual.develop(environment) self.conf.experiment_management.export_genotype(individual) @@ -178,7 +178,10 @@ async def init_pop(self, recovered_individuals=[]): self.individuals.append(individual) self.next_robot_id += 1 - # await self.evaluate(self.individuals, 0) + for environment in self.simulator_queue_envs: + print('comecou', environment) + await self.evaluate(new_individuals=self.individuals, gen_num=0, environment=environment) + print('terminou', environment) self.individuals = recovered_individuals + self.individuals async def next_gen(self, gen_num, recovered_individuals=[]): @@ -229,7 +232,7 @@ async def next_gen(self, gen_num, recovered_individuals=[]): return new_population - async def evaluate(self, new_individuals, gen_num, type_simulation = 'evolve'): + async def evaluate(self, new_individuals, gen_num, environment, type_simulation = 'evolve'): """ Evaluates each individual in the new gen population @@ -241,7 +244,7 @@ async def evaluate(self, new_individuals, gen_num, type_simulation = 'evolve'): robot_futures = [] for individual in new_individuals: logger.info(f'Evaluating individual (gen {gen_num}) {individual.genotype.id} ...') - robot_futures.append(asyncio.ensure_future(self.evaluate_single_robot(individual))) + robot_futures.append(asyncio.ensure_future(self.evaluate_single_robot(individual, environment))) await asyncio.sleep(1) @@ -254,13 +257,15 @@ async def evaluate(self, new_individuals, gen_num, type_simulation = 'evolve'): assert (individual.fitness is None) if type_simulation == 'evolve': - self.conf.experiment_management.export_behavior_measures(individual.phenotype.id, individual.phenotype._behavioural_measurements) + self.conf.experiment_management.export_behavior_measures(individual.phenotype.id, + individual.phenotype._behavioural_measurements, + environment) logger.info(f'Individual {individual.phenotype.id} has a fitness of {individual.fitness}') if type_simulation == 'evolve': self.conf.experiment_management.export_fitness(individual) - async def evaluate_single_robot(self, individual): + async def evaluate_single_robot(self, individual, environment): """ :param individual: individual :return: Returns future of the evaluation, future returns (fitness, [behavioural] measurements) @@ -268,10 +273,10 @@ async def evaluate_single_robot(self, individual): if individual.phenotype is None: individual.develop() - if self.analyzer_queue is not None: - collisions, _bounding_box = await self.analyzer_queue.test_robot(individual, self.conf) + if self.analyzer_queue_envs[environment] is not None: + collisions, _bounding_box = await self.analyzer_queue_envs[environment].test_robot(individual, self.conf) if collisions > 0: logger.info(f"discarding robot {individual} because there are {collisions} self collisions") return None, None - return await self.simulator_queue.test_robot(individual, self.conf) + return await self.simulator_queue_envs[environment].test_robot(individual, self.conf) diff --git a/pyrevolve/experiment_management.py b/pyrevolve/experiment_management.py index 2e817775b6..d54a6ba993 100644 --- a/pyrevolve/experiment_management.py +++ b/pyrevolve/experiment_management.py @@ -22,6 +22,7 @@ def create_exp_folders(self, environments): for environment in environments: os.mkdir(self.dirpath+'/selectedpop_'+environment) os.mkdir(self.dirpath+'/data_fullevolution/'+environment) + os.mkdir(self.dirpath+'/data_fullevolution/'+environment+'/individuals') os.mkdir(self.dirpath+'/data_fullevolution/'+environment+'/phenotypes') os.mkdir(self.dirpath+'/data_fullevolution/'+environment+'/descriptors') os.mkdir(self.dirpath+'/data_fullevolution/'+environment+'/fitness') @@ -50,6 +51,10 @@ def export_fitness(self, individual, environment): folder = os.path.join(self._data_folder()+'/'+environment, 'fitness') individual.export_fitness(folder) + def export_individual(self, individual, environment): + folder = self._data_folder()+'/'+environment + individual.export_individual(folder) + def export_behavior_measures(self, _id, measures, environment): filename = os.path.join(self._data_folder()+'/'+environment, 'descriptors', f'behavior_desc_{_id}.txt') with open(filename, "w") as f: diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index 9fc78e0d67..04ccb3e284 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -152,22 +152,9 @@ def load_genotype(self, genotype_file): self.grammar[repleceable_symbol].append([symbol, params]) def export_genotype(self, filepath): - pass - # file = open(filepath, 'w+') - # for key, rule in self.grammar.items(): - # line = key.value + ' ' - # for item_rule in range(0, len(rule)): - # symbol = rule[item_rule][self.index_symbol].value - # if len(rule[item_rule][self.index_params]) > 0: - # params = '_' - # for param in range(0, len(rule[item_rule][self.index_params])): - # params += str(rule[item_rule][self.index_params][param]) - # if param < len(rule[item_rule][self.index_params])-1: - # params += '|' - # symbol += params - # line += symbol + ' ' - # file.write(line+'\n') - # file.close() + f = open(filepath,"w") + f.write( str(self.grammar) ) + f.close() def load_and_develop(self, load, genotype_path='', id_genotype=None): @@ -735,7 +722,7 @@ def __init__(self): class PlasticodingConfig: def __init__(self, initialization_genome=initialization.random_initialization, - e_max_groups=1,#4, + e_max_groups=4, oscillator_param_min=1, oscillator_param_max=10, weight_param_min=-1, @@ -743,7 +730,7 @@ def __init__(self, weight_min=-1, weight_max=1, axiom_w=Alphabet.CORE_COMPONENT, - i_iterations=2,#3, + i_iterations=3, max_structural_modules=100, robot_id=0, move_to_new=False, diff --git a/pyrevolve/util/supervisor/simulator_queue.py b/pyrevolve/util/supervisor/simulator_queue.py index e4a6c276ca..e8a4aef20a 100644 --- a/pyrevolve/util/supervisor/simulator_queue.py +++ b/pyrevolve/util/supervisor/simulator_queue.py @@ -27,7 +27,7 @@ def __init__(self, n_cores: int, settings, port_start=11345, simulator_cmd=None) def _simulator_supervisor(self, simulator_name_postfix): return DynamicSimSupervisor( - world_file=self._settings.world, + world_file='worlds/'+self._settings.world+'.world', simulator_cmd=self._simulator_cmd, simulator_args=["--verbose"], plugins_dir_path=os.path.join('.', 'build', 'lib'), From 0c995b76e58c6368c53950a96fd863895d6abd3f Mon Sep 17 00:00:00 2001 From: Karine Date: Mon, 9 Dec 2019 17:35:20 +0100 Subject: [PATCH 19/45] adapts recovery (part 1) --- pyrevolve/evolution/individual.py | 6 +- pyrevolve/evolution/population.py | 98 +++++++++---------- pyrevolve/experiment_management.py | 56 ++++++----- .../genotype/plasticoding/plasticoding.py | 17 ++-- 4 files changed, 89 insertions(+), 88 deletions(-) diff --git a/pyrevolve/evolution/individual.py b/pyrevolve/evolution/individual.py index 6eef1a7c76..4d56d05fc4 100644 --- a/pyrevolve/evolution/individual.py +++ b/pyrevolve/evolution/individual.py @@ -47,9 +47,9 @@ def export_fitness(self, folder): with open(f'{folder}/fitness_{self.id}.txt', 'w') as f: f.write(str(self.fitness)) - def export_individual(self): - f = open(f'{folder}/individuals/individual_{self.id}.pkl',"wb") - pickle.dump(self,f) + def export_individual(self, folder): + f = open(f'{folder}/individuals/individual_{self.id}.pkl', "wb") + pickle.dump(self, f) f.close() def export(self, folder): diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index 029e8bcd0b..24667f5f6f 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -6,7 +6,9 @@ from ..custom_logging.logger import logger import time import asyncio +import copy import os +import pickle import sys class PopulationConfig: @@ -27,6 +29,7 @@ def __init__(self, experiment_name, experiment_management, measure_individuals, + environments, offspring_size=None, next_robot_id=1): """ @@ -64,6 +67,7 @@ def __init__(self, self.experiment_name = experiment_name self.experiment_management = experiment_management self.measure_individuals = measure_individuals + self.environments = environments self.offspring_size = offspring_size self.next_robot_id = next_robot_id @@ -90,60 +94,50 @@ def __init__(self, conf: PopulationConfig, simulator_queue_envs, analyzer_queue_ self.next_robot_id = next_robot_id def _new_individual(self, genotype): - environment = 'tilted5' #TEMP!!! - individual = Individual(genotype) - individual.develop(environment) - self.conf.experiment_management.export_genotype(individual) - self.conf.experiment_management.export_phenotype(individual, environment) - self.conf.experiment_management.export_phenotype_images('data_fullevolution/' - +environment+'/phenotype_images', individual) - individual.phenotype.measure_phenotype(self.conf.experiment_name) - individual.phenotype.export_phenotype_measurements(self.conf.experiment_name, environment) - return individual + individual = {} + individual_temp = Individual(genotype) - async def load_individual(self, id): - path = 'experiments/'+self.conf.experiment_name - genotype = self.conf.genotype_constructor(self.conf.genotype_conf, id) - genotype.load_genotype(f'{path}/data_fullevolution/genotypes/genotype_{id}.txt') + for environment in self.conf.environments: + + individual[environment] = copy.deepcopy(individual_temp) + individual[environment].develop(environment) - individual = Individual(genotype) - individual.develop() - individual.phenotype.measure_phenotype(self.conf.experiment_name) + if len(individual) == 1: + self.conf.experiment_management.export_genotype(individual[environment]) - with open(os.path.join(path, 'data_fullevolution', 'fitness', f'fitness_{id}.txt')) as f: - data = f.readlines()[0] - individual.fitness = None if data == 'None' else float(data) + self.conf.experiment_management.export_phenotype(individual[environment], environment) + self.conf.experiment_management.export_phenotype_images('data_fullevolution/' + +environment+'/phenotype_images', + individual[environment]) + individual[environment].phenotype.measure_phenotype(self.conf.experiment_name) + individual[environment].phenotype.export_phenotype_measurements(self.conf.experiment_name, environment) + self.conf.experiment_management.export_individual(individual[environment], environment) - with open(os.path.join(path, 'data_fullevolution', 'descriptors', f'behavior_desc_{id}.txt')) as f: - lines = f.readlines() - if lines[0] == 'None': - individual.phenotype._behavioural_measurements = None + return individual + + async def load_individual(self, id): + path = 'experiments/'+self.conf.experiment_name+'/'+'data_fullevolution/' + + individual = {} + for environment in self.conf.environments: + file_name = path+environment+'/individuals/individual_'+id+'.pkl' + if os.path.exists(file_name): + file = open(file_name, 'rb') + individual[environment] = pickle.load(file) else: - individual.phenotype._behavioural_measurements = measures.BehaviouralMeasurements() - for line in lines: - if line.split(' ')[0] == 'velocity': - individual.phenotype._behavioural_measurements.velocity = float(line.split(' ')[1]) - #if line.split(' ')[0] == 'displacement': - # individual.phenotype._behavioural_measurements.displacement = float(line.split(' ')[1]) - if line.split(' ')[0] == 'displacement_velocity': - individual.phenotype._behavioural_measurements.displacement_velocity = float(line.split(' ')[1]) - if line.split(' ')[0] == 'displacement_velocity_hill': - individual.phenotype._behavioural_measurements.displacement_velocity_hill = float(line.split(' ')[1]) - if line.split(' ')[0] == 'head_balance': - individual.phenotype._behavioural_measurements.head_balance = None if line.split(' ')[1] == 'None\n' else float(line.split(' ')[1]) - if line.split(' ')[0] == 'contacts': - individual.phenotype._behavioural_measurements.contacts = float(line.split(' ')[1]) + individual[environment] = copy.deepcopy(individual[list(self.conf.environments.keys())[-1]]) return individual async def load_snapshot(self, gen_num): """ - Recovers all genotypes and fitnesses of robots in the lastest selected population + Recovers all genotypes and fitnesses of robots in the latest selected population :param gen_num: number of the generation snapshot to recover """ path = 'experiments/'+self.conf.experiment_name - for r, d, f in os.walk(path +'/selectedpop_'+str(gen_num)): + for r, d, f in os.walk(path+'/selectedpop_'+ + list(self.conf.environments.keys())[-1]+'/selectedpop_'+str(gen_num)): for file in f: if 'body' in file: id = file.split('.')[0].split('_')[-2]+'_'+file.split('.')[0].split('_')[-1] @@ -172,18 +166,18 @@ async def init_pop(self, recovered_individuals=[]): """ Populates the population (individuals list) with Individual objects that contains their respective genotype. """ + # do recovery soon...! for i in range(self.conf.population_size-len(recovered_individuals)): individual = self._new_individual( self.conf.genotype_constructor(self.conf.genotype_conf, self.next_robot_id)) self.individuals.append(individual) self.next_robot_id += 1 - for environment in self.simulator_queue_envs: - print('comecou', environment) - await self.evaluate(new_individuals=self.individuals, gen_num=0, environment=environment) - print('terminou', environment) self.individuals = recovered_individuals + self.individuals + for environment in self.simulator_queue_envs: + await self.evaluate(new_individuals=self.individuals, gen_num=0, environment=environment) + async def next_gen(self, gen_num, recovered_individuals=[]): """ Creates next generation of the population through selection, mutation, crossover @@ -243,13 +237,15 @@ async def evaluate(self, new_individuals, gen_num, environment, type_simulation # await self.simulator_connection.pause(True) robot_futures = [] for individual in new_individuals: - logger.info(f'Evaluating individual (gen {gen_num}) {individual.genotype.id} ...') - robot_futures.append(asyncio.ensure_future(self.evaluate_single_robot(individual, environment))) + if individual[environment].fitness is None: + logger.info(f'Evaluating individual (gen {gen_num}) {individual[environment].genotype.id} ...') + robot_futures.append(asyncio.ensure_future(self.evaluate_single_robot(individual[environment], + environment))) await asyncio.sleep(1) for i, future in enumerate(robot_futures): - individual = new_individuals[i] + individual = new_individuals[i][environment] logger.info(f'Evaluation of Individual {individual.phenotype.id}') individual.fitness, individual.phenotype._behavioural_measurements = await future @@ -263,18 +259,18 @@ async def evaluate(self, new_individuals, gen_num, environment, type_simulation logger.info(f'Individual {individual.phenotype.id} has a fitness of {individual.fitness}') if type_simulation == 'evolve': - self.conf.experiment_management.export_fitness(individual) + self.conf.experiment_management.export_fitness(individual, environment) + self.conf.experiment_management.export_individual(individual, environment) async def evaluate_single_robot(self, individual, environment): """ :param individual: individual :return: Returns future of the evaluation, future returns (fitness, [behavioural] measurements) """ - if individual.phenotype is None: - individual.develop() if self.analyzer_queue_envs[environment] is not None: - collisions, _bounding_box = await self.analyzer_queue_envs[environment].test_robot(individual, self.conf) + collisions, _bounding_box = await self.analyzer_queue_envs[environment].test_robot(individual, + self.conf) if collisions > 0: logger.info(f"discarding robot {individual} because there are {collisions} self collisions") return None, None diff --git a/pyrevolve/experiment_management.py b/pyrevolve/experiment_management.py index d54a6ba993..444966a394 100644 --- a/pyrevolve/experiment_management.py +++ b/pyrevolve/experiment_management.py @@ -8,18 +8,19 @@ class ExperimentManagement: # ids of robots in the name of all types of files are always phenotype ids, and the standard for id is 'robot_ID' - def __init__(self, settings): + def __init__(self, settings, environments): self.settings = settings + self.environments = environments self.dirpath = os.path.join('experiments', self.settings.experiment_name) - def create_exp_folders(self, environments): + def create_exp_folders(self): if os.path.exists(self.dirpath): shutil.rmtree(self.dirpath) os.mkdir(self.dirpath) os.mkdir(self.dirpath+'/data_fullevolution') os.mkdir(self.dirpath+'/data_fullevolution/genotypes') os.mkdir(self.dirpath+'/data_fullevolution/failed_eval_robots') - for environment in environments: + for environment in self.environments: os.mkdir(self.dirpath+'/selectedpop_'+environment) os.mkdir(self.dirpath+'/data_fullevolution/'+environment) os.mkdir(self.dirpath+'/data_fullevolution/'+environment+'/individuals') @@ -73,35 +74,42 @@ def export_failed_eval_robot(self, individual): individual.phenotype.save_file(f'{self._data_folder()}/failed_eval_robots/phenotype_{str(individual.phenotype.id)}.yaml') individual.phenotype.save_file(f'{self._data_folder()}/failed_eval_robots/phenotype_{str(individual.phenotype.id)}.sdf', conf_type='sdf') - def export_snapshots(self, individuals, gen_num, environment): + def export_snapshots(self, individuals, gen_num): if self.settings.recovery_enabled: - path = os.path.join(self._experiment_folder()+'/selectedpop_'+environment, f'selectedpop_{gen_num}') - if os.path.exists(path): - shutil.rmtree(path) - os.mkdir(path) + for environment in self.environments: + path = os.path.join(self._experiment_folder()+'/selectedpop_'+environment, f'selectedpop_{gen_num}') + if os.path.exists(path): + shutil.rmtree(path) + os.mkdir(path) - for ind in individuals: - self.export_phenotype_images('selectedpop_'+environment+'/'+f'selectedpop_{str(gen_num)}', ind) - logger.info(f'Exported snapshot {str(gen_num)} with {str(len(individuals))} individuals') + for ind in individuals: + self.export_phenotype_images('selectedpop_'+environment+'/'+f'selectedpop_{str(gen_num)}', ind[environment]) + logger.info(f'Exported snapshot {str(gen_num)} with {str(len(individuals))} individuals') def experiment_is_new(self): if not os.path.exists(self._experiment_folder()): return True - path, dirs, files = next(os.walk(os.path.join(self._data_folder(), 'fitness'))) - if len(files) == 0: - return True - else: - return False + for environment in self.environments: + path, dirs, files = next(os.walk(os.path.join(self._data_folder()+'/'+environment, 'individuals'))) + if len(files) > 0: + return False + + return True def read_recovery_state(self, population_size, offspring_size): snapshots = [] - for r, d, f in os.walk(self._experiment_folder()): + # checks existent robots using the last environment of the dict as reference + path = self._experiment_folder()+'/selectedpop_'+list(self.environments.keys())[-1] + for r, d, f in os.walk(path): for dir in d: if 'selectedpop' in dir: - exported_files = len([name for name in os.listdir(os.path.join(self._experiment_folder(), dir)) - if os.path.isfile(os.path.join(self._experiment_folder(), dir, name))]) - if exported_files == (population_size * 2): # body and brain files + exported_files = len([name for name in os.listdir(os.path.join(path, + dir)) + if os.path.isfile(os.path.join(path, dir, name))]) + + # snapshot is vomplete if all body and brain files exist + if exported_files == (population_size * 2): snapshots.append(int(dir.split('_')[1])) if len(snapshots) > 0: @@ -113,10 +121,12 @@ def read_recovery_state(self, population_size, offspring_size): last_snapshot = -1 n_robots = 0 + # if robot is developed in any of the environments, the nit exists robot_ids = [] - for r, d, f in os.walk(os.path.join(self._data_folder(), 'fitness')): - for file in f: - robot_ids.append(int(file.split('.')[0].split('_')[-1])) + for environment in self.environments: + for r, d, f in os.walk(os.path.join(self._data_folder()+'/'+environment, 'individuals')): + for file in f: + robot_ids.append(int(file.split('.')[0].split('_')[-1])) last_id = np.sort(robot_ids)[-1] # if there are more robots to recover than the number expected in this snapshot diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index 04ccb3e284..30cbc7a55c 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -19,7 +19,7 @@ import itertools import pprint import sys - +import json class Alphabet(Enum): @@ -152,8 +152,8 @@ def load_genotype(self, genotype_file): self.grammar[repleceable_symbol].append([symbol, params]) def export_genotype(self, filepath): - f = open(filepath,"w") - f.write( str(self.grammar) ) + f = open(filepath, "w") + f.write(str(self.grammar)) f.close() def load_and_develop(self, load, genotype_path='', id_genotype=None): @@ -215,17 +215,14 @@ def early_development(self, environment): # one and only one rule should be true, otherwise letter doesnt get expressed if true_rules == 0 or true_rules > 1: - grammar[letter] = [] + #grammar[letter] = [] + # orrrrr actually, uses first flavor + grammar[letter] = self.grammar[letter][0][1] else: grammar = self.grammar - print('gramarrrrrrrr') - pp = pprint.PrettyPrinter(indent=4) - pp.pprint(grammar) - - self.intermediate_phenotype = [[self.conf.axiom_w, []]] for i in range(0, self.conf.i_iterations): @@ -247,8 +244,6 @@ def early_development(self, environment): else: position = position + 1 - - pp.pprint(self.intermediate_phenotype) logger.info('Robot ' + str(self.id) + ' was early-developed.') def late_development(self): From 09d65e314a69c2c36a96d4a0b9d6af2f40d3a812 Mon Sep 17 00:00:00 2001 From: Karine Date: Wed, 11 Dec 2019 15:46:49 +0100 Subject: [PATCH 20/45] baseline manager --- experiments/karines_experiments/baseline.py | 153 ++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100755 experiments/karines_experiments/baseline.py diff --git a/experiments/karines_experiments/baseline.py b/experiments/karines_experiments/baseline.py new file mode 100755 index 0000000000..3954e7c672 --- /dev/null +++ b/experiments/karines_experiments/baseline.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 2#100 + population_size = 4#100 + offspring_size = 1#50 + + # environment world and z-start + environments = {'plane': 0.03, + 'tilted5': 0.1 + } + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + environmental_conditions=['hill'], + max_terms_clause=1, + plastic=True, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + print('fdsngfkdngkfdhbgsdjgnfdsfjgnsdkjfgnsdkjgnsdkhjgbnsdkjhgbskj',gen_num, has_offspring, next_robot_id) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function(robot_manager, robot): + contacts = measures.contacts(robot_manager, robot) + assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + measure_individuals=settings.measure_individuals, + environments=environments, + ) + + settings = parser.parse_args() + + simulator_queue_envs = {} + analyzer_queue_envs = {} + + previous_port = None + # for environment in environments: + # + # settings.world = environment + # settings.z_start = environments[environment] + # + # if previous_port is None: + # port = settings.port_start + # previous_port = port + # else: + # port = previous_port + settings.n_cores + 1 + # + # simulator_queue_envs[environment] = SimulatorQueue(settings.n_cores, settings, port) + # + # await simulator_queue_envs[environment].start() + # + # analyzer_queue_envs[environment] = AnalyzerQueue(1, settings, port+settings.n_cores) + # await analyzer_queue_envs[environment].start() + + population = Population(population_conf, simulator_queue_envs, analyzer_queue_envs, next_robot_id) + + if do_recovery: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + if gen_num >= 0: + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + sys.exit() + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... From 5047e38753430cbb1e587bfe22975db620ebf999 Mon Sep 17 00:00:00 2001 From: Karine Date: Wed, 11 Dec 2019 19:21:04 +0100 Subject: [PATCH 21/45] improvement in plasticity --- .../genotype/plasticoding/initialization.py | 17 +++------- .../genotype/plasticoding/plasticoding.py | 33 ++++++++++++++----- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/pyrevolve/genotype/plasticoding/initialization.py b/pyrevolve/genotype/plasticoding/initialization.py index fa80785aeb..f5583f231c 100644 --- a/pyrevolve/genotype/plasticoding/initialization.py +++ b/pyrevolve/genotype/plasticoding/initialization.py @@ -3,6 +3,7 @@ import random import pprint + def _generate_random_grammar(conf): """ Initializing a new genotype, @@ -46,6 +47,7 @@ def _generate_random_grammar(conf): ]) return grammar + def _generate_random_plastic_grammar(conf): """ Initializing a new genotype, @@ -55,10 +57,6 @@ def _generate_random_plastic_grammar(conf): """ s_segments = random.randint(1, conf.e_max_groups) - max_terms_clause = conf.max_terms_clause - if max_terms_clause > len(conf.environmental_conditions): - max_terms_clause = len(conf.environmental_conditions) - grammar = {} for symbol in Alphabet.modules(): @@ -73,12 +71,12 @@ def _generate_random_plastic_grammar(conf): if symbol[0] == conf.axiom_w: grammar[symbol[0]][-1].extend([build_clause(conf.environmental_conditions, conf.logic_operators, - max_terms_clause), + conf.max_terms_clause), [[conf.axiom_w, []]]]) else: grammar[symbol[0]][-1].extend([build_clause(conf.environmental_conditions, conf.logic_operators, - max_terms_clause), + conf.max_terms_clause), []]) for s in range(0, s_segments): @@ -113,17 +111,12 @@ def _generate_random_plastic_grammar(conf): def build_clause(environmental_conditions, logic_operators, max_terms_clause): clause = [] - used_terms = [] num_terms_clause = random.choice(range(1, max_terms_clause+1)) for term_idx in range(1, num_terms_clause+1): # selects a random term and makes a random comparison - - available_terms = [environmental_conditions[t] for t in range(0, len(environmental_conditions)) - if environmental_conditions[t] not in used_terms] - term = random.choice(available_terms) - used_terms.append(term) + term = random.choice(environmental_conditions) state = random.choice([True, False]) clause.append([term, '==', state]) diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index 30cbc7a55c..b12cd0535c 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -200,7 +200,7 @@ def early_development(self, environment): grammar = {} for letter in self.grammar: - true_rules = 0 + true_clauses = [] clause_is_true = None for flavor in range(0, len(self.grammar[letter])): clause = '' @@ -209,20 +209,34 @@ def early_development(self, environment): clause += str(subitem) + ' ' clause_is_true = eval(clause) + if clause_is_true: - grammar[letter] = self.grammar[letter][flavor][1] - true_rules += 1 + true_clauses.append(flavor) + + # if no clause is true, letter doesnt get expressed + if len(true_clauses) == 0: + grammar[letter] = [] + else: + # if multiple clauses are true, all get expressed + for idx in range(0, len(true_clauses)): + if idx == 0: + grammar[letter] = self.grammar[letter][true_clauses[idx]][1] + else: + if letter == Alphabet.CORE_COMPONENT: + aux_list = self.grammar[letter][true_clauses[idx]][1][1:] + else: + aux_list = self.grammar[letter][true_clauses[idx]][1] + grammar[letter].extend(aux_list) - # one and only one rule should be true, otherwise letter doesnt get expressed - if true_rules == 0 or true_rules > 1: - #grammar[letter] = [] - # orrrrr actually, uses first flavor - grammar[letter] = self.grammar[letter][0][1] else: grammar = self.grammar + print('regulated') + pp = pprint.PrettyPrinter(width=41, compact=True) + pp.pprint(grammar) + self.intermediate_phenotype = [[self.conf.axiom_w, []]] for i in range(0, self.conf.i_iterations): @@ -294,6 +308,7 @@ def late_development(self): self.add_imu_nodes() logger.info('Robot ' + str(self.id) + ' was late-developed.') + print(self.intermediate_phenotype) return self.phenotype def move_in_body(self, symbol): @@ -730,7 +745,7 @@ def __init__(self, robot_id=0, move_to_new=False, max_clauses=2, - max_terms_clause=1, + max_terms_clause=2, plastic=False, environmental_conditions=['hill'], logic_operators=['and', 'or'] From 9eafb2d99ab343bebce612795744bb2604cd2dfa Mon Sep 17 00:00:00 2001 From: Karine Date: Wed, 11 Dec 2019 20:30:54 +0100 Subject: [PATCH 22/45] recover of ini pop --- experiments/karines_experiments/baseline.py | 49 ++++++++++--------- pyrevolve/evolution/individual.py | 1 + pyrevolve/evolution/population.py | 29 ++++++----- pyrevolve/experiment_management.py | 5 +- .../genotype/plasticoding/plasticoding.py | 5 -- 5 files changed, 46 insertions(+), 43 deletions(-) diff --git a/experiments/karines_experiments/baseline.py b/experiments/karines_experiments/baseline.py index 3954e7c672..b955c37f5a 100755 --- a/experiments/karines_experiments/baseline.py +++ b/experiments/karines_experiments/baseline.py @@ -25,8 +25,8 @@ async def run(): """ # experiment params # - num_generations = 2#100 - population_size = 4#100 + num_generations = 1#100 + population_size = 3#100 offspring_size = 1#50 # environment world and z-start @@ -37,7 +37,7 @@ async def run(): genotype_conf = PlasticodingConfig( max_structural_modules=15, environmental_conditions=['hill'], - max_terms_clause=1, + max_terms_clause=2, plastic=True, ) @@ -57,7 +57,7 @@ async def run(): do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) - + print(do_recovery) if do_recovery: gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, offspring_size) @@ -102,31 +102,32 @@ def fitness_function(robot_manager, robot): analyzer_queue_envs = {} previous_port = None - # for environment in environments: - # - # settings.world = environment - # settings.z_start = environments[environment] - # - # if previous_port is None: - # port = settings.port_start - # previous_port = port - # else: - # port = previous_port + settings.n_cores + 1 - # - # simulator_queue_envs[environment] = SimulatorQueue(settings.n_cores, settings, port) - # - # await simulator_queue_envs[environment].start() - # - # analyzer_queue_envs[environment] = AnalyzerQueue(1, settings, port+settings.n_cores) - # await analyzer_queue_envs[environment].start() + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port + settings.n_cores + 1 + + simulator_queue_envs[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue_envs[environment].start() + + analyzer_queue_envs[environment] = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue_envs[environment].start() population = Population(population_conf, simulator_queue_envs, analyzer_queue_envs, next_robot_id) if do_recovery: - # loading a previous state of the experiment - await population.load_snapshot(gen_num) + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + if has_offspring: individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) gen_num += 1 @@ -144,7 +145,7 @@ def fitness_function(robot_manager, robot): await population.init_pop() experiment_management.export_snapshots(population.individuals, gen_num) - sys.exit() + while gen_num < num_generations-1: gen_num += 1 population = await population.next_gen(gen_num) diff --git a/pyrevolve/evolution/individual.py b/pyrevolve/evolution/individual.py index 4d56d05fc4..6a4649ac8a 100644 --- a/pyrevolve/evolution/individual.py +++ b/pyrevolve/evolution/individual.py @@ -12,6 +12,7 @@ def __init__(self, genotype, phenotype=None): self.genotype = genotype self.phenotype = phenotype self.fitness = None + self.evaluated = False self.parents = None self.failed_eval_attempt_count = 0 diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index 24667f5f6f..ead6811df0 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -106,6 +106,8 @@ def _new_individual(self, genotype): if len(individual) == 1: self.conf.experiment_management.export_genotype(individual[environment]) + for environment in self.conf.environments: + self.conf.experiment_management.export_phenotype(individual[environment], environment) self.conf.experiment_management.export_phenotype_images('data_fullevolution/' +environment+'/phenotype_images', @@ -113,7 +115,7 @@ def _new_individual(self, genotype): individual[environment].phenotype.measure_phenotype(self.conf.experiment_name) individual[environment].phenotype.export_phenotype_measurements(self.conf.experiment_name, environment) self.conf.experiment_management.export_individual(individual[environment], environment) - + print('new',individual[environment].evaluated) return individual async def load_individual(self, id): @@ -122,12 +124,10 @@ async def load_individual(self, id): individual = {} for environment in self.conf.environments: file_name = path+environment+'/individuals/individual_'+id+'.pkl' - if os.path.exists(file_name): - file = open(file_name, 'rb') - individual[environment] = pickle.load(file) - else: - individual[environment] = copy.deepcopy(individual[list(self.conf.environments.keys())[-1]]) + file = open(file_name, 'rb') + individual[environment] = pickle.load(file) + print(id, individual[environment].evaluated) return individual async def load_snapshot(self, gen_num): @@ -159,23 +159,24 @@ async def load_offspring(self, last_snapshot, population_size, offspring_size, n for robot_id in range(n_robots+1, next_robot_id): individuals.append(await self.load_individual('robot_'+str(robot_id))) - self.next_robot_id = next_robot_id return individuals async def init_pop(self, recovered_individuals=[]): """ Populates the population (individuals list) with Individual objects that contains their respective genotype. """ - # do recovery soon...! for i in range(self.conf.population_size-len(recovered_individuals)): individual = self._new_individual( self.conf.genotype_constructor(self.conf.genotype_conf, self.next_robot_id)) self.individuals.append(individual) self.next_robot_id += 1 + print('recovered ',len(recovered_individuals)) + print('before individuals',len(self.individuals)) self.individuals = recovered_individuals + self.individuals - - for environment in self.simulator_queue_envs: + print('after individuals',len(self.individuals)) + for environment in self.conf.environments: + print('cuuu', environment) await self.evaluate(new_individuals=self.individuals, gen_num=0, environment=environment) async def next_gen(self, gen_num, recovered_individuals=[]): @@ -236,18 +237,22 @@ async def evaluate(self, new_individuals, gen_num, environment, type_simulation # Parse command line / file input arguments # await self.simulator_connection.pause(True) robot_futures = [] + to_evaluate = [] for individual in new_individuals: - if individual[environment].fitness is None: + print(individual[environment].phenotype.id, individual[environment].evaluated) + if not individual[environment].evaluated: logger.info(f'Evaluating individual (gen {gen_num}) {individual[environment].genotype.id} ...') + to_evaluate.append(individual) robot_futures.append(asyncio.ensure_future(self.evaluate_single_robot(individual[environment], environment))) await asyncio.sleep(1) for i, future in enumerate(robot_futures): - individual = new_individuals[i][environment] + individual = to_evaluate[i][environment] logger.info(f'Evaluation of Individual {individual.phenotype.id}') individual.fitness, individual.phenotype._behavioural_measurements = await future + individual.evaluated = True if individual.phenotype._behavioural_measurements is None: assert (individual.fitness is None) diff --git a/pyrevolve/experiment_management.py b/pyrevolve/experiment_management.py index 444966a394..597da2d483 100644 --- a/pyrevolve/experiment_management.py +++ b/pyrevolve/experiment_management.py @@ -89,6 +89,7 @@ def export_snapshots(self, individuals, gen_num): def experiment_is_new(self): if not os.path.exists(self._experiment_folder()): return True + # if any robot in any environment has been finished for environment in self.environments: path, dirs, files = next(os.walk(os.path.join(self._data_folder()+'/'+environment, 'individuals'))) if len(files) > 0: @@ -108,7 +109,7 @@ def read_recovery_state(self, population_size, offspring_size): dir)) if os.path.isfile(os.path.join(path, dir, name))]) - # snapshot is vomplete if all body and brain files exist + # snapshot is complete if all body/brain files exist if exported_files == (population_size * 2): snapshots.append(int(dir.split('_')[1])) @@ -121,7 +122,7 @@ def read_recovery_state(self, population_size, offspring_size): last_snapshot = -1 n_robots = 0 - # if robot is developed in any of the environments, the nit exists + # if a robot is developed in any of the environments, then it exists robot_ids = [] for environment in self.environments: for r, d, f in os.walk(os.path.join(self._data_folder()+'/'+environment, 'individuals')): diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index b12cd0535c..8a86bbf3f8 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -233,10 +233,6 @@ def early_development(self, environment): grammar = self.grammar - print('regulated') - pp = pprint.PrettyPrinter(width=41, compact=True) - pp.pprint(grammar) - self.intermediate_phenotype = [[self.conf.axiom_w, []]] for i in range(0, self.conf.i_iterations): @@ -308,7 +304,6 @@ def late_development(self): self.add_imu_nodes() logger.info('Robot ' + str(self.id) + ' was late-developed.') - print(self.intermediate_phenotype) return self.phenotype def move_in_body(self, symbol): From c370701ba1e9bbad0dc559edd5eee9e9ae98f58e Mon Sep 17 00:00:00 2001 From: Karine Date: Thu, 12 Dec 2019 19:15:44 +0100 Subject: [PATCH 23/45] crossover and mutation for plasticity --- experiments/karines_experiments/baseline.py | 9 +- experiments/karines_experiments/plastic.py | 153 ++++++++++++++++++ .../karines_experiments/run-experiments | 18 ++- pyrevolve/evolution/population.py | 19 +-- pyrevolve/evolution/selection.py | 30 +++- .../crossover/standard_crossover.py | 8 +- .../mutation/standard_mutation.py | 70 +++++++- .../genotype/plasticoding/plasticoding.py | 1 - 8 files changed, 275 insertions(+), 33 deletions(-) create mode 100755 experiments/karines_experiments/plastic.py diff --git a/experiments/karines_experiments/baseline.py b/experiments/karines_experiments/baseline.py index b955c37f5a..d42460a52b 100755 --- a/experiments/karines_experiments/baseline.py +++ b/experiments/karines_experiments/baseline.py @@ -25,8 +25,8 @@ async def run(): """ # experiment params # - num_generations = 1#100 - population_size = 3#100 + num_generations = 2#100 + population_size = 1#100 offspring_size = 1#50 # environment world and z-start @@ -84,8 +84,8 @@ def fitness_function(robot_manager, robot): mutation_conf=mutation_conf, crossover_operator=standard_crossover, crossover_conf=crossover_conf, - selection=lambda individuals: tournament_selection(individuals, 2), - parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection), + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), population_management=steady_state_population_management, population_management_selector=tournament_selection, evaluation_time=settings.evaluation_time, @@ -145,7 +145,6 @@ def fitness_function(robot_manager, robot): await population.init_pop() experiment_management.export_snapshots(population.individuals, gen_num) - while gen_num < num_generations-1: gen_num += 1 population = await population.next_gen(gen_num) diff --git a/experiments/karines_experiments/plastic.py b/experiments/karines_experiments/plastic.py new file mode 100755 index 0000000000..91445852bc --- /dev/null +++ b/experiments/karines_experiments/plastic.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 2#100 + population_size = 1#100 + offspring_size = 1#50 + + # environment world and z-start + environments = {'plane': 0.03, + 'tilted5': 0.1 + } + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + environmental_conditions=['hill'], + max_terms_clause=2, + plastic=False, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + print(do_recovery) + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + print('fdsngfkdngkfdhbgsdjgnfdsfjgnsdkjfgnsdkjgnsdkhjgbnsdkjhgbskj',gen_num, has_offspring, next_robot_id) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function(robot_manager, robot): + contacts = measures.contacts(robot_manager, robot) + assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + measure_individuals=settings.measure_individuals, + environments=environments, + ) + + settings = parser.parse_args() + + simulator_queue_envs = {} + analyzer_queue_envs = {} + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port + settings.n_cores + 1 + + simulator_queue_envs[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue_envs[environment].start() + + analyzer_queue_envs[environment] = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue_envs[environment].start() + + population = Population(population_conf, simulator_queue_envs, analyzer_queue_envs, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index 315be852b5..475e473b8d 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -1,18 +1,26 @@ #!/bin/bash -# baseline - while true do for i in {1..1}; do - ./revolve.py --experiment-name karines_experiments/data/baseline_$i --run $i --manager experiments/karines_experiments/baseline.py --n-cores 4 --port-start 11400 --world worlds/plane.world --evaluation-time 50; + ./revolve.py --experiment-name karines_experiments/data/baseline_$i --run $i --manager experiments/karines_experiments/baseline.py --n-cores 4 --port-start 11400 --evaluation-time 50; + sleep 5s done done +while true + do + for i in {1..1}; do + ./revolve.py --experiment-name karines_experiments/data/plastic_$i --run $i --manager experiments/karines_experiments/plastic.py --n-cores 4 --port-start 11500 --evaluation-time 50; + + sleep 5s + done +done + @@ -24,7 +32,3 @@ while true done - - - - #./revolve.py --experiment-name karines_experiments/data/tilted5_$i --run $i --manager experiments/karines_experiments/tilted.py --n-cores 4 --port-start 11800 --world worlds/tilted5.world --z-start 0.1 --evaluation-time 50; diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index ead6811df0..eb3e2dad8a 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -171,12 +171,9 @@ async def init_pop(self, recovered_individuals=[]): self.individuals.append(individual) self.next_robot_id += 1 - print('recovered ',len(recovered_individuals)) - print('before individuals',len(self.individuals)) self.individuals = recovered_individuals + self.individuals - print('after individuals',len(self.individuals)) + for environment in self.conf.environments: - print('cuuu', environment) await self.evaluate(new_individuals=self.individuals, gen_num=0, environment=environment) async def next_gen(self, gen_num, recovered_individuals=[]): @@ -195,7 +192,10 @@ async def next_gen(self, gen_num, recovered_individuals=[]): # Crossover if self.conf.crossover_operator is not None: parents = self.conf.parent_selection(self.individuals) - child_genotype = self.conf.crossover_operator(parents, self.conf.genotype_conf, self.conf.crossover_conf) + child_genotype = self.conf.crossover_operator(self.conf.environments, + parents, + self.conf.genotype_conf, + self.conf.crossover_conf) child = Individual(child_genotype) else: child = self.conf.selection(self.individuals) @@ -205,16 +205,17 @@ async def next_gen(self, gen_num, recovered_individuals=[]): # Mutation operator child_genotype = self.conf.mutation_operator(child.genotype, self.conf.mutation_conf) + sys.exit() # Insert individual in new population individual = self._new_individual(child_genotype) - new_individuals.append(individual) - # evaluate new individuals - await self.evaluate(new_individuals, gen_num) - new_individuals = recovered_individuals + new_individuals + # evaluate new individuals + for environment in self.conf.environments: + await self.evaluate(new_individuals=self.individuals, gen_num=gen_num, environment=environment) + # create next population if self.conf.population_management_selector is not None: new_individuals = self.conf.population_management(self.individuals, new_individuals, diff --git a/pyrevolve/evolution/selection.py b/pyrevolve/evolution/selection.py index 9b3e06cb8c..6e854edbe4 100644 --- a/pyrevolve/evolution/selection.py +++ b/pyrevolve/evolution/selection.py @@ -1,15 +1,31 @@ from random import randint +import statistics _neg_inf = -float('Inf') -def _compare_maj_fitness(indiv_1, indiv_2): - fit_1 = _neg_inf if indiv_1.fitness is None else indiv_1.fitness - fit_2 = _neg_inf if indiv_2.fitness is None else indiv_2.fitness +def _compare_maj_fitness(indiv_1, indiv_2, environments): + + indiv_1_fitness = [] + indiv_2_fitness = [] + + for environment in environments: + indiv_1_fitness.append(indiv_1[environment].fitness) + indiv_2_fitness.append(indiv_2[environment].fitness) + + # indiv_1_fitness = abs(sum(indiv_1_fitness) - statistics.stdev(indiv_1_fitness)) + # indiv_2_fitness = abs(sum(indiv_2_fitness) - statistics.stdev(indiv_2_fitness)) + + indiv_1_fitness = statistics.mean(indiv_1_fitness) + indiv_2_fitness = statistics.mean(indiv_2_fitness) + + fit_1 = _neg_inf if indiv_1_fitness is None else indiv_1_fitness + fit_2 = _neg_inf if indiv_2_fitness is None else indiv_2_fitness + return fit_1 > fit_2 -def tournament_selection(population, k=2): +def tournament_selection(population, environments, k=2): """ Perform tournament selection and return best individual :param k: amount of individuals to participate in tournament @@ -17,12 +33,12 @@ def tournament_selection(population, k=2): best_individual = None for _ in range(k): individual = population[randint(0, len(population) - 1)] - if (best_individual is None) or (_compare_maj_fitness(individual, best_individual)): + if (best_individual is None) or (_compare_maj_fitness(individual, best_individual, environments)): best_individual = individual return best_individual -def multiple_selection(population, selection_size, selection_function): +def multiple_selection(population, selection_size, selection_function, environments): """ Perform selection on population of distinct group, can be used in the form parent selection or survival selection :param population: parent selection in population @@ -34,7 +50,7 @@ def multiple_selection(population, selection_size, selection_function): for _ in range(selection_size): new_individual = False while new_individual is False: - selected_individual = selection_function(population) + selected_individual = selection_function(population, environments) if selected_individual not in selected_individuals: selected_individuals.append(selected_individual) new_individual = True diff --git a/pyrevolve/genotype/plasticoding/crossover/standard_crossover.py b/pyrevolve/genotype/plasticoding/crossover/standard_crossover.py index d95ad6286c..90ef63134a 100644 --- a/pyrevolve/genotype/plasticoding/crossover/standard_crossover.py +++ b/pyrevolve/genotype/plasticoding/crossover/standard_crossover.py @@ -19,6 +19,7 @@ def generate_child_genotype(parent_genotypes, genotype_conf, crossover_conf): else: for letter in Alphabet.modules(): parent = random.randint(0, 1) + print(letter, parent) # gets the production rule for the respective letter grammar[letter[0]] = parent_genotypes[parent].grammar[letter[0]] @@ -27,15 +28,18 @@ def generate_child_genotype(parent_genotypes, genotype_conf, crossover_conf): return genotype.clone() -def standard_crossover(parent_individuals, genotype_conf, crossover_conf): +def standard_crossover(environments, parent_individuals, genotype_conf, crossover_conf): """ Creates an child (individual) through crossover with two parents :param parent_genotypes: genotypes of the parents to be used for crossover :return: genotype result of the crossover """ - parent_genotypes = [p.genotype for p in parent_individuals] + first_environment = list(environments.keys())[-1] + + parent_genotypes = [p[first_environment].genotype for p in parent_individuals] new_genotype = generate_child_genotype(parent_genotypes, genotype_conf, crossover_conf) + #TODO what if you have more than 2 parents? fix log genotype_logger.info( f'crossover: for genome {new_genotype.id} - p1: {parent_genotypes[0].id} p2: {parent_genotypes[1].id}.') diff --git a/pyrevolve/genotype/plasticoding/mutation/standard_mutation.py b/pyrevolve/genotype/plasticoding/mutation/standard_mutation.py index e877a947a1..ff5c56aabb 100644 --- a/pyrevolve/genotype/plasticoding/mutation/standard_mutation.py +++ b/pyrevolve/genotype/plasticoding/mutation/standard_mutation.py @@ -1,8 +1,8 @@ import random from pyrevolve.genotype.plasticoding.plasticoding import Alphabet, Plasticoding from ....custom_logging.logger import genotype_logger - - +import sys +import pprint def handle_deletion(genotype): @@ -103,6 +103,69 @@ def handle_addition(genotype, genotype_conf): return genotype +def handle_clause(genotype, genotype_conf): + + pp = pprint.PrettyPrinter(depth=6) + + max_terms_clause = 2 # TMP! + + target_letter = random.choice(list(genotype.grammar)) + target_clause = random.choice(range(0, len(genotype.grammar[target_letter]))) + # TEMP! + environmental_conditions=['hill'] + logic_operators=['and', 'or'] + + print(target_letter, target_clause) + pp.pprint(genotype.grammar[target_letter][target_clause][0]) + + # defines which mutations are possible + + possible_mutations = ['flipping_value'] + + if len(genotype.grammar[target_letter][target_clause][0]) > 1: + possible_mutations.append('deletion') + possible_mutations.append('flipping_operator') + + if len(genotype.grammar[target_letter][target_clause][0]) < max_terms_clause: + possible_mutations.append('addition') + + mutation_type = random.choice(possible_mutations) + print(mutation_type) + + + # deletes terms items and logic operator + if mutation_type == 'deletion': + position_delete = random.choice(range(0, len(genotype.grammar[target_letter][target_clause][0]) + 1, 2)) + genotype.grammar[target_letter][target_clause][0].pop(position_delete) + if position_delete == 0: + genotype.grammar[target_letter][target_clause][0].pop(position_delete) + else: + genotype.grammar[target_letter][target_clause][0].pop(position_delete-1) + + if mutation_type == 'addition': + + term = random.choice(environmental_conditions) + state = random.choice([True, False]) + + genotype.grammar[target_letter][target_clause][0].append([random.choice(logic_operators)]) + genotype.grammar[target_letter][target_clause][0].append([term, '==', state]) + + if mutation_type == 'flipping_value': + position_flip = random.choice(range(0, len(genotype.grammar[target_letter][target_clause][0]) + 1, 2)) + if genotype.grammar[target_letter][target_clause][0][position_flip][2]: + genotype.grammar[target_letter][target_clause][0][position_flip][2] = False + else: + genotype.grammar[target_letter][target_clause][0][position_flip][2] = True + + if mutation_type == 'flipping_operator': + position_flip = random.choice(range(1, len(genotype.grammar[target_letter][target_clause][0]), 2)) + if genotype.grammar[target_letter][target_clause][0][position_flip] == 'and': + genotype.grammar[target_letter][target_clause][0][position_flip] = ['or'] + else: + genotype.grammar[target_letter][target_clause][0][position_flip] = ['and'] + + pp.pprint(genotype.grammar[target_letter][target_clause][0]) + def standard_mutation(genotype, mutation_conf): """ Mutates genotype through addition/removal/swapping of symbols @@ -118,12 +181,15 @@ def standard_mutation(genotype, mutation_conf): return new_genotype else: mutation_type = random.randint(1, 3) # NTS: better way? + mutation_type = 4 if mutation_type == 1: modified_genotype = handle_deletion(new_genotype) elif mutation_type == 2: modified_genotype = handle_swap(new_genotype) elif mutation_type == 3: modified_genotype = handle_addition(new_genotype, mutation_conf.genotype_conf) + elif mutation_type == 4: + modified_genotype = handle_clause(new_genotype, mutation_conf.genotype_conf) else: raise Exception( 'mutation_type value was not in the expected range (1,3). The value was: {}'.format(mutation_type)) diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index 8a86bbf3f8..73bce7934e 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -17,7 +17,6 @@ import math import copy import itertools -import pprint import sys import json From 7fca73806a08bb855ef6ee05ba0b6211bb722101 Mon Sep 17 00:00:00 2001 From: Karine Date: Thu, 12 Dec 2019 19:17:32 +0100 Subject: [PATCH 24/45] tiny --- pyrevolve/evolution/population.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index eb3e2dad8a..e026dee5c5 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -205,7 +205,7 @@ async def next_gen(self, gen_num, recovered_individuals=[]): # Mutation operator child_genotype = self.conf.mutation_operator(child.genotype, self.conf.mutation_conf) - sys.exit() + # Insert individual in new population individual = self._new_individual(child_genotype) new_individuals.append(individual) From 319f7d0c77948f694e68c9b50827d274967426fd Mon Sep 17 00:00:00 2001 From: Karine Date: Tue, 17 Dec 2019 16:39:18 +0100 Subject: [PATCH 25/45] final adjusments for phenotypic plasticity in multiseason experiment --- experiments/karines_experiments/baseline.py | 32 +++++------- experiments/karines_experiments/plastic.py | 26 ++++------ pyrevolve/angle/manage/world.py | 52 +++++++++---------- pyrevolve/evolution/population.py | 43 ++++++++------- pyrevolve/evolution/selection.py | 4 -- .../crossover/standard_crossover.py | 1 - pyrevolve/tol/manage/measures.py | 2 +- 7 files changed, 72 insertions(+), 88 deletions(-) diff --git a/experiments/karines_experiments/baseline.py b/experiments/karines_experiments/baseline.py index 343ff69450..df712c4d39 100755 --- a/experiments/karines_experiments/baseline.py +++ b/experiments/karines_experiments/baseline.py @@ -25,9 +25,9 @@ async def run(): """ # experiment params # - num_generations = 2#100 - population_size = 1#100 - offspring_size = 1#50 + num_generations = 100 + population_size = 100 + offspring_size = 50 # environment world and z-start environments = {'plane': 0.03, @@ -36,8 +36,6 @@ async def run(): genotype_conf = PlasticodingConfig( max_structural_modules=15, - environmental_conditions=['hill'], - max_terms_clause=2, plastic=False, ) @@ -57,11 +55,10 @@ async def run(): do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) - print(do_recovery) + if do_recovery: gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, offspring_size) - print('fdsngfkdngkfdhbgsdjgnfdsfjgnsdkjfgnsdkjgnsdkhjgbnsdkjhgbskj',gen_num, has_offspring, next_robot_id) if gen_num == num_generations-1: logger.info('Experiment is already complete.') @@ -71,8 +68,8 @@ async def run(): next_robot_id = 1 def fitness_function(robot_manager, robot): - contacts = measures.contacts(robot_manager, robot) - assert(contacts != 0) + #contacts = measures.contacts(robot_manager, robot) + #assert(contacts != 0) return fitness.displacement_velocity_hill(robot_manager, robot, False) population_conf = PopulationConfig( @@ -97,9 +94,7 @@ def fitness_function(robot_manager, robot): settings = parser.parse_args() - simulator_queue_envs = {} - analyzer_queue_envs = {} - + simulator_queue = {} previous_port = None for environment in environments: @@ -110,15 +105,16 @@ def fitness_function(robot_manager, robot): port = settings.port_start previous_port = port else: - port = previous_port + settings.n_cores + 1 + port = previous_port+settings.n_cores + previous_port = port - simulator_queue_envs[environment] = SimulatorQueue(settings.n_cores, settings, port) - await simulator_queue_envs[environment].start() + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() - analyzer_queue_envs[environment] = AnalyzerQueue(1, settings, port+settings.n_cores) - await analyzer_queue_envs[environment].start() + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() - population = Population(population_conf, simulator_queue_envs, analyzer_queue_envs, next_robot_id) + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) if do_recovery: diff --git a/experiments/karines_experiments/plastic.py b/experiments/karines_experiments/plastic.py index 3e0cb6207c..e0c9456432 100755 --- a/experiments/karines_experiments/plastic.py +++ b/experiments/karines_experiments/plastic.py @@ -25,9 +25,9 @@ async def run(): """ # experiment params # - num_generations = 1#100 - population_size = 4#100 - offspring_size = 2#50 + num_generations = 100 + population_size = 100 + offspring_size = 50 # environment world and z-start environments = {'plane': 0.03, @@ -94,9 +94,7 @@ def fitness_function(robot_manager, robot): settings = parser.parse_args() - simulator_queue_envs = {} - analyzer_queue = None - + simulator_queue = {} previous_port = None for environment in environments: @@ -107,20 +105,16 @@ def fitness_function(robot_manager, robot): port = settings.port_start previous_port = port else: - port = previous_port + settings.n_cores + 1 + port = previous_port+settings.n_cores previous_port = port - print(environment, port) - simulator_queue_envs[environment] = SimulatorQueue(settings.n_cores, settings, port) - await simulator_queue_envs[environment].start() - # await asyncio.sleep(3) - - print('anal', port+ settings.n_cores+ 1) - analyzer_queue = AnalyzerQueue(1, settings, port+ settings.n_cores + 1) - #await analyzer_queue.start() + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() - population = Population(population_conf, simulator_queue_envs, analyzer_queue, next_robot_id) + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) if do_recovery: diff --git a/pyrevolve/angle/manage/world.py b/pyrevolve/angle/manage/world.py index 31c8fd9a9b..12539ce419 100644 --- a/pyrevolve/angle/manage/world.py +++ b/pyrevolve/angle/manage/world.py @@ -11,7 +11,7 @@ from asyncio import Future from datetime import datetime from pygazebo.msg import gz_string_pb2 -from pygazebo.msg.contacts_pb2 import Contacts +#from pygazebo.msg.contacts_pb2 import Contacts from pyrevolve.SDF.math import Vector3 from pyrevolve.spec.msgs import BoundingBox @@ -208,11 +208,11 @@ async def _init(self): self._update_states ) - self.contact_subscriber = await self.manager.subscribe( - '/gazebo/default/physics/contacts', - 'gazebo.msgs.Contacts', - self._update_contacts - ) + # self.contact_subscriber = await self.manager.subscribe( + # '/gazebo/default/physics/contacts', + # 'gazebo.msgs.Contacts', + # self._update_contacts + # ) # Awaiting this immediately will lock the program update_state_future = self.set_state_update_frequency( @@ -230,7 +230,7 @@ async def _init(self): # Wait for connections await self.pose_subscriber.wait_for_connection() - await self.contact_subscriber.wait_for_connection() + #await self.contact_subscriber.wait_for_connection() await update_state_future if self.do_restore: @@ -239,7 +239,7 @@ async def _init(self): async def disconnect(self): await super().disconnect() await self.pose_subscriber.remove() - await self.contact_subscriber.remove() + #await self.contact_subscriber.remove() await self.battery_handler.stop() async def create_snapshot(self, pause_when_saving=True): @@ -648,24 +648,24 @@ def _update_states(self, msg): robot_manager.dead = True self.call_update_triggers() - - def _update_contacts(self, msg): - """ - Handles the contacts with the ground info message by updating robot contacts. - :param msg: - :return: - """ - contacts = Contacts() - contacts.ParseFromString(msg) - # if there was any contact in that instant - if contacts.contact: - # fetches one or more contact points for each module that has contacts - for module_contacts in contacts.contact: - robot_name = module_contacts.collision1.split('::')[0] - robot_manager = self.robot_managers.get(robot_name, None) - if not robot_manager: - continue - robot_manager.update_contacts(self, module_contacts) + # + # def _update_contacts(self, msg): + # """ + # Handles the contacts with the ground info message by updating robot contacts. + # :param msg: + # :return: + # """ + # contacts = Contacts() + # contacts.ParseFromString(msg) + # # if there was any contact in that instant + # if contacts.contact: + # # fetches one or more contact points for each module that has contacts + # for module_contacts in contacts.contact: + # robot_name = module_contacts.collision1.split('::')[0] + # robot_manager = self.robot_managers.get(robot_name, None) + # if not robot_manager: + # continue + # robot_manager.update_contacts(self, module_contacts) def add_update_trigger(self, callback): """ diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index dea7de15ff..a08c5bd935 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -72,7 +72,7 @@ def __init__(self, class Population: - def __init__(self, conf: PopulationConfig, simulator_queue_envs, analyzer_queue=None, next_robot_id=1): + def __init__(self, conf: PopulationConfig, simulator_queue, analyzer_queue=None, next_robot_id=1): """ Creates a Population object that initialises the individuals in the population with an empty list @@ -87,7 +87,7 @@ def __init__(self, conf: PopulationConfig, simulator_queue_envs, analyzer_queue= self.conf = conf self.individuals = [] self.analyzer_queue = analyzer_queue - self.simulator_queue_envs = simulator_queue_envs + self.simulator_queue = simulator_queue self.next_robot_id = next_robot_id def _new_individual(self, genotype): @@ -159,10 +159,6 @@ async def load_offspring(self, last_snapshot, population_size, offspring_size, n async def consolidate_fitness(self, individuals): - for individual_ref in individuals: - for enviroment in self.conf.environments: - individual_ref[enviroment].fitness = random() - if len(self.conf.environments) == 0: for individual in individuals: fit = individual[list(self.conf.environments.keys())[-1]] @@ -175,30 +171,32 @@ async def consolidate_fitness(self, individuals): for individual_comp in individuals: equal = 0 better = 0 - for enviroment in self.conf.environments: - - if individual_ref[enviroment].fitness is None and individual_comp[enviroment].fitness is None: + for environment in self.conf.environments: + if individual_ref[environment].fitness is None \ + and individual_comp[environment].fitness is None: equal += 1 - if individual_ref[enviroment].fitness is None and individual_comp[enviroment].fitness is not None: + if individual_ref[environment].fitness is None \ + and individual_comp[environment].fitness is not None: equal += -1 - if individual_ref[enviroment].fitness is not None and individual_comp[enviroment].fitness is None: + if individual_ref[environment].fitness is not None \ + and individual_comp[environment].fitness is None: better += 1 + if individual_ref[environment].fitness is not None \ + and individual_comp[environment].fitness is not None: - if individual_ref[enviroment].fitness is not None and individual_comp[enviroment].fitness is not None: - - if individual_ref[enviroment].fitness > individual_comp[enviroment].fitness: + if individual_ref[environment].fitness > individual_comp[environment].fitness: better += 1 - if individual_ref[enviroment].fitness < individual_comp[enviroment].fitness: + if individual_ref[environment].fitness < individual_comp[environment].fitness: equal += -1 - if individual_ref[enviroment].fitness == individual_comp[enviroment].fitness: + if individual_ref[environment].fitness == individual_comp[environment].fitness: equal += 1 - # if it ref is not worse in any objective, and better in at least one, tje comp becomes slave of ref + # if it ref is not worse in any objective, and better in at least one, the comp becomes slave of ref if equal >= 0 and better > 0: slaves += 1 @@ -208,8 +206,8 @@ async def consolidate_fitness(self, individuals): self.conf.experiment_management.export_consolidated_fitness( individual[list(self.conf.environments.keys())[-1]],) - self.conf.experiment_management.export_individual( individual[list(self.conf.environments.keys())[-1]], - list(self.conf.environments.keys())[-1]) + self.conf.experiment_management.export_individual(individual[list(self.conf.environments.keys())[-1]], + list(self.conf.environments.keys())[-1]) async def init_pop(self, recovered_individuals=[]): """ @@ -269,7 +267,6 @@ async def next_gen(self, gen_num, recovered_individuals=[]): for environment in self.conf.environments: await self.evaluate(new_individuals=new_individuals, gen_num=gen_num, environment=environment) - selection_pool = self.individuals + new_individuals await self.consolidate_fitness(selection_pool) @@ -282,7 +279,7 @@ async def next_gen(self, gen_num, recovered_individuals=[]): else: new_individuals = self.conf.population_management(self.individuals, new_individuals, self.conf) - new_population = Population(self.conf, self.simulator_queue_envs, self.analyzer_queue, self.next_robot_id) + new_population = Population(self.conf, self.simulator_queue, self.analyzer_queue, self.next_robot_id) new_population.individuals = new_individuals logger.info(f'Population selected in gen {gen_num} with {len(new_population.individuals)} individuals...') @@ -313,6 +310,7 @@ async def evaluate(self, new_individuals, gen_num, environment, type_simulation for i, future in enumerate(robot_futures): individual = to_evaluate[i][environment] + logger.info(f'Evaluation of Individual {individual.phenotype.id}') individual.fitness, individual.phenotype._behavioural_measurements = await future @@ -342,4 +340,5 @@ async def evaluate_single_robot(self, individual, environment): logger.info(f"discarding robot {individual} because there are {collisions} self collisions") return None, None - return await self.simulator_queue_envs[environment].test_robot(individual, self.conf) + return await self.simulator_queue[environment].test_robot(individual, self.conf) + diff --git a/pyrevolve/evolution/selection.py b/pyrevolve/evolution/selection.py index 9276234289..62b95d854e 100644 --- a/pyrevolve/evolution/selection.py +++ b/pyrevolve/evolution/selection.py @@ -8,10 +8,6 @@ def _compare_maj_fitness(indiv_1, indiv_2, environments): fit_1 = indiv_1[list(environments.keys())[-1]].consolidated_fitness fit_2 = indiv_2[list(environments.keys())[-1]].consolidated_fitness - print(list(environments.keys())[-1],list(environments.keys())[-1]) - print('buceta1', indiv_1[list(environments.keys())[-1]].phenotype.id, fit_1) - print('buceta2', indiv_2[list(environments.keys())[-1]].phenotype.id, fit_2) - fit_1 = _neg_inf if fit_1 is None else fit_1 fit_2 = _neg_inf if fit_2 is None else fit_2 diff --git a/pyrevolve/genotype/plasticoding/crossover/standard_crossover.py b/pyrevolve/genotype/plasticoding/crossover/standard_crossover.py index 90ef63134a..2c0afad436 100644 --- a/pyrevolve/genotype/plasticoding/crossover/standard_crossover.py +++ b/pyrevolve/genotype/plasticoding/crossover/standard_crossover.py @@ -19,7 +19,6 @@ def generate_child_genotype(parent_genotypes, genotype_conf, crossover_conf): else: for letter in Alphabet.modules(): parent = random.randint(0, 1) - print(letter, parent) # gets the production rule for the respective letter grammar[letter[0]] = parent_genotypes[parent].grammar[letter[0]] diff --git a/pyrevolve/tol/manage/measures.py b/pyrevolve/tol/manage/measures.py index 4e0f007773..64130b8cdb 100644 --- a/pyrevolve/tol/manage/measures.py +++ b/pyrevolve/tol/manage/measures.py @@ -22,7 +22,7 @@ def __init__(self, robot_manager = None, robot = None): self.displacement_velocity = displacement_velocity(robot_manager) self.displacement_velocity_hill = displacement_velocity_hill(robot_manager) self.head_balance = head_balance(robot_manager) - self.contacts = -1#contacts(robot_manager, robot) + self.contacts = -1 #contacts(robot_manager, robot) else: self.velocity = None self.displacement = None From c6949ccb8f60e46c8eee6f856af2ba77e9957503 Mon Sep 17 00:00:00 2001 From: Karine Date: Tue, 17 Dec 2019 18:20:38 +0100 Subject: [PATCH 26/45] fixed bug mutation --- experiments/karines_experiments/baseline.py | 2 + experiments/karines_experiments/plastic.py | 2 + .../karines_experiments/run-experiments | 46 +++++- .../mutation/standard_mutation.py | 150 +++++++++++++----- .../genotype/plasticoding/plasticoding.py | 5 +- 5 files changed, 159 insertions(+), 46 deletions(-) diff --git a/experiments/karines_experiments/baseline.py b/experiments/karines_experiments/baseline.py index df712c4d39..f1a4a4bdcd 100755 --- a/experiments/karines_experiments/baseline.py +++ b/experiments/karines_experiments/baseline.py @@ -95,6 +95,8 @@ def fitness_function(robot_manager, robot): settings = parser.parse_args() simulator_queue = {} + analyzer_queue = None + previous_port = None for environment in environments: diff --git a/experiments/karines_experiments/plastic.py b/experiments/karines_experiments/plastic.py index e0c9456432..5f4c47d651 100755 --- a/experiments/karines_experiments/plastic.py +++ b/experiments/karines_experiments/plastic.py @@ -95,6 +95,8 @@ def fitness_function(robot_manager, robot): settings = parser.parse_args() simulator_queue = {} + analyzer_queue = None + previous_port = None for environment in environments: diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index 475e473b8d..7ba3bf6e3e 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -3,32 +3,68 @@ while true do - for i in {1..1}; do - ./revolve.py --experiment-name karines_experiments/data/baseline_$i --run $i --manager experiments/karines_experiments/baseline.py --n-cores 4 --port-start 11400 --evaluation-time 50; + for i in {1..10}; do + ./revolve.py --experiment-name karines_experiments/data/baseline_$i --run $i --manager experiments/karines_experiments/baseline.py --n-cores 4 --port-start 11000 --evaluation-time 50; sleep 5s done done +while true + do + for i in {11..20}; do + ./revolve.py --experiment-name karines_experiments/data/baseline_$i --run $i --manager experiments/karines_experiments/baseline.py --n-cores 4 --port-start 11010 --evaluation-time 50; + + sleep 5s + done +done + +while true + do + for i in {21..30}; do + ./revolve.py --experiment-name karines_experiments/data/baseline_$i --run $i --manager experiments/karines_experiments/baseline.py --n-cores 4 --port-start 11020 --evaluation-time 50; + + sleep 5s + done +done while true do - for i in {1..1}; do - ./revolve.py --experiment-name karines_experiments/data/plastic_$i --run $i --manager experiments/karines_experiments/plastic.py --n-cores 4 --port-start 11500 --evaluation-time 50; + for i in {1..10}; do + ./revolve.py --experiment-name karines_experiments/data/plastic_$i --run $i --manager experiments/karines_experiments/plastic.py --n-cores 4 --port-start 11030 --evaluation-time 50; sleep 5s done done +while true + do + for i in {11..20}; do + ./revolve.py --experiment-name karines_experiments/data/plastic_$i --run $i --manager experiments/karines_experiments/plastic.py --n-cores 4 --port-start 11040 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {21..30}; do + ./revolve.py --experiment-name karines_experiments/data/plastic_$i --run $i --manager experiments/karines_experiments/plastic.py --n-cores 4 --port-start 11050 --evaluation-time 50; + + sleep 5s + done +done while true do - sleep 1800s; + sleep 900s; kill $( ps aux | grep 'gzserver' | awk '{print $2}'); kill $( ps aux | grep 'revolve.py' | awk '{print $2}'); + sleep 60s; done diff --git a/pyrevolve/genotype/plasticoding/mutation/standard_mutation.py b/pyrevolve/genotype/plasticoding/mutation/standard_mutation.py index ee23dac229..77f778666c 100644 --- a/pyrevolve/genotype/plasticoding/mutation/standard_mutation.py +++ b/pyrevolve/genotype/plasticoding/mutation/standard_mutation.py @@ -4,10 +4,65 @@ import sys - def handle_deletion(genotype): """ Deletes symbols from genotype + :param genotype: genotype to be modified + :return: genotype + """ + target_production_rule = random.choice(list(genotype.grammar)) + if (len(genotype.grammar[target_production_rule])) > 1: + symbol_to_delete = random.choice(genotype.grammar[target_production_rule]) + if symbol_to_delete[0] != Alphabet.CORE_COMPONENT: + genotype.grammar[target_production_rule].remove(symbol_to_delete) + genotype_logger.info( + f'mutation: remove in {genotype.id} for {target_production_rule} at {symbol_to_delete[0]}.') + return genotype + + +def handle_swap(genotype): + """ + Swaps symbols within the genotype + :param genotype: genotype to be modified + :return: genotype + """ + target_production_rule = random.choice(list(genotype.grammar)) + if (len(genotype.grammar[target_production_rule])) > 1: + symbols_to_swap = random.choices(population=genotype.grammar[target_production_rule], k=2) + for symbol in symbols_to_swap: + if symbol[0] == Alphabet.CORE_COMPONENT: + return genotype + item_index_1 = genotype.grammar[target_production_rule].index(symbols_to_swap[0]) + item_index_2 = genotype.grammar[target_production_rule].index(symbols_to_swap[1]) + genotype.grammar[target_production_rule][item_index_2], genotype.grammar[target_production_rule][item_index_1] = \ + genotype.grammar[target_production_rule][item_index_1], genotype.grammar[target_production_rule][item_index_2] + genotype_logger.info( + f'mutation: swap in {genotype.id} for {target_production_rule} between {symbols_to_swap[0]} and {symbols_to_swap[1]}.') + return genotype + + +def handle_addition(genotype, genotype_conf): + """ + Adds symbol to genotype + :param genotype: genotype to add to + :param genotype_conf: configuration for the genotype + :return: genotype + """ + target_production_rule = random.choice(list(genotype.grammar)) + if target_production_rule == Alphabet.CORE_COMPONENT: + addition_index = random.randint(1, len(genotype.grammar[target_production_rule]) - 1) + else: + addition_index = random.randint(0, len(genotype.grammar[target_production_rule]) - 1) + symbol_to_add = generate_symbol(genotype_conf) + genotype.grammar[target_production_rule].insert(addition_index, symbol_to_add) + genotype_logger.info( + f'mutation: add {symbol_to_add} in {genotype.id} for {target_production_rule} at {addition_index}.') + return genotype + + +def handle_deletion_plastic(genotype): + """ + Deletes symbols from genotype :param genotype: genotype to be modified @@ -26,7 +81,7 @@ def handle_deletion(genotype): return genotype -def handle_swap(genotype): +def handle_swap_plastic(genotype): """ Swaps symbols within the genotype @@ -52,6 +107,31 @@ def handle_swap(genotype): return genotype +def handle_addition_plastic(genotype, genotype_conf): + """ + Adds symbol to genotype + + :param genotype: genotype to add to + :param genotype_conf: configuration for the genotype + + :return: genotype + """ + + target_letter = random.choice(list(genotype.grammar)) + target_clause = random.choice(range(0, len(genotype.grammar[target_letter]))) + + if target_letter == Alphabet.CORE_COMPONENT: + addition_index = random.randint(1, len(genotype.grammar[target_letter][target_clause][1]) - 1) + else: + addition_index = random.randint(0, len(genotype.grammar[target_letter][target_clause][1]) - 1) + symbol_to_add = generate_symbol(genotype_conf) + genotype.grammar[target_letter][target_clause][1].insert(addition_index, symbol_to_add) + + genotype_logger.info( + f'mutation: add {symbol_to_add} in {genotype.id} for {target_letter} in {target_clause} at {addition_index}.') + return genotype + + def generate_symbol(genotype_conf): """ Generates a symbol for addition @@ -88,34 +168,8 @@ def generate_symbol(genotype_conf): return symbol -def handle_addition(genotype, genotype_conf): - """ - Adds symbol to genotype - - :param genotype: genotype to add to - :param genotype_conf: configuration for the genotype - - :return: genotype - """ - - target_letter = random.choice(list(genotype.grammar)) - target_clause = random.choice(range(0, len(genotype.grammar[target_letter]))) - - if target_letter == Alphabet.CORE_COMPONENT: - addition_index = random.randint(1, len(genotype.grammar[target_letter][target_clause][1]) - 1) - else: - addition_index = random.randint(0, len(genotype.grammar[target_letter][target_clause][1]) - 1) - symbol_to_add = generate_symbol(genotype_conf) - genotype.grammar[target_letter][target_clause][1].insert(addition_index, symbol_to_add) - - genotype_logger.info( - f'mutation: add {symbol_to_add} in {genotype.id} for {target_letter} in {target_clause} at {addition_index}.') - return genotype - - def handle_clause(genotype, mutation_conf): - max_terms_clause = mutation_conf.genotype_conf.max_terms_clause target_letter = random.choice(list(genotype.grammar)) @@ -170,6 +224,7 @@ def handle_clause(genotype, mutation_conf): return genotype + def standard_mutation(genotype, mutation_conf): """ Mutates genotype through addition/removal/swapping of symbols @@ -183,21 +238,36 @@ def standard_mutation(genotype, mutation_conf): mutation_attempt = random.uniform(0.0, 1.0) if mutation_attempt > mutation_conf.mutation_prob: return new_genotype + else: + if mutation_conf.genotype_conf.plastic: - mutation_type = random.randint(1, 4) # NTS: better way? + + mutation_type = random.randint(1, 4) + + if mutation_type == 1: + modified_genotype = handle_deletion_plastic(new_genotype) + elif mutation_type == 2: + modified_genotype = handle_swap_plastic(new_genotype) + elif mutation_type == 3: + modified_genotype = handle_addition_plastic(new_genotype, mutation_conf.genotype_conf) + elif mutation_type == 4: + modified_genotype = handle_clause(new_genotype, mutation_conf) + else: + raise Exception( + 'mutation_type value was not in the expected range (1,4). The value was: {}'.format(mutation_type)) else: + mutation_type = random.randint(1, 3) - if mutation_type == 1: - modified_genotype = handle_deletion(new_genotype) - elif mutation_type == 2: - modified_genotype = handle_swap(new_genotype) - elif mutation_type == 3: - modified_genotype = handle_addition(new_genotype, mutation_conf.genotype_conf) - elif mutation_type == 4: - modified_genotype = handle_clause(new_genotype, mutation_conf) - else: - raise Exception( - 'mutation_type value was not in the expected range (1,3). The value was: {}'.format(mutation_type)) + if mutation_type == 1: + modified_genotype = handle_deletion(new_genotype) + elif mutation_type == 2: + modified_genotype = handle_swap(new_genotype) + elif mutation_type == 3: + modified_genotype = handle_addition(new_genotype, mutation_conf.genotype_conf) + else: + raise Exception( + 'mutation_type value was not in the expected range (1,3). The value was: {}'.format(mutation_type)) + return modified_genotype diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index 73bce7934e..03bae748b3 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -215,6 +215,10 @@ def early_development(self, environment): # if no clause is true, letter doesnt get expressed if len(true_clauses) == 0: grammar[letter] = [] + + # actually...for now, it is safer to just express the first rule + # because this could result in tiny robots, which could be exploited in the hill + #grammar[letter] = self.grammar[letter][0][1] else: # if multiple clauses are true, all get expressed for idx in range(0, len(true_clauses)): @@ -227,7 +231,6 @@ def early_development(self, environment): aux_list = self.grammar[letter][true_clauses[idx]][1] grammar[letter].extend(aux_list) - else: grammar = self.grammar From ed685ea689cd8fad4ac08d8424db4fff2edc3089 Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 10 Jan 2020 18:44:44 +0100 Subject: [PATCH 27/45] adapts scripts od analysis --- .../consolidate_experiments.py | 126 ++++++++++-------- 1 file changed, 67 insertions(+), 59 deletions(-) diff --git a/experiments/karines_experiments/consolidate_experiments.py b/experiments/karines_experiments/consolidate_experiments.py index fee0fa76de..50b3ecab99 100644 --- a/experiments/karines_experiments/consolidate_experiments.py +++ b/experiments/karines_experiments/consolidate_experiments.py @@ -1,20 +1,23 @@ import os - +import math # set these variables according to your experiments # -dirpath = 'data' +dirpath = 'data/' experiments_type = [ - 'plane', - 'lava' + 'baseline', + 'plastic' ] -runs = 10 -# set these variables according to your experiments # +environments = [ + 'plane', + 'tilted5' + ] +runs = 30 +# set these variables according to your experiments # -def build_headers(path): +def build_headers(path1, path2): - print(path + "/all_measures.txt") - file_summary = open(path + "/all_measures.tsv", "w+") + file_summary = open(path1 + "/all_measures.tsv", "w+") file_summary.write('robot_id\t') behavior_headers = [] @@ -36,7 +39,7 @@ def build_headers(path): # file_summary.write(measure+'\t') phenotype_headers = [] - with open(path + '/data_fullevolution/descriptors/phenotype_desc_robot_1.txt') as file: + with open(path1 + '/descriptors/phenotype_desc_robot_1.txt') as file: for line in file: measure, value = line.strip().split(' ') phenotype_headers.append(measure) @@ -44,64 +47,69 @@ def build_headers(path): file_summary.write('fitness\n') file_summary.close() - file_summary = open(path + "/snapshots_ids.tsv", "w+") + file_summary = open(path2 + "/snapshots_ids.tsv", "w+") file_summary.write('generation\trobot_id\n') file_summary.close() return behavior_headers, phenotype_headers - for exp in experiments_type: - for run in range(1, runs+1): - print(exp, run) - path = os.path.join(dirpath, str(exp), str(run)) - behavior_headers, phenotype_headers = build_headers(path) + for env in environments: + + for run in range(1, runs+1): + + + path1 = dirpath + str(exp) + '_' + str(run) + '/data_fullevolution/' + env + path2 = dirpath + str(exp) + '_' + str(run) + '/selectedpop_' + env + + behavior_headers, phenotype_headers = build_headers(path1, path2) + + file_summary = open(path1 + "/all_measures.tsv", "a") + for r, d, f in os.walk(path1+'/fitness'): + for file in f: - file_summary = open(path + "/all_measures.tsv", "a") - for r, d, f in os.walk(path+'/data_fullevolution/fitness'): - for file in f: + robot_id = file.split('.')[0].split('_')[-1] + file_summary.write(robot_id+'\t') - robot_id = file.split('.')[0].split('_')[-1] - file_summary.write(robot_id+'\t') + bh_file = path1+'/descriptors/behavior_desc_robot_'+robot_id+'.txt' + if os.path.isfile(bh_file): + with open(bh_file) as file: + for line in file: + if line != 'None': + measure, value = line.strip().split(' ') + file_summary.write(value+'\t') + else: + for h in behavior_headers: + file_summary.write('None'+'\t') + else: + for h in behavior_headers: + file_summary.write('None'+'\t') - bh_file = path+'/data_fullevolution/descriptors/behavior_desc_robot_'+robot_id+'.txt' - if os.path.isfile(bh_file): - with open(bh_file) as file: - for line in file: - if line != 'None': + pt_file = path1+'/descriptors/phenotype_desc_robot_'+robot_id+'.txt' + if os.path.isfile(pt_file): + with open(pt_file) as file: + for line in file: measure, value = line.strip().split(' ') file_summary.write(value+'\t') - else: - for h in behavior_headers: - file_summary.write('None'+'\t') - else: - for h in behavior_headers: - file_summary.write('None'+'\t') - - pt_file = path+'/data_fullevolution/descriptors/phenotype_desc_robot_'+robot_id+'.txt' - if os.path.isfile(pt_file): - with open(pt_file) as file: - for line in file: - measure, value = line.strip().split(' ') - file_summary.write(value+'\t') - else: - for h in phenotype_headers: - file_summary.write('None'+'\t') - - file = open(path+'/data_fullevolution/fitness/fitness_robot_'+robot_id+'.txt', 'r') - fitness = file.read() - file_summary.write(fitness + '\n') - file_summary.close() - - file_summary = open(path + "/snapshots_ids.tsv", "a") - for r, d, f in os.walk(path): - for dir in d: - if 'selectedpop' in dir: - gen = dir.split('_')[1] - for r2, d2, f2 in os.walk(path + '/selectedpop_' + str(gen)): - for file in f2: - if 'body' in file: - id = file.split('.')[0].split('_')[-1] - file_summary.write(gen+'\t'+id+'\n') - file_summary.close() \ No newline at end of file + else: + for h in phenotype_headers: + file_summary.write('None'+'\t') + + file = open(path1+'/fitness/fitness_robot_'+robot_id+'.txt', 'r') + fitness = file.read() + file_summary.write(fitness + '\n') + file_summary.close() + print(exp, run, len(f), round(((len(f)-100)/50),0)+1) + + file_summary = open(path2 + "/snapshots_ids.tsv", "a") + for r, d, f in os.walk(path2): + for dir in d: + if 'selectedpop' in dir: + gen = dir.split('_')[1] + for r2, d2, f2 in os.walk(path2 + '/selectedpop_' + str(gen)): + for file in f2: + if 'body' in file: + id = file.split('.')[0].split('_')[-1] + file_summary.write(gen+'\t'+id+'\n') + file_summary.close() From 05825c1113bbf8046c52c15e9ef3c16d3a787c95 Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 10 Jan 2020 19:07:24 +0100 Subject: [PATCH 28/45] analysis --- .../karines_experiments/summary_measures.R | 529 ++++++++++++++++++ 1 file changed, 529 insertions(+) create mode 100644 experiments/karines_experiments/summary_measures.R diff --git a/experiments/karines_experiments/summary_measures.R b/experiments/karines_experiments/summary_measures.R new file mode 100644 index 0000000000..8f5b947137 --- /dev/null +++ b/experiments/karines_experiments/summary_measures.R @@ -0,0 +1,529 @@ + library(ggplot2) + library(sqldf) + library(plyr) + library(dplyr) + library(trend) + library(purrr) + library(ggsignif) + + base_directory <-paste('data', sep='') + +analysis = 'analysis' + +output_directory = paste(base_directory,'/',analysis ,sep='') + +#### CHANGE THE PARAMETERS HERE #### + + +experiments_type = c( 'baseline','plastic') + +environments = c( 'plane','tilted5') + +methods = c() +for (exp in 1:length(experiments_type)) +{ + for (env in 1:length(environments)) + { + methods = c(methods, paste(experiments_type[exp], environments[env], sep='_')) + } +} + +initials = c( 'bp', 'bt', 'pp', 'pt') + +experiments_labels = c( 'Baseline: Flat', 'Baseline: Tilted', + 'Plastic: Flat', 'Plastic: Tilted') + +experiments_labels2 = c( 'Baseline', 'Baseline', + 'Plastic: Flat', 'Plastic: Tilted') + + runs = c(1:30) + gens = 100 + pop = 100 + + #### CHANGE THE PARAMETERS HERE #### + + sig = 0.05 + line_size = 30 + show_markers = TRUE#FALSE + show_legends = FALSE + experiments_type_colors = c( '#00e700' , '#009900', '#ffb83b', '#fd8a3b') # DARK: light green,dark green, light red, dark red + + measures_names = c( + 'displacement_velocity_hill', + 'head_balance', + 'contacts', + 'displacement_velocity', + 'branching', + 'branching_modules_count', + 'limbs', + 'extremities', + 'length_of_limbs', + 'extensiveness', + 'coverage', + 'joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'proportion', + 'width', + 'height', + 'absolute_size', + 'sensors', + 'symmetry', + 'avg_period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'fitness' + ) + + # add proper labels soon... + measures_labels = c( + 'Speed (cm/s)', + 'Balance', + 'Contacts', + 'displacement_velocity', + 'Branching', + 'branching_modules_count', + 'Rel number of limbs', + 'extremities', + 'Rel. Length of Limbs', + 'extensiveness', + 'coverage', + 'Rel. Number of Joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'Proportion', + 'width', + 'height', + 'Size', + 'sensors', + 'Symmetry', + 'Average Period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'Fitness' + ) + + + measures_snapshots_all = NULL + + for (exp in 1:length(experiments_type)) + { + for(run in runs) + { + for (env in 1:length(environments)) + { + input_directory <- paste(base_directory, '/', + experiments_type[exp], '_',sep='') + + measures = read.table(paste(input_directory, run, '/data_fullevolution/', + environments[env], "/all_measures.tsv", sep=''), header = TRUE) + for( m in 1:length(measures_names)) + { + measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) + } + + snapshots = read.table(paste(input_directory, run,'/selectedpop_', + environments[env],"/snapshots_ids.tsv", sep=''), header = TRUE) + + measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') + + measures_snapshots$run = run + measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 + measures_snapshots$run = as.factor(measures_snapshots$run) + measures_snapshots$method = paste(experiments_type[exp], environments[env],sep='_') + + if ( is.null(measures_snapshots_all)){ + measures_snapshots_all = measures_snapshots + }else{ + measures_snapshots_all = rbind(measures_snapshots_all, measures_snapshots) + } + } + } + } + + + fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) + + + measures_snapshots_all = sqldf("select * from measures_snapshots_all where fitness IS NOT NULL") + + + + measures_averages_gens_1 = list() + measures_averages_gens_2 = list() + + measures_ini = list() + measures_fin = list() + + for (met in 1:length(methods)) + { + + measures_aux = c() + query ='select run, generation' + for (i in 1:length(measures_names)) + { + query = paste(query,', avg(',measures_names[i],') as ', methods[met], '_',measures_names[i],'_avg', sep='') + } + query = paste(query,' from measures_snapshots_all + where method="', methods[met],'" group by run, generation', sep='') + + + measures_averages_gens_1[[met]] = sqldf(query) + + temp = measures_averages_gens_1[[met]] + + temp$generation = as.numeric(temp$generation) + + measures_ini[[met]] = sqldf(paste("select * from temp where generation=0")) + measures_fin[[met]] = sqldf(paste("select * from temp where generation=",gens-1)) + query = 'select generation' + for (i in 1:length(measures_names)) + { + # later renames vars _avg_SUMMARY, just to make it in the same style as the quantile variables + query = paste(query,', avg(', methods[met], '_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_avg', sep='') + query = paste(query,', max(', methods[met],'_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_max', sep='') + query = paste(query,', stdev(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_stdev', sep='') + query = paste(query,', median(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_median', sep='') + + measures_aux = c(measures_aux, paste(methods[met],'_',measures_names[i],'_avg', sep='') ) + } + query = paste(query,' from temp group by generation', sep="") + + temp2 = sqldf(query) + + p <- c(0.25, 0.75) + p_names <- map_chr(p, ~paste0('Q',.x*100, sep="")) + p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>% + set_names(nm = p_names) + + quantiles = data.frame(temp %>% + group_by(generation) %>% + summarize_at(vars(measures_aux), funs(!!!p_funs)) ) + + measures_averages_gens_2[[met]] = sqldf('select * from temp2 inner join quantiles using (generation)') + + } + + + for (met in 1:length(methods)) + { + if(met==1){ + measures_averages_gens = measures_averages_gens_2[[1]] + }else{ + measures_averages_gens = merge(measures_averages_gens, measures_averages_gens_2[[met]], by = "generation") + } + } + + file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") + + #tests trends in curves and difference between ini and fin generations + + + # ini VS fin + array_wilcoxon = list() + array_wilcoxon2 = list() + + # curve + array_mann = list() + + + for (m in 1:length(methods)) + { + + array_wilcoxon[[m]] = list() + array_mann[[m]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(experiments_type[m],measures_names[i],'ini avg ',as.character( + mean(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon[[m]][[i]] = wilcox.test(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'iniVSfin',measures_names[i],'wilcox p: ',as.character(round(array_wilcoxon[[m]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'iniVSfin',measures_names[i],'wilcox est: ',as.character(round(array_wilcoxon[[m]][[i]]$statistic,4)), sep=' ') + + ), file) + + + #tests trends + array_mann[[m]][[i]] = mk.test(c(array(measures_averages_gens_2[[m]][paste(methods[m],"_",measures_names[i],'_median',sep='')]) )[[1]], + continuity = TRUE) + + + writeLines(c( + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median p', as.character(round(array_mann[[m]][[i]]$p.value,4)),sep=' '), + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median s', as.character(round(array_mann[[m]][[i]]$statistic,4)),sep=' ') + ), file) + + } + + } + + + + # tests final generation among experiments_type + + aux_m = length(methods) + + if (aux_m>1) + { + + # fins + array_wilcoxon2[[1]] = list() + array_wilcoxon2[[2]] = list() + + aux_m = aux_m -1 + count_pairs = 0 + for(m in 1:aux_m) + { + aux = m+1 + for(m2 in aux:length(methods)) + { + + count_pairs = count_pairs+1 + array_wilcoxon2[[1]][[count_pairs]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + writeLines(paste(methods[m2],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon2[[1]][[count_pairs]][[i]] = wilcox.test(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'VS',methods,measures_names[i],'fin avg wilcox p: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'VS',methods[m2],measures_names[i],'fin avg wilcox est: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$statistic,4)), sep=' ') + + ), file) + + } + + + array_wilcoxon2[[2]][[count_pairs]] = paste(initials[m],initials[m2],sep='') + + } + } + + } + + close(file) + + # plots measures + + for (type_summary in c('means','quants')) + { + + + for (i in 1:length(measures_names)) + { + tests1 = '' + tests2 = '' + tests3 = '' + break_aux = 0 + + graph <- ggplot(data=measures_averages_gens, aes(x=generation)) + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg','-',methods[m],'_',measures_names[i],'_stdev',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg','+',methods[m],'_',measures_names[i],'_stdev',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + }else + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg_Q25',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg_Q75',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + } + } + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) + } + + }else{ + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') , colour=shQuote(experiments_labels[m]) ),size=2 ) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') ),size=2, color = experiments_type_colors[m] ) + } + } + + if (length(array_mann)>0) + { + if (length(array_mann[[m]])>0) + { + if(!is.na(array_mann[[m]][[i]]$p.value)) + { + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } + } + } + } + } + + if (length(array_wilcoxon[[m]])>0) + { + for(m in 1:length(methods)) + { + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + { + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } + } + } + } + + if (length(array_wilcoxon2)>0) + { + for(p in 1:length(array_wilcoxon2[[1]])) + { + if (length(array_wilcoxon2[[1]][[p]])>0) + { + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + { + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') + } + } + } + } + } + + max_y = 0 + if(measures_names[i]=='proportion' || measures_names[i]=='balance' || measures_names[i]=='joints' ){ max_y = 1.1 } + if(measures_names[i]=='limbs' ){ max_y = 0.85 } + if(measures_names[i]=='absolute_size' ){ max_y = 17 } + if(measures_names[i]=='displacement_velocity_hill' ){ max_y = 4 } + + graph = graph + labs( y=measures_labels[i], x="Generation") + if (max_y>0) { + graph = graph + coord_cartesian(ylim = c(0, max_y)) + } + + if(show_markers == TRUE){ + graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) + } + graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=30),axis.title=element_text(size=39), + plot.subtitle=element_text(size=25 )) + + ggsave(paste( output_directory,'/',type_summary,'_' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 10, width = 10) + } + + } + + + + + for (i in 1:length(measures_names)) + { + + all_final_values = data.frame() + if (measures_names[i] == 'displacement_velocity_hill') { ini=1 } + else{ ini=2 } + + for (exp in ini:length(methods)) + { + temp = data.frame( c(measures_fin[[exp]][paste(methods[exp],'_',measures_names[i],'_avg', sep='')])) + colnames(temp) <- 'values' + if (measures_names[i] == 'displacement_velocity_hill') { temp$type = experiments_labels[exp] + }else{ temp$type = experiments_labels2[exp] } + + all_final_values = rbind(all_final_values, temp) + } + + + max_y = 0 + if(measures_names[i]=='proportion' || measures_names[i]=='head_balance' || measures_names[i]=='joints' ){ max_y = 1.1 } + if(measures_names[i]=='limbs' ){ max_y = 0.85 } + if(measures_names[i]=='absolute_size' ){ max_y = 17 } + if(measures_names[i]=='displacement_velocity_hill' ){ max_y = 4 } + + g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4, notch=TRUE) + + labs( x="Environment", y=measures_labels[i], title="Final generation") + + if (measures_names[i] == 'displacement_velocity_hill') { g1 = g1 + scale_color_manual(values=experiments_type_colors) + }else{ g1 = g1 + scale_color_manual(values=experiments_type_colors[-1]) } + + g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , + plot.title=element_text(size=40), axis.text=element_text(size=45), + axis.title=element_text(size=50), + axis.text.x = element_text(angle = 20, hjust = 1))+ + stat_summary(fun.y = mean, geom="point" ,shape = 16, size=11) + + if (measures_names[i] == 'displacement_velocity_hill') { comps = list(c("Baseline: Flat", "Plastic: Flat"), + c("Baseline: Tilted", "Plastic: Tilted")) + }else{ comps = list(c("Baseline", "Plastic: Flat"), + c("Baseline", "Plastic: Tilted"), + c("Plastic: Flat", "Plastic: Tilted")) } + + + g1 = g1 + geom_signif( test="wilcox.test", size=2, textsize=22, + comparisons = comps, + map_signif_level=c("***"=0.001,"**"=0.01, "*"=0.05) ) + if (max_y>0) { + g1 = g1 + coord_cartesian(ylim = c(0, max_y)) + } + + ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = 10) + + } From 3891141ffe1c80b117ecf85265eeb797a59d9061 Mon Sep 17 00:00:00 2001 From: Karine Date: Wed, 15 Jan 2020 15:04:24 +0100 Subject: [PATCH 29/45] fix bug recovery + new pareto fronts --- experiments/karines_experiments/baseline.py | 2 + experiments/karines_experiments/baseline2.py | 152 +++++++++++++++++ experiments/karines_experiments/baseline3.py | 152 +++++++++++++++++ .../bestrobots_summary_renders.r | 103 ++++++------ .../consolidate_experiments.py | 35 ++-- experiments/karines_experiments/plastic.py | 5 +- experiments/karines_experiments/plastic2.py | 153 ++++++++++++++++++ experiments/karines_experiments/plastic3.py | 153 ++++++++++++++++++ .../karines_experiments/run-experiments | 82 +++++++++- .../karines_experiments/summary_measures.R | 39 ++--- pyrevolve/evolution/population.py | 28 +++- pyrevolve/experiment_management.py | 13 +- 12 files changed, 823 insertions(+), 94 deletions(-) create mode 100755 experiments/karines_experiments/baseline2.py create mode 100755 experiments/karines_experiments/baseline3.py create mode 100755 experiments/karines_experiments/plastic2.py create mode 100755 experiments/karines_experiments/plastic3.py diff --git a/experiments/karines_experiments/baseline.py b/experiments/karines_experiments/baseline.py index f1a4a4bdcd..6367c7862a 100755 --- a/experiments/karines_experiments/baseline.py +++ b/experiments/karines_experiments/baseline.py @@ -28,6 +28,7 @@ async def run(): num_generations = 100 population_size = 100 offspring_size = 50 + front = 'slaves' # environment world and z-start environments = {'plane': 0.03, @@ -90,6 +91,7 @@ def fitness_function(robot_manager, robot): experiment_name=settings.experiment_name, experiment_management=experiment_management, environments=environments, + front=front ) settings = parser.parse_args() diff --git a/experiments/karines_experiments/baseline2.py b/experiments/karines_experiments/baseline2.py new file mode 100755 index 0000000000..346ac36b32 --- /dev/null +++ b/experiments/karines_experiments/baseline2.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + front = 'total_slaves' + + # environment world and z-start + environments = {'plane': 0.03, + 'tilted5': 0.1 + } + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=False, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function(robot_manager, robot): + #contacts = measures.contacts(robot_manager, robot) + #assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/karines_experiments/baseline3.py b/experiments/karines_experiments/baseline3.py new file mode 100755 index 0000000000..0466cdc4c4 --- /dev/null +++ b/experiments/karines_experiments/baseline3.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + front = 'masters' + + # environment world and z-start + environments = {'plane': 0.03, + 'tilted5': 0.1 + } + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=False, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function(robot_manager, robot): + #contacts = measures.contacts(robot_manager, robot) + #assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/karines_experiments/bestrobots_summary_renders.r b/experiments/karines_experiments/bestrobots_summary_renders.r index 40ee0ea3c3..335af366b1 100644 --- a/experiments/karines_experiments/bestrobots_summary_renders.r +++ b/experiments/karines_experiments/bestrobots_summary_renders.r @@ -1,34 +1,20 @@ -#library(ggplot2) -#library(dplyr) -#library(viridis) -#ibrary(Interpol.T) -#library(lubridate) -#library(ggExtra) -#library(tidyr) -#library(trend) -#library(poweRlaw) -#library(plyr) + library(sqldf) require('magick') ##### change paths/labels/params here ##### -paths = c( - 'plane', - 'lava', - 'lavacost', - 'lavacostold', - 'lavaold' -) +paths = c( 'baseline','plastic') +environments = c( 'plane','tilted5') -base_directory <- paste('projects/revolve/experiments/karines_experiments/data/', sep='') +base_directory <- paste('data/', sep='') experiments = 30 gens = 100 pop = 100 -num_top = 3 +num_top = 1 analysis = 'images' @@ -42,51 +28,54 @@ file <-file(paste(output_directory,'/best.txt',sep=''), open="w") # for each method for(m in 1:length(paths)) { - - # for each repetition - for (exp in 1:experiments) - { - - input_directory <- paste(base_directory, paths[m],'_',exp,sep='') - - ids_gens = data.frame() - list = strsplit(list.files(paste(input_directory, '/selectedpop_',gens-1, sep='')), ' ') - for(geno in 1:pop) + # for each repetition + for (exp in 1:experiments) { - genome = data.frame(cbind(c(gens), c(strsplit(strsplit(list [[geno]],'_')[[1]][3],'.png')[[1]][1] ))) - names(genome)<-c('generation','robot_id') - ids_gens = rbind(ids_gens,genome) - } - measures = read.table(paste(input_directory,"/all_measures.tsv", sep=''), header = TRUE) - bests = sqldf(paste("select robot_id, fitness from measures inner join ids_gens using (robot_id) order by fitness desc limit",num_top)) - - for(b in 1:nrow(bests)) - { + input_directory1 <- paste(base_directory, paths[m],'_',exp, '/data_fullevolution/',environments[1],sep='') + input_directory2 <- paste(base_directory, paths[m],'_',exp, '/selectedpop_', sep='') - writeLines( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'fitness'] ), file ) - - phenotype= bests[b,'robot_id'] - - patha = paste(base_directory,paths[m],'_',exp,"/selectedpop_",gens-1,sep="") - - body <- list.files(patha, paste("body_robot_",phenotype,".png$",sep=""), full.names = TRUE) - body = image_read(body) - body = image_scale(body, "100x100") - body = image_border(image_background(body, "white"), "white", "5x5") - + ids_gens = data.frame() + list = strsplit(list.files(paste(input_directory2, environments[1],'/selectedpop_',gens-1, sep='')), ' ') + for(geno in 1:pop) + { + genome = data.frame(cbind(c(gens), c(strsplit(strsplit(list [[geno]],'_')[[1]][3],'.png')[[1]][1] ))) + names(genome)<-c('generation','robot_id') + ids_gens = rbind(ids_gens,genome) + } - if(b == 1) + measures = read.table(paste(input_directory1,"/all_measures.tsv", sep=''), header = TRUE) + bests = sqldf(paste("select robot_id, cons_fitness from measures inner join ids_gens using (robot_id) order by cons_fitness desc limit",num_top)) + + for(b in 1:nrow(bests)) { - bodies = body - }else{ - bodies = c(bodies, body) + + writeLines( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] ), file ) + print( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] )) + + phenotype= bests[b,'robot_id'] + + for (env in 1:length(environments)) + { + patha = paste(input_directory2, environments[env], "/selectedpop_",gens-1,sep="") + + body <- list.files(patha, paste("body_robot_",phenotype,".png$",sep=""), full.names = TRUE) + body = image_read(body) + body = image_scale(body, "100x100") + body = image_border(image_background(body, "white"), "white", "5x5") + + if(b == 1 && env == 1) + { + bodies = body + }else{ + bodies = c(bodies, body) + } + } } - } + + side_by_side = image_append(bodies, stack=F) + image_write(side_by_side, path = paste(output_directory,"/",paths[m],'_', environments[env], "_bodies_best_",exp,".png",sep=''), format = "png") - side_by_side = image_append(bodies, stack=F) - image_write(side_by_side, path = paste(output_directory,"/",methods[m],"_bodies_best_",exp,".png",sep=''), format = "png") - } } diff --git a/experiments/karines_experiments/consolidate_experiments.py b/experiments/karines_experiments/consolidate_experiments.py index 50b3ecab99..ddc9ba4937 100644 --- a/experiments/karines_experiments/consolidate_experiments.py +++ b/experiments/karines_experiments/consolidate_experiments.py @@ -4,14 +4,14 @@ # set these variables according to your experiments # dirpath = 'data/' experiments_type = [ - 'baseline', - 'plastic' + #'baseline', + 'plastic3' ] environments = [ 'plane', 'tilted5' ] -runs = 30 +runs = 10#30 # set these variables according to your experiments # @@ -44,7 +44,7 @@ def build_headers(path1, path2): measure, value = line.strip().split(' ') phenotype_headers.append(measure) file_summary.write(measure+'\t') - file_summary.write('fitness\n') + file_summary.write('fitness\t cons_fitness\n') file_summary.close() file_summary = open(path2 + "/snapshots_ids.tsv", "w+") @@ -59,14 +59,14 @@ def build_headers(path1, path2): for run in range(1, runs+1): - + path0 = dirpath + str(exp) + '_' + str(run) + '/data_fullevolution' path1 = dirpath + str(exp) + '_' + str(run) + '/data_fullevolution/' + env path2 = dirpath + str(exp) + '_' + str(run) + '/selectedpop_' + env behavior_headers, phenotype_headers = build_headers(path1, path2) file_summary = open(path1 + "/all_measures.tsv", "a") - for r, d, f in os.walk(path1+'/fitness'): + for r, d, f in os.walk(path0+'/consolidated_fitness'): for file in f: robot_id = file.split('.')[0].split('_')[-1] @@ -96,11 +96,25 @@ def build_headers(path1, path2): for h in phenotype_headers: file_summary.write('None'+'\t') - file = open(path1+'/fitness/fitness_robot_'+robot_id+'.txt', 'r') - fitness = file.read() - file_summary.write(fitness + '\n') + f_file = open(path1+'/fitness/fitness_robot_'+robot_id+'.txt', 'r') + fitness = f_file.read() + file_summary.write(fitness + '\t') + + cf_file = open(path0+'/consolidated_fitness/consolidated_fitness_robot_'+robot_id+'.txt', 'r') + cons_fitness = cf_file.read() + file_summary.write(cons_fitness + '\n') + + num_files = len(f) + list_gens = [] + for r, d, f in os.walk(path2): + for dir in d: + if 'selectedpop' in dir: + gen = dir.split('_')[1] + list_gens.append(int(gen)) + list_gens.sort() + print(exp, run, num_files, list_gens[-1], num_files-(list_gens[-1]*50+100)) + file_summary.close() - print(exp, run, len(f), round(((len(f)-100)/50),0)+1) file_summary = open(path2 + "/snapshots_ids.tsv", "a") for r, d, f in os.walk(path2): @@ -112,4 +126,5 @@ def build_headers(path1, path2): if 'body' in file: id = file.split('.')[0].split('_')[-1] file_summary.write(gen+'\t'+id+'\n') + file_summary.close() diff --git a/experiments/karines_experiments/plastic.py b/experiments/karines_experiments/plastic.py index 5f4c47d651..d77169629c 100755 --- a/experiments/karines_experiments/plastic.py +++ b/experiments/karines_experiments/plastic.py @@ -18,6 +18,7 @@ from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue from pyrevolve.custom_logging.logger import logger import sys +import time async def run(): """ @@ -28,6 +29,7 @@ async def run(): num_generations = 100 population_size = 100 offspring_size = 50 + front = 'slaves' # environment world and z-start environments = {'plane': 0.03, @@ -47,7 +49,7 @@ async def run(): crossover_conf = CrossoverConfig( crossover_prob=0.8, ) - # experiment params # + # experiment params #load_individual # Parse command line / file input arguments settings = parser.parse_args() @@ -90,6 +92,7 @@ def fitness_function(robot_manager, robot): experiment_name=settings.experiment_name, experiment_management=experiment_management, environments=environments, + front=front ) settings = parser.parse_args() diff --git a/experiments/karines_experiments/plastic2.py b/experiments/karines_experiments/plastic2.py new file mode 100755 index 0000000000..5289307500 --- /dev/null +++ b/experiments/karines_experiments/plastic2.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys +import time + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + front = 'total_slaves' + + # environment world and z-start + environments = {'plane': 0.03, + 'tilted5': 0.1 + } + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=True, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function(robot_manager, robot): + #contacts = measures.contacts(robot_manager, robot) + #assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/karines_experiments/plastic3.py b/experiments/karines_experiments/plastic3.py new file mode 100755 index 0000000000..3ea5de279f --- /dev/null +++ b/experiments/karines_experiments/plastic3.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys +import time + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + front = 'masters' + + # environment world and z-start + environments = {'plane': 0.03, + 'tilted5': 0.1 + } + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=True, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function(robot_manager, robot): + #contacts = measures.contacts(robot_manager, robot) + #assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index 7ba3bf6e3e..e5552b2b35 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -61,10 +61,90 @@ done while true do - sleep 900s; + sleep 1800s; kill $( ps aux | grep 'gzserver' | awk '{print $2}'); kill $( ps aux | grep 'revolve.py' | awk '{print $2}'); sleep 60s; done + + +while true + do + for i in {1..5}; do + ./revolve.py --experiment-name karines_experiments/data/plastic2_$i --run $i --manager experiments/karines_experiments/plastic2.py --n-cores 4 --port-start 11150 --evaluation-time 50; + + sleep 5s + done +done + +while true + do + for i in {6..10}; do + ./revolve.py --experiment-name karines_experiments/data/plastic2_$i --run $i --manager experiments/karines_experiments/plastic2.py --n-cores 4 --port-start 11120 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {1..5}; do + ./revolve.py --experiment-name karines_experiments/data/plastic3_$i --run $i --manager experiments/karines_experiments/plastic3.py --n-cores 4 --port-start 12150 --evaluation-time 50; + + sleep 5s + done +done + +while true + do + for i in {6..10}; do + ./revolve.py --experiment-name karines_experiments/data/plastic3_$i --run $i --manager experiments/karines_experiments/plastic3.py --n-cores 4 --port-start 12250 --evaluation-time 50; + + sleep 5s + done +done + + + +while true + do + for i in {1..5}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 12050 --evaluation-time 50; + + sleep 5s + done +done + +while true + do + for i in {6..10}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 9870 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {1..5}; do + ./revolve.py --experiment-name karines_experiments/data/baseline3_$i --run $i --manager experiments/karines_experiments/baseline3.py --n-cores 4 --port-start 9890 --evaluation-time 50; + + sleep 5s + done +done + +while true + do + for i in {6..10}; do + ./revolve.py --experiment-name karines_experiments/data/baseline3_$i --run $i --manager experiments/karines_experiments/baseline3.py --n-cores 4 --port-start 7870 --evaluation-time 50; + + sleep 5s + done +done + + + diff --git a/experiments/karines_experiments/summary_measures.R b/experiments/karines_experiments/summary_measures.R index 8f5b947137..f5387f884e 100644 --- a/experiments/karines_experiments/summary_measures.R +++ b/experiments/karines_experiments/summary_measures.R @@ -8,14 +8,14 @@ base_directory <-paste('data', sep='') -analysis = 'analysis' +analysis = 'analysis1' output_directory = paste(base_directory,'/',analysis ,sep='') #### CHANGE THE PARAMETERS HERE #### -experiments_type = c( 'baseline','plastic') +experiments_type = c( 'baseline','plastic') environments = c( 'plane','tilted5') @@ -36,8 +36,12 @@ experiments_labels = c( 'Baseline: Flat', 'Baseline: Tilted', experiments_labels2 = c( 'Baseline', 'Baseline', 'Plastic: Flat', 'Plastic: Tilted') - runs = c(1:30) - gens = 100 + #runs = c(1:30) + runs = list( c(21:30), + c(21:30)) + #runs = list( c(12, 16, 15, 17, 21, 22, 23, 26, 27, 29), + # c(11, 13, 15, 16, 19, 20 ,24, 25, 26, 28)) + gens = 50#100 pop = 100 #### CHANGE THE PARAMETERS HERE #### @@ -83,7 +87,8 @@ experiments_labels2 = c( 'Baseline', 'Baseline', 'sensors_reach', 'recurrence', 'synaptic_reception', - 'fitness' + 'fitness', + 'cons_fitness' ) # add proper labels soon... @@ -122,7 +127,8 @@ experiments_labels2 = c( 'Baseline', 'Baseline', 'sensors_reach', 'recurrence', 'synaptic_reception', - 'Fitness' + 'Fitness', + 'Number of slaves' ) @@ -130,7 +136,8 @@ experiments_labels2 = c( 'Baseline', 'Baseline', for (exp in 1:length(experiments_type)) { - for(run in runs) + #for(run in runs) + for(run in runs[[exp]]) { for (env in 1:length(environments)) { @@ -167,7 +174,7 @@ experiments_labels2 = c( 'Baseline', 'Baseline', fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) - measures_snapshots_all = sqldf("select * from measures_snapshots_all where fitness IS NOT NULL") + measures_snapshots_all = sqldf("select * from measures_snapshots_all where cons_fitness IS NOT NULL") @@ -449,11 +456,8 @@ experiments_labels2 = c( 'Baseline', 'Baseline', } max_y = 0 - if(measures_names[i]=='proportion' || measures_names[i]=='balance' || measures_names[i]=='joints' ){ max_y = 1.1 } - if(measures_names[i]=='limbs' ){ max_y = 0.85 } - if(measures_names[i]=='absolute_size' ){ max_y = 17 } - if(measures_names[i]=='displacement_velocity_hill' ){ max_y = 4 } - + #if(measures_names[i]=='proportion' || measures_names[i]=='balance' || measures_names[i]=='joints' ){ max_y = 1.1 } + graph = graph + labs( y=measures_labels[i], x="Generation") if (max_y>0) { graph = graph + coord_cartesian(ylim = c(0, max_y)) @@ -492,11 +496,8 @@ experiments_labels2 = c( 'Baseline', 'Baseline', max_y = 0 - if(measures_names[i]=='proportion' || measures_names[i]=='head_balance' || measures_names[i]=='joints' ){ max_y = 1.1 } - if(measures_names[i]=='limbs' ){ max_y = 0.85 } - if(measures_names[i]=='absolute_size' ){ max_y = 17 } - if(measures_names[i]=='displacement_velocity_hill' ){ max_y = 4 } - + # if(measures_names[i]=='proportion' || measures_names[i]=='head_balance' || measures_names[i]=='joints' ){ max_y = 1.1 } + g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4, notch=TRUE) + labs( x="Environment", y=measures_labels[i], title="Final generation") @@ -527,3 +528,5 @@ experiments_labels2 = c( 'Baseline', 'Baseline', ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = 10) } + + \ No newline at end of file diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index a08c5bd935..7961a3a7e6 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -30,6 +30,7 @@ def __init__(self, experiment_name, experiment_management, environments, + front, offspring_size=None, next_robot_id=1): """ @@ -66,6 +67,7 @@ def __init__(self, self.experiment_name = experiment_name self.experiment_management = experiment_management self.environments = environments + self.front = front self.offspring_size = offspring_size self.next_robot_id = next_robot_id @@ -167,10 +169,16 @@ async def consolidate_fitness(self, individuals): # if there are multiple seasons (environments) else: for individual_ref in individuals: + slaves = 0 + total_slaves = 0 + masters = 0 + for individual_comp in individuals: + equal = 0 better = 0 + for environment in self.conf.environments: if individual_ref[environment].fitness is None \ and individual_comp[environment].fitness is None: @@ -200,7 +208,25 @@ async def consolidate_fitness(self, individuals): if equal >= 0 and better > 0: slaves += 1 - individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = slaves + # if better in all objectives + if better == len(self.conf.environments): + total_slaves += 1 + + # if it is worse + if equal < 0 and better == 0: + masters += 1 + + if self.conf.front == 'slaves': + individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = slaves + + if self.conf.front == 'total_slaves': + individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = total_slaves + + if self.conf.front == 'masters': + if masters == 0: + individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = 0 + else: + individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = 1/masters for individual in individuals: self.conf.experiment_management.export_consolidated_fitness( diff --git a/pyrevolve/experiment_management.py b/pyrevolve/experiment_management.py index 788da68179..dca4305370 100644 --- a/pyrevolve/experiment_management.py +++ b/pyrevolve/experiment_management.py @@ -122,12 +122,13 @@ def read_recovery_state(self, population_size, offspring_size): last_snapshot = -1 n_robots = 0 - # if a robot is developed in any of the environments, then it exists + # if a robot is developed in the last environment robot_ids = [] - for environment in self.environments: - for r, d, f in os.walk(os.path.join(self._data_folder()+'/'+environment, 'individuals')): - for file in f: - robot_ids.append(int(file.split('.')[0].split('_')[-1])) + last_id = 0 + environment = list(self.environments.keys())[-1] + for r, d, f in os.walk(os.path.join(self._data_folder()+'/'+environment, 'individuals')): + for file in f: + robot_ids.append(int(file.split('.')[0].split('_')[-1])) last_id = np.sort(robot_ids)[-1] # if there are more robots to recover than the number expected in this snapshot @@ -137,4 +138,4 @@ def read_recovery_state(self, population_size, offspring_size): else: has_offspring = False - return last_snapshot, has_offspring, last_id+1 \ No newline at end of file + return last_snapshot, has_offspring, last_id+1 From b13df9efd8df223e6ea2431c3bc0d9935ad3b05a Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 17 Jan 2020 18:31:27 +0100 Subject: [PATCH 30/45] fix gub time + plots --- .../karines_experiments/baseline_big.py | 152 ++++++++++++++++++ .../consolidate_experiments.py | 9 +- experiments/karines_experiments/scatter.R | 72 +++++++++ experiments/karines_experiments/scatter2.R | 80 +++++++++ .../karines_experiments/summary_measures.R | 2 +- .../{watch_best_robots.py => watch_best.py} | 91 ++++++++--- pyrevolve/evolution/population.py | 15 +- pyrevolve/tol/manage/robotmanager.py | 5 +- 8 files changed, 397 insertions(+), 29 deletions(-) create mode 100755 experiments/karines_experiments/baseline_big.py create mode 100644 experiments/karines_experiments/scatter.R create mode 100644 experiments/karines_experiments/scatter2.R rename experiments/karines_experiments/{watch_best_robots.py => watch_best.py} (51%) diff --git a/experiments/karines_experiments/baseline_big.py b/experiments/karines_experiments/baseline_big.py new file mode 100755 index 0000000000..84d75f6e7e --- /dev/null +++ b/experiments/karines_experiments/baseline_big.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 100 + front = 'slaves' + + # environment world and z-start + environments = {'plane': 0.03, + 'tilted5': 0.1 + } + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=False, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function(robot_manager, robot): + #contacts = measures.contacts(robot_manager, robot) + #assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/karines_experiments/consolidate_experiments.py b/experiments/karines_experiments/consolidate_experiments.py index ddc9ba4937..d267c49268 100644 --- a/experiments/karines_experiments/consolidate_experiments.py +++ b/experiments/karines_experiments/consolidate_experiments.py @@ -57,7 +57,7 @@ def build_headers(path1, path2): for env in environments: - for run in range(1, runs+1): + for run in runs: path0 = dirpath + str(exp) + '_' + str(run) + '/data_fullevolution' path1 = dirpath + str(exp) + '_' + str(run) + '/data_fullevolution/' + env @@ -112,7 +112,11 @@ def build_headers(path1, path2): gen = dir.split('_')[1] list_gens.append(int(gen)) list_gens.sort() - print(exp, run, num_files, list_gens[-1], num_files-(list_gens[-1]*50+100)) + if len(list_gens)>0: + gen = list_gens[-1] + else: + gen = -1 + print(exp, run, num_files, gen, num_files-(gen*50+100)) file_summary.close() @@ -128,3 +132,4 @@ def build_headers(path1, path2): file_summary.write(gen+'\t'+id+'\n') file_summary.close() + diff --git a/experiments/karines_experiments/scatter.R b/experiments/karines_experiments/scatter.R new file mode 100644 index 0000000000..5a3fb8deda --- /dev/null +++ b/experiments/karines_experiments/scatter.R @@ -0,0 +1,72 @@ + +library(ggplot2) +library(sqldf) + +base_directory <-paste('data', sep='') + +analysis = 'analysis1' + +output_directory = paste(base_directory,'/',analysis ,sep='') + +experiments_type = c( 'baseline','plastic') + +labels_type = c( 'Baseline','Plastic') + +environments = c( 'plane','tilted5') + +labels = c('Speed (cm/s) in Flat', 'Speed (cm/s) in Tilted') + + +runs = list( c(21:30), + c(21:30)) + + + +measures_all = NULL + +for (exp in 1:length(experiments_type)) +{ + for(run in runs[[exp]]) + { + measures_envs = NULL + for (env in 1:length(environments)) + { + input_directory <- paste(base_directory, '/', + experiments_type[exp], '_',sep='') + + measures = read.table(paste(input_directory, run, '/data_fullevolution/', + environments[env], "/all_measures.tsv", sep=''), header = TRUE) + measures = sqldf('select robot_id, displacement_velocity_hill from measures') + measures[paste('speed_',environments[env],sep='')] = as.numeric(as.character(measures[['displacement_velocity_hill']])) + measures[paste('speed_',environments[env],sep='')] = measures[paste('speed_',environments[env],sep='')] * 100 + measures$run = run + + if(env==1){ + measures_envs = measures + }else{ + measures_envs = merge(measures_envs, measures, by = "robot_id") + } + + } + + if ( is.null(measures_all)){ + measures_all = measures_envs + }else{ + measures_all = rbind(measures_all, measures_envs) + } + } + + + measures_all = sqldf('select * from measures_all order by robot_id ') + + graph = ggplot(measures_all, aes(x=speed_plane, y=speed_tilted5, colour=robot_id))+ + geom_point(alpha=0.5, size=3)+ + labs(subtitle=labels_type[exp], x=labels[1], y=labels[2])+ + coord_cartesian(ylim = c(-5, 5), xlim = c(-5, 5)) + + ggsave(paste( output_directory,'/',experiments_type[exp],'_scatter.pdf', sep=''), graph , device='pdf', height = 10, width = 10) + +} + + + diff --git a/experiments/karines_experiments/scatter2.R b/experiments/karines_experiments/scatter2.R new file mode 100644 index 0000000000..b1164d90ca --- /dev/null +++ b/experiments/karines_experiments/scatter2.R @@ -0,0 +1,80 @@ + +library(ggplot2) +library(sqldf) + +base_directory <-paste('data', sep='') + +analysis = 'analysis3' + +output_directory = paste(base_directory,'/',analysis ,sep='') + +experiments_type = c( 'baseline3','plastic3') + +labels_type = c( 'Baseline','Plastic') + +environments = c( 'plane','tilted5') + +labels = c('Speed (cm/s) in Flat', 'Speed (cm/s) in Tilted') + + +runs = list( c(1:10), + c(1:10)) + + + +measures_all = NULL + +for (exp in 1:length(experiments_type)) +{ + for(run in runs[[exp]]) + { + measures_envs = NULL + for (env in 1:length(environments)) + { + input_directory <- paste(base_directory, '/', + experiments_type[exp], '_',sep='') + + measures = read.table(paste(input_directory, run, '/data_fullevolution/', + environments[env], "/all_measures.tsv", sep=''), header = TRUE) + measures = sqldf('select robot_id, displacement_velocity_hill from measures') + measures[paste('speed_',environments[env],sep='')] = as.numeric(as.character(measures[['displacement_velocity_hill']])) + measures[paste('speed_',environments[env],sep='')] = measures[paste('speed_',environments[env],sep='')] * 100 + measures$run = run + + snapshots = read.table(paste(input_directory, run,'/selectedpop_', + environments[env],"/snapshots_ids.tsv", sep=''), header = TRUE) + + measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') + + #measures_snapshots = sqldf('select * from measures_snapshots where generation in (0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 99)') + measures_snapshots = sqldf('select * from measures_snapshots where generation in (0, 30, 60, 99)') + + if(env==1){ + measures_envs = measures_snapshots + }else{ + measures_envs = merge(measures_envs, measures_snapshots, by = "robot_id") + } + + } + + if ( is.null(measures_all)){ + measures_all = measures_envs + }else{ + measures_all = rbind(measures_all, measures_envs) + } + } + + + measures_all = sqldf('select * from measures_all order by robot_id ') + + graph = ggplot(measures_all, aes(x=speed_plane, y=speed_tilted5, colour=generation.x))+ + geom_point(alpha=0.5, size=3)+ + labs(subtitle=labels_type[exp], x=labels[1], y=labels[2])+ + coord_cartesian(ylim = c(-5, 5), xlim = c(-5, 5)) + + ggsave(paste( output_directory,'/',experiments_type[exp],'_scatter.pdf', sep=''), graph , device='pdf', height = 10, width = 10) + +} + + + diff --git a/experiments/karines_experiments/summary_measures.R b/experiments/karines_experiments/summary_measures.R index f5387f884e..9266108b14 100644 --- a/experiments/karines_experiments/summary_measures.R +++ b/experiments/karines_experiments/summary_measures.R @@ -15,7 +15,7 @@ output_directory = paste(base_directory,'/',analysis ,sep='') #### CHANGE THE PARAMETERS HERE #### -experiments_type = c( 'baseline','plastic') +experiments_type = c( 'baseline','plastic') environments = c( 'plane','tilted5') diff --git a/experiments/karines_experiments/watch_best_robots.py b/experiments/karines_experiments/watch_best.py similarity index 51% rename from experiments/karines_experiments/watch_best_robots.py rename to experiments/karines_experiments/watch_best.py index 3b8b489615..4681cc7c04 100755 --- a/experiments/karines_experiments/watch_best_robots.py +++ b/experiments/karines_experiments/watch_best.py @@ -13,19 +13,33 @@ from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys +import time import numpy as np - async def run(): """ The main coroutine, which is started below. """ - # Parse command line / file input arguments + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + front = 'slaves' + + # environment world and z-start + environments = {'plane': 0.03, + 'tilted5': 0.1 + } genotype_conf = PlasticodingConfig( max_structural_modules=15, + plastic=True, ) mutation_conf = MutationConfig( @@ -36,49 +50,81 @@ async def run(): crossover_conf = CrossoverConfig( crossover_prob=0.8, ) + # experiment params #load_individual + # Parse command line / file input arguments settings = parser.parse_args() - experiment_management = ExperimentManagement(settings) + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + + def fitness_function(robot_manager, robot): + #contacts = measures.contacts(robot_manager, robot) + #assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) population_conf = PopulationConfig( - population_size=100, + population_size=population_size, genotype_constructor=random_initialization, genotype_conf=genotype_conf, - fitness_function=fitness.displacement_velocity_hill, + fitness_function=fitness_function, mutation_operator=standard_mutation, mutation_conf=mutation_conf, crossover_operator=standard_crossover, crossover_conf=crossover_conf, - selection=lambda individuals: tournament_selection(individuals, 2), - parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection), + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), population_management=steady_state_population_management, population_management_selector=tournament_selection, evaluation_time=settings.evaluation_time, - offspring_size=50, + offspring_size=offspring_size, experiment_name=settings.experiment_name, experiment_management=experiment_management, + environments=environments, + front=front ) settings = parser.parse_args() - simulator_queue = SimulatorQueue(settings.n_cores, settings, settings.port_start) - await simulator_queue.start() - # analyzer_queue = AnalyzerQueue(1, settings, settings.port_start+settings.n_cores) - # await analyzer_queue.start() + simulator_queue = {} + analyzer_queue = None - population = Population(population_conf, simulator_queue) + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, 1) # choose a snapshot here. and the maximum best individuals you wish to watch - generation = 99 - max_best = 10 + generation = 61#99 + max_best = 3#10 await population.load_snapshot(generation) values = [] for ind in population.individuals: # define a criteria here - values.append(ind.fitness) - # values.append(ind.phenotype._behavioural_measurements.contacts) - #values.append(ind.phenotype._behavioural_measurements.displacement_velocity_hill) + for environment in environments: + ind[environment].evaluated = False + values.append(ind[list(environments.keys())[-1]].consolidated_fitness) + #values.append(ind['plane'].phenotype._behavioural_measurements.displacement_velocity_hill) + values = np.array(values) ini = len(population.individuals)-max_best @@ -91,7 +137,10 @@ async def run(): #population.individuals = population.individuals[np.argsort(values)[0:max_best]] for ind in population.individuals: - print(ind.phenotype.id) - print('contacts', ind.phenotype._behavioural_measurements.contacts) + print(ind[list(environments.keys())[-1]].phenotype.id) + print('consolidated_fitness', ind[list(environments.keys())[-1]].consolidated_fitness) - await population.evaluate(population.individuals, generation, 'watch') + for environment in environments: + print(environment) + await population.evaluate(new_individuals=population.individuals, gen_num=generation, + environment=environment, type_simulation='watch') diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index 7961a3a7e6..dd499381e1 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -172,8 +172,10 @@ async def consolidate_fitness(self, individuals): slaves = 0 total_slaves = 0 + total_masters = 0 masters = 0 + # this BIZARRE logic works only for two seasons! shame on me! fix it later! for individual_comp in individuals: equal = 0 @@ -212,8 +214,12 @@ async def consolidate_fitness(self, individuals): if better == len(self.conf.environments): total_slaves += 1 - # if it is worse + # if it is totally worse if equal < 0 and better == 0: + total_masters += 1 + + # if it is worse + if equal <= 0 and better == 0: masters += 1 if self.conf.front == 'slaves': @@ -222,6 +228,12 @@ async def consolidate_fitness(self, individuals): if self.conf.front == 'total_slaves': individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = total_slaves + if self.conf.front == 'total_masters': + if total_masters == 0: + individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = 0 + else: + individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = 1/total_masters + if self.conf.front == 'masters': if masters == 0: individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = 0 @@ -324,7 +336,6 @@ async def evaluate(self, new_individuals, gen_num, environment, type_simulation robot_futures = [] to_evaluate = [] for individual in new_individuals: - if not individual[environment].evaluated: logger.info(f'Evaluating individual (gen {gen_num}) {individual[environment].genotype.id} ...') to_evaluate.append(individual) diff --git a/pyrevolve/tol/manage/robotmanager.py b/pyrevolve/tol/manage/robotmanager.py index 78200e0010..703db3ee27 100644 --- a/pyrevolve/tol/manage/robotmanager.py +++ b/pyrevolve/tol/manage/robotmanager.py @@ -30,14 +30,13 @@ def __init__( :param robot: RevolveBot :param position: :type position: Vector3 - :param time: + :param time: time the robot was created :type time: Time :param battery_level: Battery charge for this robot :type battery_level: float :return: """ - time = conf.evaluation_time if time is None else time - speed_window = int(float(time) * conf.pose_update_frequency) + 1 if position_log_size is None \ + speed_window = int(float(conf.evaluation_time) * conf.pose_update_frequency) + 1 if position_log_size is None \ else position_log_size super(RobotManager, self).__init__( robot=robot, From 7830878562fa3e266992e6341769253250159bf7 Mon Sep 17 00:00:00 2001 From: Karine Date: Wed, 22 Jan 2020 18:28:16 +0100 Subject: [PATCH 31/45] run exps --- .../karines_experiments/baseline_big.py | 152 ----------------- .../bestrobots_summary_renders.r | 10 +- .../consolidate_experiments.py | 10 +- .../{baseline.py => flat.py} | 6 +- experiments/karines_experiments/plastic.py | 153 ------------------ experiments/karines_experiments/plastic3.py | 153 ------------------ .../karines_experiments/run-experiments | 84 ++++------ experiments/karines_experiments/scatter2.R | 8 +- .../karines_experiments/summary_measures.R | 20 ++- .../{baseline3.py => tilted.py} | 6 +- 10 files changed, 63 insertions(+), 539 deletions(-) delete mode 100755 experiments/karines_experiments/baseline_big.py rename experiments/karines_experiments/{baseline.py => flat.py} (98%) delete mode 100755 experiments/karines_experiments/plastic.py delete mode 100755 experiments/karines_experiments/plastic3.py rename experiments/karines_experiments/{baseline3.py => tilted.py} (98%) diff --git a/experiments/karines_experiments/baseline_big.py b/experiments/karines_experiments/baseline_big.py deleted file mode 100755 index 84d75f6e7e..0000000000 --- a/experiments/karines_experiments/baseline_big.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env python3 -import asyncio - -from pyrevolve import parser -from pyrevolve.evolution import fitness -from pyrevolve.evolution.selection import multiple_selection, tournament_selection -from pyrevolve.evolution.population import Population, PopulationConfig -from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management -from pyrevolve.experiment_management import ExperimentManagement -from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig -from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover -from pyrevolve.genotype.plasticoding.initialization import random_initialization -from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig -from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation -from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig -from pyrevolve.tol.manage import measures -from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue -from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue -from pyrevolve.custom_logging.logger import logger -import sys - -async def run(): - """ - The main coroutine, which is started below. - """ - - # experiment params # - num_generations = 100 - population_size = 100 - offspring_size = 100 - front = 'slaves' - - # environment world and z-start - environments = {'plane': 0.03, - 'tilted5': 0.1 - } - - genotype_conf = PlasticodingConfig( - max_structural_modules=15, - plastic=False, - ) - - mutation_conf = MutationConfig( - mutation_prob=0.8, - genotype_conf=genotype_conf, - ) - - crossover_conf = CrossoverConfig( - crossover_prob=0.8, - ) - # experiment params # - - # Parse command line / file input arguments - settings = parser.parse_args() - experiment_management = ExperimentManagement(settings, environments) - do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() - - logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) - - if do_recovery: - gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, - offspring_size) - - if gen_num == num_generations-1: - logger.info('Experiment is already complete.') - return - else: - gen_num = 0 - next_robot_id = 1 - - def fitness_function(robot_manager, robot): - #contacts = measures.contacts(robot_manager, robot) - #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) - - population_conf = PopulationConfig( - population_size=population_size, - genotype_constructor=random_initialization, - genotype_conf=genotype_conf, - fitness_function=fitness_function, - mutation_operator=standard_mutation, - mutation_conf=mutation_conf, - crossover_operator=standard_crossover, - crossover_conf=crossover_conf, - selection=lambda individuals: tournament_selection(individuals, environments, 2), - parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), - population_management=steady_state_population_management, - population_management_selector=tournament_selection, - evaluation_time=settings.evaluation_time, - offspring_size=offspring_size, - experiment_name=settings.experiment_name, - experiment_management=experiment_management, - environments=environments, - front=front - ) - - settings = parser.parse_args() - - simulator_queue = {} - analyzer_queue = None - - previous_port = None - for environment in environments: - - settings.world = environment - settings.z_start = environments[environment] - - if previous_port is None: - port = settings.port_start - previous_port = port - else: - port = previous_port+settings.n_cores - previous_port = port - - simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) - await simulator_queue[environment].start() - - analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) - await analyzer_queue.start() - - population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) - - if do_recovery: - - if gen_num >= 0: - # loading a previous state of the experiment - await population.load_snapshot(gen_num) - logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') - - if has_offspring: - individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) - gen_num += 1 - logger.info('Recovered unfinished offspring '+str(gen_num)) - - if gen_num == 0: - await population.init_pop(individuals) - else: - population = await population.next_gen(gen_num, individuals) - - experiment_management.export_snapshots(population.individuals, gen_num) - else: - # starting a new experiment - experiment_management.create_exp_folders() - await population.init_pop() - experiment_management.export_snapshots(population.individuals, gen_num) - - while gen_num < num_generations-1: - gen_num += 1 - population = await population.next_gen(gen_num) - experiment_management.export_snapshots(population.individuals, gen_num) - - # output result after completing all generations... diff --git a/experiments/karines_experiments/bestrobots_summary_renders.r b/experiments/karines_experiments/bestrobots_summary_renders.r index 335af366b1..570110c706 100644 --- a/experiments/karines_experiments/bestrobots_summary_renders.r +++ b/experiments/karines_experiments/bestrobots_summary_renders.r @@ -5,16 +5,16 @@ require('magick') ##### change paths/labels/params here ##### -paths = c( 'baseline','plastic') +paths = c( 'baseline') environments = c( 'plane','tilted5') -base_directory <- paste('data/', sep='') +base_directory <- paste('data/old/', sep='') -experiments = 30 +experiments = c(22, 23,24, 25,26,27,29)#c(1:30) gens = 100 pop = 100 -num_top = 1 +num_top = 3 analysis = 'images' @@ -29,7 +29,7 @@ file <-file(paste(output_directory,'/best.txt',sep=''), open="w") for(m in 1:length(paths)) { # for each repetition - for (exp in 1:experiments) + for (exp in experiments) { input_directory1 <- paste(base_directory, paths[m],'_',exp, '/data_fullevolution/',environments[1],sep='') diff --git a/experiments/karines_experiments/consolidate_experiments.py b/experiments/karines_experiments/consolidate_experiments.py index d267c49268..fce9458158 100644 --- a/experiments/karines_experiments/consolidate_experiments.py +++ b/experiments/karines_experiments/consolidate_experiments.py @@ -4,14 +4,16 @@ # set these variables according to your experiments # dirpath = 'data/' experiments_type = [ - #'baseline', - 'plastic3' - ] + 'baseline2', + 'plastic2' + # 'flat', + # 'tilted' + ] environments = [ 'plane', 'tilted5' ] -runs = 10#30 +runs = range(1, 11) # set these variables according to your experiments # diff --git a/experiments/karines_experiments/baseline.py b/experiments/karines_experiments/flat.py similarity index 98% rename from experiments/karines_experiments/baseline.py rename to experiments/karines_experiments/flat.py index 6367c7862a..a7a10ca1a1 100755 --- a/experiments/karines_experiments/baseline.py +++ b/experiments/karines_experiments/flat.py @@ -28,12 +28,10 @@ async def run(): num_generations = 100 population_size = 100 offspring_size = 50 - front = 'slaves' + front = None # environment world and z-start - environments = {'plane': 0.03, - 'tilted5': 0.1 - } + environments = {'plane': 0.03} genotype_conf = PlasticodingConfig( max_structural_modules=15, diff --git a/experiments/karines_experiments/plastic.py b/experiments/karines_experiments/plastic.py deleted file mode 100755 index d77169629c..0000000000 --- a/experiments/karines_experiments/plastic.py +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env python3 -import asyncio - -from pyrevolve import parser -from pyrevolve.evolution import fitness -from pyrevolve.evolution.selection import multiple_selection, tournament_selection -from pyrevolve.evolution.population import Population, PopulationConfig -from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management -from pyrevolve.experiment_management import ExperimentManagement -from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig -from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover -from pyrevolve.genotype.plasticoding.initialization import random_initialization -from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig -from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation -from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig -from pyrevolve.tol.manage import measures -from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue -from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue -from pyrevolve.custom_logging.logger import logger -import sys -import time - -async def run(): - """ - The main coroutine, which is started below. - """ - - # experiment params # - num_generations = 100 - population_size = 100 - offspring_size = 50 - front = 'slaves' - - # environment world and z-start - environments = {'plane': 0.03, - 'tilted5': 0.1 - } - - genotype_conf = PlasticodingConfig( - max_structural_modules=15, - plastic=True, - ) - - mutation_conf = MutationConfig( - mutation_prob=0.8, - genotype_conf=genotype_conf, - ) - - crossover_conf = CrossoverConfig( - crossover_prob=0.8, - ) - # experiment params #load_individual - - # Parse command line / file input arguments - settings = parser.parse_args() - experiment_management = ExperimentManagement(settings, environments) - do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() - - logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) - - if do_recovery: - gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, - offspring_size) - - if gen_num == num_generations-1: - logger.info('Experiment is already complete.') - return - else: - gen_num = 0 - next_robot_id = 1 - - def fitness_function(robot_manager, robot): - #contacts = measures.contacts(robot_manager, robot) - #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) - - population_conf = PopulationConfig( - population_size=population_size, - genotype_constructor=random_initialization, - genotype_conf=genotype_conf, - fitness_function=fitness_function, - mutation_operator=standard_mutation, - mutation_conf=mutation_conf, - crossover_operator=standard_crossover, - crossover_conf=crossover_conf, - selection=lambda individuals: tournament_selection(individuals, environments, 2), - parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), - population_management=steady_state_population_management, - population_management_selector=tournament_selection, - evaluation_time=settings.evaluation_time, - offspring_size=offspring_size, - experiment_name=settings.experiment_name, - experiment_management=experiment_management, - environments=environments, - front=front - ) - - settings = parser.parse_args() - - simulator_queue = {} - analyzer_queue = None - - previous_port = None - for environment in environments: - - settings.world = environment - settings.z_start = environments[environment] - - if previous_port is None: - port = settings.port_start - previous_port = port - else: - port = previous_port+settings.n_cores - previous_port = port - - simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) - await simulator_queue[environment].start() - - analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) - await analyzer_queue.start() - - population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) - - if do_recovery: - - if gen_num >= 0: - # loading a previous state of the experiment - await population.load_snapshot(gen_num) - logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') - - if has_offspring: - individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) - gen_num += 1 - logger.info('Recovered unfinished offspring '+str(gen_num)) - - if gen_num == 0: - await population.init_pop(individuals) - else: - population = await population.next_gen(gen_num, individuals) - - experiment_management.export_snapshots(population.individuals, gen_num) - else: - # starting a new experiment - experiment_management.create_exp_folders() - await population.init_pop() - experiment_management.export_snapshots(population.individuals, gen_num) - - while gen_num < num_generations-1: - gen_num += 1 - population = await population.next_gen(gen_num) - experiment_management.export_snapshots(population.individuals, gen_num) - - # output result after completing all generations... diff --git a/experiments/karines_experiments/plastic3.py b/experiments/karines_experiments/plastic3.py deleted file mode 100755 index 3ea5de279f..0000000000 --- a/experiments/karines_experiments/plastic3.py +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env python3 -import asyncio - -from pyrevolve import parser -from pyrevolve.evolution import fitness -from pyrevolve.evolution.selection import multiple_selection, tournament_selection -from pyrevolve.evolution.population import Population, PopulationConfig -from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management -from pyrevolve.experiment_management import ExperimentManagement -from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig -from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover -from pyrevolve.genotype.plasticoding.initialization import random_initialization -from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig -from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation -from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig -from pyrevolve.tol.manage import measures -from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue -from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue -from pyrevolve.custom_logging.logger import logger -import sys -import time - -async def run(): - """ - The main coroutine, which is started below. - """ - - # experiment params # - num_generations = 100 - population_size = 100 - offspring_size = 50 - front = 'masters' - - # environment world and z-start - environments = {'plane': 0.03, - 'tilted5': 0.1 - } - - genotype_conf = PlasticodingConfig( - max_structural_modules=15, - plastic=True, - ) - - mutation_conf = MutationConfig( - mutation_prob=0.8, - genotype_conf=genotype_conf, - ) - - crossover_conf = CrossoverConfig( - crossover_prob=0.8, - ) - # experiment params # - - # Parse command line / file input arguments - settings = parser.parse_args() - experiment_management = ExperimentManagement(settings, environments) - do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() - - logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) - - if do_recovery: - gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, - offspring_size) - - if gen_num == num_generations-1: - logger.info('Experiment is already complete.') - return - else: - gen_num = 0 - next_robot_id = 1 - - def fitness_function(robot_manager, robot): - #contacts = measures.contacts(robot_manager, robot) - #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) - - population_conf = PopulationConfig( - population_size=population_size, - genotype_constructor=random_initialization, - genotype_conf=genotype_conf, - fitness_function=fitness_function, - mutation_operator=standard_mutation, - mutation_conf=mutation_conf, - crossover_operator=standard_crossover, - crossover_conf=crossover_conf, - selection=lambda individuals: tournament_selection(individuals, environments, 2), - parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), - population_management=steady_state_population_management, - population_management_selector=tournament_selection, - evaluation_time=settings.evaluation_time, - offspring_size=offspring_size, - experiment_name=settings.experiment_name, - experiment_management=experiment_management, - environments=environments, - front=front - ) - - settings = parser.parse_args() - - simulator_queue = {} - analyzer_queue = None - - previous_port = None - for environment in environments: - - settings.world = environment - settings.z_start = environments[environment] - - if previous_port is None: - port = settings.port_start - previous_port = port - else: - port = previous_port+settings.n_cores - previous_port = port - - simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) - await simulator_queue[environment].start() - - analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) - await analyzer_queue.start() - - population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) - - if do_recovery: - - if gen_num >= 0: - # loading a previous state of the experiment - await population.load_snapshot(gen_num) - logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') - - if has_offspring: - individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) - gen_num += 1 - logger.info('Recovered unfinished offspring '+str(gen_num)) - - if gen_num == 0: - await population.init_pop(individuals) - else: - population = await population.next_gen(gen_num, individuals) - - experiment_management.export_snapshots(population.individuals, gen_num) - else: - # starting a new experiment - experiment_management.create_exp_folders() - await population.init_pop() - experiment_management.export_snapshots(population.individuals, gen_num) - - while gen_num < num_generations-1: - gen_num += 1 - population = await population.next_gen(gen_num) - experiment_management.export_snapshots(population.individuals, gen_num) - - # output result after completing all generations... diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index e5552b2b35..92f4f00b33 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -1,28 +1,11 @@ #!/bin/bash +# BASELINE MEANS BASELINE+FLAT-TILTED while true do - for i in {1..10}; do - ./revolve.py --experiment-name karines_experiments/data/baseline_$i --run $i --manager experiments/karines_experiments/baseline.py --n-cores 4 --port-start 11000 --evaluation-time 50; - - sleep 5s - done -done - -while true - do - for i in {11..20}; do - ./revolve.py --experiment-name karines_experiments/data/baseline_$i --run $i --manager experiments/karines_experiments/baseline.py --n-cores 4 --port-start 11010 --evaluation-time 50; - - sleep 5s - done -done - -while true - do - for i in {21..30}; do - ./revolve.py --experiment-name karines_experiments/data/baseline_$i --run $i --manager experiments/karines_experiments/baseline.py --n-cores 4 --port-start 11020 --evaluation-time 50; + for i in {1..5}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 11000 --evaluation-time 50; sleep 5s done @@ -31,8 +14,8 @@ done while true do - for i in {1..10}; do - ./revolve.py --experiment-name karines_experiments/data/plastic_$i --run $i --manager experiments/karines_experiments/plastic.py --n-cores 4 --port-start 11030 --evaluation-time 50; + for i in {6..10}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 11050 --evaluation-time 50; sleep 5s done @@ -41,8 +24,8 @@ done while true do - for i in {11..20}; do - ./revolve.py --experiment-name karines_experiments/data/plastic_$i --run $i --manager experiments/karines_experiments/plastic.py --n-cores 4 --port-start 11040 --evaluation-time 50; + for i in {11..15}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 11100 --evaluation-time 50; sleep 5s done @@ -51,38 +34,31 @@ done while true do - for i in {21..30}; do - ./revolve.py --experiment-name karines_experiments/data/plastic_$i --run $i --manager experiments/karines_experiments/plastic.py --n-cores 4 --port-start 11050 --evaluation-time 50; + for i in {16..20}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 11150 --evaluation-time 50; sleep 5s done done -while true - do - sleep 1800s; - kill $( ps aux | grep 'gzserver' | awk '{print $2}'); - kill $( ps aux | grep 'revolve.py' | awk '{print $2}'); - sleep 60s; -done - - +# PLASTIC MEANS PLASTIC+FLAT-TILTED while true do for i in {1..5}; do - ./revolve.py --experiment-name karines_experiments/data/plastic2_$i --run $i --manager experiments/karines_experiments/plastic2.py --n-cores 4 --port-start 11150 --evaluation-time 50; + ./revolve.py --experiment-name karines_experiments/data/plastic2_$i --run $i --manager experiments/karines_experiments/plastic2.py --n-cores 4 --port-start 11200 --evaluation-time 50; sleep 5s done done + while true do for i in {6..10}; do - ./revolve.py --experiment-name karines_experiments/data/plastic2_$i --run $i --manager experiments/karines_experiments/plastic2.py --n-cores 4 --port-start 11120 --evaluation-time 50; + ./revolve.py --experiment-name karines_experiments/data/plastic2_$i --run $i --manager experiments/karines_experiments/plastic2.py --n-cores 4 --port-start 11250 --evaluation-time 50; sleep 5s done @@ -91,17 +67,18 @@ done while true do - for i in {1..5}; do - ./revolve.py --experiment-name karines_experiments/data/plastic3_$i --run $i --manager experiments/karines_experiments/plastic3.py --n-cores 4 --port-start 12150 --evaluation-time 50; + for i in {11..15}; do + ./revolve.py --experiment-name karines_experiments/data/plastic2_$i --run $i --manager experiments/karines_experiments/plastic2.py --n-cores 4 --port-start 11300 --evaluation-time 50; sleep 5s done done + while true do - for i in {6..10}; do - ./revolve.py --experiment-name karines_experiments/data/plastic3_$i --run $i --manager experiments/karines_experiments/plastic3.py --n-cores 4 --port-start 12250 --evaluation-time 50; + for i in {16..20}; do + ./revolve.py --experiment-name karines_experiments/data/plastic2_$i --run $i --manager experiments/karines_experiments/plastic2.py --n-cores 4 --port-start 11350 --evaluation-time 50; sleep 5s done @@ -109,10 +86,11 @@ done + while true do - for i in {1..5}; do - ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 12050 --evaluation-time 50; + for i in {1..10}; do + ./revolve.py --experiment-name karines_experiments/data/flat_$i --run $i --manager experiments/karines_experiments/flat.py --n-cores 4 --port-start 11400 --evaluation-time 50; sleep 5s done @@ -120,8 +98,8 @@ done while true do - for i in {6..10}; do - ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 9870 --evaluation-time 50; + for i in {11..20}; do + ./revolve.py --experiment-name karines_experiments/data/flat_$i --run $i --manager experiments/karines_experiments/flat.py --n-cores 4 --port-start 11500 --evaluation-time 50; sleep 5s done @@ -130,8 +108,8 @@ done while true do - for i in {1..5}; do - ./revolve.py --experiment-name karines_experiments/data/baseline3_$i --run $i --manager experiments/karines_experiments/baseline3.py --n-cores 4 --port-start 9890 --evaluation-time 50; + for i in {1..10}; do + ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/tilted.py --n-cores 4 --port-start 11600 --evaluation-time 50; sleep 5s done @@ -139,12 +117,20 @@ done while true do - for i in {6..10}; do - ./revolve.py --experiment-name karines_experiments/data/baseline3_$i --run $i --manager experiments/karines_experiments/baseline3.py --n-cores 4 --port-start 7870 --evaluation-time 50; + for i in {11..20}; do + ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/tilted.py --n-cores 4 --port-start 11700 --evaluation-time 50; sleep 5s done done +while true + do + sleep 900s; + kill $( ps aux | grep 'gzserver' | awk '{print $2}'); + kill $( ps aux | grep 'revolve.py' | awk '{print $2}'); + sleep 60s; +done + diff --git a/experiments/karines_experiments/scatter2.R b/experiments/karines_experiments/scatter2.R index b1164d90ca..ab70887559 100644 --- a/experiments/karines_experiments/scatter2.R +++ b/experiments/karines_experiments/scatter2.R @@ -4,11 +4,11 @@ library(sqldf) base_directory <-paste('data', sep='') -analysis = 'analysis3' +analysis = 'analysis1' output_directory = paste(base_directory,'/',analysis ,sep='') -experiments_type = c( 'baseline3','plastic3') +experiments_type = c( 'baseline','plastic') labels_type = c( 'Baseline','Plastic') @@ -17,8 +17,8 @@ environments = c( 'plane','tilted5') labels = c('Speed (cm/s) in Flat', 'Speed (cm/s) in Tilted') -runs = list( c(1:10), - c(1:10)) +runs = list( c(21:30), + c(21:30)) diff --git a/experiments/karines_experiments/summary_measures.R b/experiments/karines_experiments/summary_measures.R index 9266108b14..28fe84cf41 100644 --- a/experiments/karines_experiments/summary_measures.R +++ b/experiments/karines_experiments/summary_measures.R @@ -8,15 +8,15 @@ base_directory <-paste('data', sep='') -analysis = 'analysis1' +analysis = 'analysis2' output_directory = paste(base_directory,'/',analysis ,sep='') #### CHANGE THE PARAMETERS HERE #### -experiments_type = c( 'baseline','plastic') - +experiments_type = c( 'baseline2', 'plastic2') + environments = c( 'plane','tilted5') methods = c() @@ -36,12 +36,9 @@ experiments_labels = c( 'Baseline: Flat', 'Baseline: Tilted', experiments_labels2 = c( 'Baseline', 'Baseline', 'Plastic: Flat', 'Plastic: Tilted') - #runs = c(1:30) - runs = list( c(21:30), - c(21:30)) - #runs = list( c(12, 16, 15, 17, 21, 22, 23, 26, 27, 29), - # c(11, 13, 15, 16, 19, 20 ,24, 25, 26, 28)) - gens = 50#100 + runs = list( c(1:10), c(1:10) ) + + gens = 10#100 pop = 100 #### CHANGE THE PARAMETERS HERE #### @@ -196,8 +193,9 @@ experiments_labels2 = c( 'Baseline', 'Baseline', query = paste(query,' from measures_snapshots_all where method="', methods[met],'" group by run, generation', sep='') - - measures_averages_gens_1[[met]] = sqldf(query) + temp = sqldf(query) + + measures_averages_gens_1[[met]] = temp temp = measures_averages_gens_1[[met]] diff --git a/experiments/karines_experiments/baseline3.py b/experiments/karines_experiments/tilted.py similarity index 98% rename from experiments/karines_experiments/baseline3.py rename to experiments/karines_experiments/tilted.py index 0466cdc4c4..fef3500226 100755 --- a/experiments/karines_experiments/baseline3.py +++ b/experiments/karines_experiments/tilted.py @@ -28,12 +28,10 @@ async def run(): num_generations = 100 population_size = 100 offspring_size = 50 - front = 'masters' + front = None # environment world and z-start - environments = {'plane': 0.03, - 'tilted5': 0.1 - } + environments = {'tilted5': 0.1} genotype_conf = PlasticodingConfig( max_structural_modules=15, From 3dbc1829b46d335ae4e6ed9c2ae368c3f1e8eac8 Mon Sep 17 00:00:00 2001 From: Karine Date: Thu, 23 Jan 2020 12:40:56 +0100 Subject: [PATCH 32/45] fix exception pickle, and fix bug consolidation for non-seasonal --- pyrevolve/evolution/population.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index dd499381e1..fb90f5f40d 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -122,9 +122,14 @@ async def load_individual(self, id): individual = {} for environment in self.conf.environments: - file_name = os.path.join(path, environment,'individuals','individual_'+id+'.pkl') - file = open(file_name, 'rb') - individual[environment] = pickle.load(file) + try: + file_name = os.path.join(path, environment,'individuals','individual_'+id+'.pkl') + file = open(file_name, 'rb') + individual[environment] = pickle.load(file) + except EOFError: + print('bad pickle for robot', id, ' was replaced for new robot with None fitness') + individual = self._new_individual( + self.conf.genotype_constructor(self.conf.genotype_conf, id)) return individual @@ -161,9 +166,9 @@ async def load_offspring(self, last_snapshot, population_size, offspring_size, n async def consolidate_fitness(self, individuals): - if len(self.conf.environments) == 0: + if len(self.conf.environments) == 1: for individual in individuals: - fit = individual[list(self.conf.environments.keys())[-1]] + fit = individual[list(self.conf.environments.keys())[-1]].fitness individual[list(self.conf.environments.keys())[-1]].consolidated_fitness = fit # if there are multiple seasons (environments) @@ -241,8 +246,7 @@ async def consolidate_fitness(self, individuals): individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = 1/masters for individual in individuals: - self.conf.experiment_management.export_consolidated_fitness( - individual[list(self.conf.environments.keys())[-1]],) + self.conf.experiment_management.export_consolidated_fitness(individual[list(self.conf.environments.keys())[-1]]) self.conf.experiment_management.export_individual(individual[list(self.conf.environments.keys())[-1]], list(self.conf.environments.keys())[-1]) From 70e7a000af72daa03836924b3ce1e4a973728330 Mon Sep 17 00:00:00 2001 From: Karine Date: Thu, 23 Jan 2020 18:22:54 +0100 Subject: [PATCH 33/45] untested lava changes + analysis scripts adaptation --- .../karines_experiments/baseline2_lava.py | 160 ++++++ experiments/karines_experiments/lava.py | 152 +++++ .../karines_experiments/plastic2_lava.py | 160 ++++++ .../summary_measures_journal1_tilted.R | 540 ++++++++++++++++++ ...s.R => summary_measures_journal2_tilted.R} | 24 +- worlds/lava.world | 43 ++ 6 files changed, 1067 insertions(+), 12 deletions(-) create mode 100755 experiments/karines_experiments/baseline2_lava.py create mode 100755 experiments/karines_experiments/lava.py create mode 100755 experiments/karines_experiments/plastic2_lava.py create mode 100644 experiments/karines_experiments/summary_measures_journal1_tilted.R rename experiments/karines_experiments/{summary_measures.R => summary_measures_journal2_tilted.R} (97%) create mode 100644 worlds/lava.world diff --git a/experiments/karines_experiments/baseline2_lava.py b/experiments/karines_experiments/baseline2_lava.py new file mode 100755 index 0000000000..c95bebcf9c --- /dev/null +++ b/experiments/karines_experiments/baseline2_lava.py @@ -0,0 +1,160 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + front = 'total_slaves' + + # environment world and z-start + environments = {'plane': 0.03, + 'lava': 0.03 + } + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=False, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function_plane(robot_manager, robot): + contacts = measures.contacts(robot_manager, robot) + assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + def fitness_function_lava(robot_manager, robot): + contacts = measures.contacts(robot_manager, robot) + assert(contacts != 0) + return fitness.floor_is_lava(robot_manager, robot, False) + + fitness_functions = {'plane': fitness_function_plane, + 'lava': fitness_function_lava} + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_functions, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/karines_experiments/lava.py b/experiments/karines_experiments/lava.py new file mode 100755 index 0000000000..e0b8d01626 --- /dev/null +++ b/experiments/karines_experiments/lava.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + front = None + + # environment world and z-start + environments = {'lava': 0.03} + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=False, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function_lava(robot_manager, robot): + contacts = measures.contacts(robot_manager, robot) + assert(contacts != 0) + return fitness.floor_is_lava(robot_manager, robot, False) + + fitness_functions = {'lava': fitness_function_lava} + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_functions, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/karines_experiments/plastic2_lava.py b/experiments/karines_experiments/plastic2_lava.py new file mode 100755 index 0000000000..413cbf8393 --- /dev/null +++ b/experiments/karines_experiments/plastic2_lava.py @@ -0,0 +1,160 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + front = 'total_slaves' + + # environment world and z-start + environments = {'plane': 0.03, + 'lava': 0.03 + } + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=True, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function_plane(robot_manager, robot): + contacts = measures.contacts(robot_manager, robot) + assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + def fitness_function_lava(robot_manager, robot): + contacts = measures.contacts(robot_manager, robot) + assert(contacts != 0) + return fitness.floor_is_lava(robot_manager, robot, False) + + fitness_functions = {'plane': fitness_function_plane, + 'lava': fitness_function_lava} + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_functions, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/karines_experiments/summary_measures_journal1_tilted.R b/experiments/karines_experiments/summary_measures_journal1_tilted.R new file mode 100644 index 0000000000..892cb13ce6 --- /dev/null +++ b/experiments/karines_experiments/summary_measures_journal1_tilted.R @@ -0,0 +1,540 @@ +library(ggplot2) +library(sqldf) +library(plyr) +library(dplyr) +library(trend) +library(purrr) +library(ggsignif) + +base_directory <-paste('data', sep='') + +analysis = 'analysis_journal1_tilted' + +output_directory = paste(base_directory,'/',analysis ,sep='') + +#### CHANGE THE PARAMETERS HERE #### + + +experiments_type = c('flat', 'tilted','baseline2') + +environments = list( c( 'plane'), + c('tilted5'), + c( 'plane','tilted5') ) + +methods = c() +for (exp in 1:length(experiments_type)) +{ + for (env in 1:length(environments[[exp]])) + { + methods = c(methods, paste(experiments_type[exp], environments[[exp]][env], sep='_')) + } +} + +initials = c( 'bp', 'bt', 'pp', 'pt') + +experiments_labels = c( 'Non-S: Flat', 'Non-S: Tilted', + 'Seasonal: Flat', 'Seasonal: Tilted') + +experiments_labels2 = c( 'Non-S: Flat', 'Non-S: Tilted', + 'Seasonal', 'Seasonal') + +runs = list( c(1:20) , + c(1:20) , + c(1:20) ) + +gens = 1#100 +pop = 100 + +#### CHANGE THE PARAMETERS HERE #### + +sig = 0.05 +line_size = 30 +show_markers = TRUE#FALSE +show_legends = FALSE +experiments_type_colors = c( '#00e700' , '#009900', '#ffb83b', '#fd8a3b') # DARK: light green,dark green, light red, dark red + +measures_names = c( + 'displacement_velocity_hill', + 'head_balance', + 'contacts', + 'displacement_velocity', + 'branching', + 'branching_modules_count', + 'limbs', + 'extremities', + 'length_of_limbs', + 'extensiveness', + 'coverage', + 'joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'proportion', + 'width', + 'height', + 'absolute_size', + 'sensors', + 'symmetry', + 'avg_period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'fitness', + 'cons_fitness' +) + +# add proper labels soon... +measures_labels = c( + 'Speed (cm/s)', + 'Balance', + 'Contacts', + 'displacement_velocity', + 'Branching', + 'branching_modules_count', + 'Rel number of limbs', + 'extremities', + 'Rel. Length of Limbs', + 'extensiveness', + 'coverage', + 'Rel. Number of Joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'Proportion', + 'width', + 'height', + 'Size', + 'sensors', + 'Symmetry', + 'Average Period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'Fitness', + 'Number of slaves' +) + + +measures_snapshots_all = NULL + +for (exp in 1:length(experiments_type)) +{ + #for(run in runs) + for(run in runs[[exp]]) + { + for (env in 1:length(environments[[exp]])) + { + input_directory <- paste(base_directory, '/', + experiments_type[exp], '_',sep='') + + measures = read.table(paste(input_directory, run, '/data_fullevolution/', + environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE) + for( m in 1:length(measures_names)) + { + measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) + } + + snapshots = read.table(paste(input_directory, run,'/selectedpop_', + environments[[exp]][env],"/snapshots_ids.tsv", sep=''), header = TRUE) + + measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') + + measures_snapshots$run = run + measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 + measures_snapshots$run = as.factor(measures_snapshots$run) + measures_snapshots$method = paste(experiments_type[exp], environments[[exp]][env],sep='_') + + if ( is.null(measures_snapshots_all)){ + measures_snapshots_all = measures_snapshots + }else{ + measures_snapshots_all = rbind(measures_snapshots_all, measures_snapshots) + } + } + } +} + + +fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) + + +measures_snapshots_all = sqldf("select * from measures_snapshots_all where cons_fitness IS NOT NULL") + + + +measures_averages_gens_1 = list() +measures_averages_gens_2 = list() + +measures_ini = list() +measures_fin = list() + +for (met in 1:length(methods)) +{ + + measures_aux = c() + query ='select run, generation' + for (i in 1:length(measures_names)) + { + query = paste(query,', avg(',measures_names[i],') as ', methods[met], '_',measures_names[i],'_avg', sep='') + } + query = paste(query,' from measures_snapshots_all + where method="', methods[met],'" group by run, generation', sep='') + + temp = sqldf(query) + + measures_averages_gens_1[[met]] = temp + + temp = measures_averages_gens_1[[met]] + + temp$generation = as.numeric(temp$generation) + + measures_ini[[met]] = sqldf(paste("select * from temp where generation=0")) + measures_fin[[met]] = sqldf(paste("select * from temp where generation=",gens-1)) + query = 'select generation' + for (i in 1:length(measures_names)) + { + # later renames vars _avg_SUMMARY, just to make it in the same style as the quantile variables + query = paste(query,', avg(', methods[met], '_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_avg', sep='') + query = paste(query,', max(', methods[met],'_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_max', sep='') + query = paste(query,', stdev(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_stdev', sep='') + query = paste(query,', median(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_median', sep='') + + measures_aux = c(measures_aux, paste(methods[met],'_',measures_names[i],'_avg', sep='') ) + } + query = paste(query,' from temp group by generation', sep="") + + temp2 = sqldf(query) + + p <- c(0.25, 0.75) + p_names <- map_chr(p, ~paste0('Q',.x*100, sep="")) + p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>% + set_names(nm = p_names) + + quantiles = data.frame(temp %>% + group_by(generation) %>% + summarize_at(vars(measures_aux), funs(!!!p_funs)) ) + + measures_averages_gens_2[[met]] = sqldf('select * from temp2 inner join quantiles using (generation)') + +} + + +for (met in 1:length(methods)) +{ + if(met==1){ + measures_averages_gens = measures_averages_gens_2[[1]] + }else{ + measures_averages_gens = merge(measures_averages_gens, measures_averages_gens_2[[met]], all=TRUE, by = "generation") + } +} + +file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") + +#tests trends in curves and difference between ini and fin generations + + +# ini VS fin +array_wilcoxon = list() +array_wilcoxon2 = list() + +# curve +array_mann = list() + + +for (m in 1:length(methods)) +{ + + array_wilcoxon[[m]] = list() + array_mann[[m]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(experiments_type[m],measures_names[i],'ini avg ',as.character( + mean(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon[[m]][[i]] = wilcox.test(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'iniVSfin',measures_names[i],'wilcox p: ',as.character(round(array_wilcoxon[[m]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'iniVSfin',measures_names[i],'wilcox est: ',as.character(round(array_wilcoxon[[m]][[i]]$statistic,4)), sep=' ') + + ), file) + + + #tests trends + array_mann[[m]][[i]] = mk.test(c(array(measures_averages_gens_2[[m]][paste(methods[m],"_",measures_names[i],'_median',sep='')]) )[[1]], + continuity = TRUE) + + + writeLines(c( + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median p', as.character(round(array_mann[[m]][[i]]$p.value,4)),sep=' '), + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median s', as.character(round(array_mann[[m]][[i]]$statistic,4)),sep=' ') + ), file) + + } + +} + + + +# tests final generation among experiments_type + +aux_m = length(methods) + +if (aux_m>1) +{ + + # fins + array_wilcoxon2[[1]] = list() + array_wilcoxon2[[2]] = list() + + aux_m = aux_m -1 + count_pairs = 0 + for(m in 1:aux_m) + { + aux = m+1 + for(m2 in aux:length(methods)) + { + + count_pairs = count_pairs+1 + array_wilcoxon2[[1]][[count_pairs]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + writeLines(paste(methods[m2],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon2[[1]][[count_pairs]][[i]] = wilcox.test(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'VS',methods,measures_names[i],'fin avg wilcox p: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'VS',methods[m2],measures_names[i],'fin avg wilcox est: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$statistic,4)), sep=' ') + + ), file) + + } + + + array_wilcoxon2[[2]][[count_pairs]] = paste(initials[m],initials[m2],sep='') + + } + } + +} + +close(file) + +# plots measures + +for (type_summary in c('means','quants')) +{ + + + for (i in 1:length(measures_names)) + { + tests1 = '' + tests2 = '' + tests3 = '' + break_aux = 0 + + graph <- ggplot(data=measures_averages_gens, aes(x=generation)) + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg','-',methods[m],'_',measures_names[i],'_stdev',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg','+',methods[m],'_',measures_names[i],'_stdev',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + }else + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg_Q25',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg_Q75',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + } + } + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) + } + + }else{ + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') , colour=shQuote(experiments_labels[m]) ),size=2 ) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') ),size=2, color = experiments_type_colors[m] ) + } + } + + if (length(array_mann)>0) + { + if (length(array_mann[[m]])>0) + { + if(!is.na(array_mann[[m]][[i]]$p.value)) + { + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } + } + } + } + } + + if (length(array_wilcoxon[[m]])>0) + { + for(m in 1:length(methods)) + { + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + { + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } + } + } + } + + if (length(array_wilcoxon2)>0) + { + for(p in 1:length(array_wilcoxon2[[1]])) + { + if (length(array_wilcoxon2[[1]][[p]])>0) + { + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + { + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') + } + } + } + } + } + + max_y = 0 + #if(measures_names[i]=='proportion' || measures_names[i]=='balance' || measures_names[i]=='joints' ){ max_y = 1.1 } + + graph = graph + labs( y=measures_labels[i], x="Generation") + if (max_y>0) { + graph = graph + coord_cartesian(ylim = c(0, max_y)) + } + + if(show_markers == TRUE){ + graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) + } + graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=30),axis.title=element_text(size=39), + plot.subtitle=element_text(size=25 )) + + ggsave(paste( output_directory,'/',type_summary,'_' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 10, width = 10) + } + +} + + + + +for (i in 1:length(measures_names)) +{ + + all_final_values = data.frame() + if (measures_names[i] == 'displacement_velocity_hill') { fin=length(methods) + }else{ fin=length(methods)-1 } + + for (exp in 1:fin) + { + temp = data.frame( c(measures_fin[[exp]][paste(methods[exp],'_',measures_names[i],'_avg', sep='')])) + colnames(temp) <- 'values' + if (measures_names[i] == 'displacement_velocity_hill') { temp$type = experiments_labels[exp] + }else{ temp$type = experiments_labels2[exp] } + + all_final_values = rbind(all_final_values, temp) + } + + + max_y = 0 + # if(measures_names[i]=='proportion' || measures_names[i]=='head_balance' || measures_names[i]=='joints' ){ max_y = 1.1 } + + g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4, notch=TRUE) + + labs( x="Environment", y=measures_labels[i], title="Final generation") + + if (measures_names[i] == 'displacement_velocity_hill') { g1 = g1 + scale_color_manual(values=experiments_type_colors) + }else{ g1 = g1 + scale_color_manual(values= c(experiments_type_colors[1:2],experiments_type_colors[4:4])) } + + g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , + plot.title=element_text(size=40), axis.text=element_text(size=45), + axis.title=element_text(size=50), + axis.text.x = element_text(angle = 20, hjust = 1 ), + plot.margin=margin(t = 0.5, r = 0.5, b = 0.5, l = 0.5, unit = "cm") + )+ + stat_summary(fun.y = mean, geom="point" ,shape = 16, size=11) + + if (measures_names[i] == 'displacement_velocity_hill') { comps = list(c("Non-S: Flat", "Seasonal: Flat"), + c("Non-S: Tilted", "Seasonal: Tilted"), + c("Non-S: Tilted", "Non-S: Flat"), + c("Seasonal: Tilted", "Seasonal: Flat")) + aux_width=13 + }else{ comps = list(c("Non-S: Flat", "Non-S: Tilted"), + c("Non-S: Flat", "Seasonal"), + c("Non-S: Tilted", "Seasonal")) + aux_width=10 + } + + + g1 = g1 + geom_signif( test="wilcox.test", size=2, textsize=22, + comparisons = comps, + map_signif_level=c("***"=0.001,"**"=0.01, "*"=0.05) ) + if (max_y>0) { + g1 = g1 + coord_cartesian(ylim = c(0, max_y)) + } + + ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = aux_width) + +} + diff --git a/experiments/karines_experiments/summary_measures.R b/experiments/karines_experiments/summary_measures_journal2_tilted.R similarity index 97% rename from experiments/karines_experiments/summary_measures.R rename to experiments/karines_experiments/summary_measures_journal2_tilted.R index 28fe84cf41..3cc570b9a9 100644 --- a/experiments/karines_experiments/summary_measures.R +++ b/experiments/karines_experiments/summary_measures_journal2_tilted.R @@ -8,7 +8,7 @@ base_directory <-paste('data', sep='') -analysis = 'analysis2' +analysis = 'analysis_journal2_tilted' output_directory = paste(base_directory,'/',analysis ,sep='') @@ -17,14 +17,14 @@ output_directory = paste(base_directory,'/',analysis ,sep='') experiments_type = c( 'baseline2', 'plastic2') -environments = c( 'plane','tilted5') +environments = list(c( 'plane','tilted5'), c( 'plane','tilted5') ) methods = c() for (exp in 1:length(experiments_type)) { - for (env in 1:length(environments)) + for (env in 1:length(environments[[exp]])) { - methods = c(methods, paste(experiments_type[exp], environments[env], sep='_')) + methods = c(methods, paste(experiments_type[exp], environments[[exp]][env], sep='_')) } } @@ -36,7 +36,7 @@ experiments_labels = c( 'Baseline: Flat', 'Baseline: Tilted', experiments_labels2 = c( 'Baseline', 'Baseline', 'Plastic: Flat', 'Plastic: Tilted') - runs = list( c(1:10), c(1:10) ) + runs = list( c(1:20), c(1:20) ) gens = 10#100 pop = 100 @@ -136,27 +136,27 @@ experiments_labels2 = c( 'Baseline', 'Baseline', #for(run in runs) for(run in runs[[exp]]) { - for (env in 1:length(environments)) + for (env in 1:length(environments[[exp]])) { input_directory <- paste(base_directory, '/', experiments_type[exp], '_',sep='') measures = read.table(paste(input_directory, run, '/data_fullevolution/', - environments[env], "/all_measures.tsv", sep=''), header = TRUE) + environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE) for( m in 1:length(measures_names)) { measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) } snapshots = read.table(paste(input_directory, run,'/selectedpop_', - environments[env],"/snapshots_ids.tsv", sep=''), header = TRUE) + environments[[exp]][env],"/snapshots_ids.tsv", sep=''), header = TRUE) measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') measures_snapshots$run = run measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 measures_snapshots$run = as.factor(measures_snapshots$run) - measures_snapshots$method = paste(experiments_type[exp], environments[env],sep='_') + measures_snapshots$method = paste(experiments_type[exp], environments[[exp]][env],sep='_') if ( is.null(measures_snapshots_all)){ measures_snapshots_all = measures_snapshots @@ -479,8 +479,8 @@ experiments_labels2 = c( 'Baseline', 'Baseline', { all_final_values = data.frame() - if (measures_names[i] == 'displacement_velocity_hill') { ini=1 } - else{ ini=2 } + if (measures_names[i] == 'displacement_velocity_hill') { ini=1 + }else{ ini=2 } for (exp in ini:length(methods)) { @@ -522,7 +522,7 @@ experiments_labels2 = c( 'Baseline', 'Baseline', if (max_y>0) { g1 = g1 + coord_cartesian(ylim = c(0, max_y)) } - + g1 ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = 10) } diff --git a/worlds/lava.world b/worlds/lava.world new file mode 100644 index 0000000000..07330739c3 --- /dev/null +++ b/worlds/lava.world @@ -0,0 +1,43 @@ + + + + + 0 + 0 + + + + 0.005 + + + 0 + + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + world + + + + + + + + + model://sun + + + model://tol_ground + + + + + From 0cfff982ab630f17ccc7a37ce1648c5fef5a862a Mon Sep 17 00:00:00 2001 From: Karine Date: Fri, 24 Jan 2020 16:58:30 +0100 Subject: [PATCH 34/45] more scripts --- ...bestrobots_summary_renders_journal1_lava.r | 86 +++ ...strobots_summary_renders_journal1_tilted.r | 86 +++ ...bestrobots_summary_renders_journal2_lava.r | 85 +++ ...trobots_summary_renders_journal2_tilted.r} | 26 +- .../consolidate_experiments.py | 25 +- .../karines_experiments/densities_tilted.R | 100 +++ experiments/karines_experiments/scatter.R | 8 +- experiments/karines_experiments/scatter2.R | 10 +- .../summary_measures_journal1_lava.R | 575 ++++++++++++++++++ .../summary_measures_journal1_tilted.R | 45 +- .../summary_measures_journal2_lava.R | 566 +++++++++++++++++ .../summary_measures_journal2_tilted.R | 51 +- 12 files changed, 1620 insertions(+), 43 deletions(-) create mode 100644 experiments/karines_experiments/bestrobots_summary_renders_journal1_lava.r create mode 100644 experiments/karines_experiments/bestrobots_summary_renders_journal1_tilted.r create mode 100644 experiments/karines_experiments/bestrobots_summary_renders_journal2_lava.r rename experiments/karines_experiments/{bestrobots_summary_renders.r => bestrobots_summary_renders_journal2_tilted.r} (77%) create mode 100644 experiments/karines_experiments/densities_tilted.R create mode 100644 experiments/karines_experiments/summary_measures_journal1_lava.R create mode 100644 experiments/karines_experiments/summary_measures_journal2_lava.R diff --git a/experiments/karines_experiments/bestrobots_summary_renders_journal1_lava.r b/experiments/karines_experiments/bestrobots_summary_renders_journal1_lava.r new file mode 100644 index 0000000000..3f80de3e00 --- /dev/null +++ b/experiments/karines_experiments/bestrobots_summary_renders_journal1_lava.r @@ -0,0 +1,86 @@ + +library(sqldf) +require('magick') + +##### change paths/labels/params here ##### + + +paths = c( 'flat', 'lava', 'baseline2_lava') + +environments = list(c( 'plane'), + c( 'lava'), + c( 'plane') +) + +base_directory <- paste('data/', sep='') + +experiments = c(1:20) +gens = 42#100 +pop = 100 +num_top = 1 + +analysis = 'analysis_journal1_tilted' + +##### change paths/labels/params here ##### + +output_directory = paste(base_directory,analysis, sep='') + + +file <-file(paste(output_directory,'/best.txt',sep=''), open="w") + +# for each method +for(m in 1:length(paths)) +{ + # for each repetition + for (exp in experiments) + { + + input_directory1 <- paste(base_directory, paths[m],'_',exp, '/data_fullevolution/',environments[[m]][1],sep='') + input_directory2 <- paste(base_directory, paths[m],'_',exp, '/selectedpop_', sep='') + + ids_gens = data.frame() + list = strsplit(list.files(paste(input_directory2, environments[[m]][1],'/selectedpop_',gens-1, sep='')), ' ') + for(geno in 1:pop) + { + genome = data.frame(cbind(c(gens), c(strsplit(strsplit(list [[geno]],'_')[[1]][3],'.png')[[1]][1] ))) + names(genome)<-c('generation','robot_id') + ids_gens = rbind(ids_gens,genome) + } + + measures = read.table(paste(input_directory1,"/all_measures.tsv", sep=''), header = TRUE) + bests = sqldf(paste("select robot_id, cons_fitness from measures inner join ids_gens using (robot_id) order by cons_fitness desc limit",num_top)) + + for(b in 1:nrow(bests)) + { + + writeLines( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] ), file ) + print( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] )) + + phenotype= bests[b,'robot_id'] + + for (env in 1:length(environments[[m]])) + { + patha = paste(input_directory2, environments[[m]][env], "/selectedpop_",gens-1,sep="") + + body <- list.files(patha, paste("body_robot_",phenotype,".png$",sep=""), full.names = TRUE) + body = image_read(body) + body = image_scale(body, "100x100") + body = image_border(image_background(body, "white"), "white", "5x5") + + if(b == 1 && env == 1) + { + bodies = body + }else{ + bodies = c(bodies, body) + } + } + } + + side_by_side = image_append(bodies, stack=F) + image_write(side_by_side, path = paste(output_directory,"/",paths[m],'_', environments[[m]][env], "_bodies_best_",exp,".png",sep=''), format = "png") + + } +} + + +close(file) diff --git a/experiments/karines_experiments/bestrobots_summary_renders_journal1_tilted.r b/experiments/karines_experiments/bestrobots_summary_renders_journal1_tilted.r new file mode 100644 index 0000000000..32668b1e5a --- /dev/null +++ b/experiments/karines_experiments/bestrobots_summary_renders_journal1_tilted.r @@ -0,0 +1,86 @@ + +library(sqldf) +require('magick') + +##### change paths/labels/params here ##### + + +paths = c( 'flat', 'tilted', 'baseline2') + +environments = list(c( 'plane'), + c( 'tilted5'), + c( 'plane') +) + +base_directory <- paste('data/', sep='') + +experiments = c(1:20) +gens = 42#100 +pop = 100 +num_top = 1 + +analysis = 'analysis_journal1_tilted' + +##### change paths/labels/params here ##### + +output_directory = paste(base_directory,analysis, sep='') + + +file <-file(paste(output_directory,'/best.txt',sep=''), open="w") + +# for each method +for(m in 1:length(paths)) +{ + # for each repetition + for (exp in experiments) + { + + input_directory1 <- paste(base_directory, paths[m],'_',exp, '/data_fullevolution/',environments[[m]][1],sep='') + input_directory2 <- paste(base_directory, paths[m],'_',exp, '/selectedpop_', sep='') + + ids_gens = data.frame() + list = strsplit(list.files(paste(input_directory2, environments[[m]][1],'/selectedpop_',gens-1, sep='')), ' ') + for(geno in 1:pop) + { + genome = data.frame(cbind(c(gens), c(strsplit(strsplit(list [[geno]],'_')[[1]][3],'.png')[[1]][1] ))) + names(genome)<-c('generation','robot_id') + ids_gens = rbind(ids_gens,genome) + } + + measures = read.table(paste(input_directory1,"/all_measures.tsv", sep=''), header = TRUE) + bests = sqldf(paste("select robot_id, cons_fitness from measures inner join ids_gens using (robot_id) order by cons_fitness desc limit",num_top)) + + for(b in 1:nrow(bests)) + { + + writeLines( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] ), file ) + print( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] )) + + phenotype= bests[b,'robot_id'] + + for (env in 1:length(environments[[m]])) + { + patha = paste(input_directory2, environments[[m]][env], "/selectedpop_",gens-1,sep="") + + body <- list.files(patha, paste("body_robot_",phenotype,".png$",sep=""), full.names = TRUE) + body = image_read(body) + body = image_scale(body, "100x100") + body = image_border(image_background(body, "white"), "white", "5x5") + + if(b == 1 && env == 1) + { + bodies = body + }else{ + bodies = c(bodies, body) + } + } + } + + side_by_side = image_append(bodies, stack=F) + image_write(side_by_side, path = paste(output_directory,"/",paths[m],'_', environments[[m]][env], "_bodies_best_",exp,".png",sep=''), format = "png") + + } +} + + +close(file) diff --git a/experiments/karines_experiments/bestrobots_summary_renders_journal2_lava.r b/experiments/karines_experiments/bestrobots_summary_renders_journal2_lava.r new file mode 100644 index 0000000000..331fab5186 --- /dev/null +++ b/experiments/karines_experiments/bestrobots_summary_renders_journal2_lava.r @@ -0,0 +1,85 @@ + +library(sqldf) +require('magick') + +##### change paths/labels/params here ##### + + +paths = c( 'baseline2_lava', 'plastic2_lava') + +environments = list(c( 'plane','lava'), + c( 'plane','lava') +) + +base_directory <- paste('data/', sep='') + +experiments = c(1:20) +gens = 42#100 +pop = 100 +num_top = 1 + +analysis = 'analysis_journal2_lava' + +##### change paths/labels/params here ##### + +output_directory = paste(base_directory,analysis, sep='') + + +file <-file(paste(output_directory,'/best.txt',sep=''), open="w") + +# for each method +for(m in 1:length(paths)) +{ + # for each repetition + for (exp in experiments) + { + + input_directory1 <- paste(base_directory, paths[m],'_',exp, '/data_fullevolution/',environments[[m]][1],sep='') + input_directory2 <- paste(base_directory, paths[m],'_',exp, '/selectedpop_', sep='') + + ids_gens = data.frame() + list = strsplit(list.files(paste(input_directory2, environments[[m]][1],'/selectedpop_',gens-1, sep='')), ' ') + for(geno in 1:pop) + { + genome = data.frame(cbind(c(gens), c(strsplit(strsplit(list [[geno]],'_')[[1]][3],'.png')[[1]][1] ))) + names(genome)<-c('generation','robot_id') + ids_gens = rbind(ids_gens,genome) + } + + measures = read.table(paste(input_directory1,"/all_measures.tsv", sep=''), header = TRUE) + bests = sqldf(paste("select robot_id, cons_fitness from measures inner join ids_gens using (robot_id) order by cons_fitness desc limit",num_top)) + + for(b in 1:nrow(bests)) + { + + writeLines( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] ), file ) + print( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] )) + + phenotype= bests[b,'robot_id'] + + for (env in 1:length(environments[[m]])) + { + patha = paste(input_directory2, environments[[m]][env], "/selectedpop_",gens-1,sep="") + + body <- list.files(patha, paste("body_robot_",phenotype,".png$",sep=""), full.names = TRUE) + body = image_read(body) + body = image_scale(body, "100x100") + body = image_border(image_background(body, "white"), "white", "5x5") + + if(b == 1 && env == 1) + { + bodies = body + }else{ + bodies = c(bodies, body) + } + } + } + + side_by_side = image_append(bodies, stack=F) + image_write(side_by_side, path = paste(output_directory,"/",paths[m],'_', environments[[m]][env], "_bodies_best_",exp,".png",sep=''), format = "png") + + } +} + + +close(file) diff --git a/experiments/karines_experiments/bestrobots_summary_renders.r b/experiments/karines_experiments/bestrobots_summary_renders_journal2_tilted.r similarity index 77% rename from experiments/karines_experiments/bestrobots_summary_renders.r rename to experiments/karines_experiments/bestrobots_summary_renders_journal2_tilted.r index 570110c706..7f33f63c47 100644 --- a/experiments/karines_experiments/bestrobots_summary_renders.r +++ b/experiments/karines_experiments/bestrobots_summary_renders_journal2_tilted.r @@ -5,18 +5,20 @@ require('magick') ##### change paths/labels/params here ##### -paths = c( 'baseline') +paths = c( 'baseline2', 'plastic2') -environments = c( 'plane','tilted5') +environments = list(c( 'plane','tilted5'), + c( 'plane','tilted5') +) -base_directory <- paste('data/old/', sep='') +base_directory <- paste('data/', sep='') -experiments = c(22, 23,24, 25,26,27,29)#c(1:30) -gens = 100 +experiments = c(1:20) +gens = 42#100 pop = 100 -num_top = 3 +num_top = 1 -analysis = 'images' +analysis = 'analysis_journal2_tilted' ##### change paths/labels/params here ##### @@ -32,11 +34,11 @@ for(m in 1:length(paths)) for (exp in experiments) { - input_directory1 <- paste(base_directory, paths[m],'_',exp, '/data_fullevolution/',environments[1],sep='') + input_directory1 <- paste(base_directory, paths[m],'_',exp, '/data_fullevolution/',environments[[m]][1],sep='') input_directory2 <- paste(base_directory, paths[m],'_',exp, '/selectedpop_', sep='') ids_gens = data.frame() - list = strsplit(list.files(paste(input_directory2, environments[1],'/selectedpop_',gens-1, sep='')), ' ') + list = strsplit(list.files(paste(input_directory2, environments[[m]][1],'/selectedpop_',gens-1, sep='')), ' ') for(geno in 1:pop) { genome = data.frame(cbind(c(gens), c(strsplit(strsplit(list [[geno]],'_')[[1]][3],'.png')[[1]][1] ))) @@ -55,9 +57,9 @@ for(m in 1:length(paths)) phenotype= bests[b,'robot_id'] - for (env in 1:length(environments)) + for (env in 1:length(environments[[m]])) { - patha = paste(input_directory2, environments[env], "/selectedpop_",gens-1,sep="") + patha = paste(input_directory2, environments[[m]][env], "/selectedpop_",gens-1,sep="") body <- list.files(patha, paste("body_robot_",phenotype,".png$",sep=""), full.names = TRUE) body = image_read(body) @@ -74,7 +76,7 @@ for(m in 1:length(paths)) } side_by_side = image_append(bodies, stack=F) - image_write(side_by_side, path = paste(output_directory,"/",paths[m],'_', environments[env], "_bodies_best_",exp,".png",sep=''), format = "png") + image_write(side_by_side, path = paste(output_directory,"/",paths[m],'_', environments[[m]][env], "_bodies_best_",exp,".png",sep=''), format = "png") } } diff --git a/experiments/karines_experiments/consolidate_experiments.py b/experiments/karines_experiments/consolidate_experiments.py index fce9458158..995b499084 100644 --- a/experiments/karines_experiments/consolidate_experiments.py +++ b/experiments/karines_experiments/consolidate_experiments.py @@ -4,16 +4,19 @@ # set these variables according to your experiments # dirpath = 'data/' experiments_type = [ - 'baseline2', - 'plastic2' - # 'flat', - # 'tilted' - ] -environments = [ - 'plane', - 'tilted5' - ] -runs = range(1, 11) + 'baseline2', + 'plastic2', + 'flat', + 'tilted' +] +environments = { 'baseline2': ['plane','tilted5'], + 'plastic2': ['plane','tilted5'], + 'flat': ['plane'], + 'tilted': ['tilted5'] + } + +runs = range(1, 21) + # set these variables according to your experiments # @@ -57,7 +60,7 @@ def build_headers(path1, path2): for exp in experiments_type: - for env in environments: + for env in environments[exp]: for run in runs: diff --git a/experiments/karines_experiments/densities_tilted.R b/experiments/karines_experiments/densities_tilted.R new file mode 100644 index 0000000000..2491e45f7e --- /dev/null +++ b/experiments/karines_experiments/densities_tilted.R @@ -0,0 +1,100 @@ + + + library(ggplot2) + library(sqldf) + library(plyr) + library(dplyr) + library(trend) + library(purrr) + + base_directory <- paste('data', sep='') #paste('projects/revolve/experiments/karines_experiments/data', sep='') + + analysis = 'analysis2_plane_tilted' + + output_directory = paste(base_directory,'/',analysis ,sep='') + + #### CHANGE THE PARAMETERS HERE #### + + + experiments_type_colors = c('#FF8000', '#009900') # DARK: green, orange + + experiments_type = c( 'plane', 'tilted5') + + experiments_type_label = c( '2-Plane', '1-Tilted') + + + runs = c(1:60) + gens = 100 + pop = 100 + + #### CHANGE THE PARAMETERS HERE #### + + sig = 0.05 + line_size = 30 + show_markers = TRUE + show_legends = FALSE + + + measures_names = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') + + measures_labels = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') + + measures_snapshots_all = NULL + + for (exp in 1:length(experiments_type)) + { + for(run in runs) + { + input_directory <- paste(base_directory, '/', experiments_type[exp], '_', run, sep='') + measures = read.table(paste(input_directory,"/all_measures.tsv", sep=''), header = TRUE) + for( m in 1:length(measures_names)) + { + measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) + } + + snapshots = read.table(paste(input_directory,"/snapshots_ids.tsv", sep=''), header = TRUE) + measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') + + measures_snapshots$run = run + measures_snapshots$run = as.factor(measures_snapshots$run) + measures_snapshots$method = experiments_type_label[exp] + + if ( is.null(measures_snapshots_all)){ + measures_snapshots_all = measures_snapshots + }else{ + measures_snapshots_all = rbind(measures_snapshots_all, measures_snapshots) + } + } + } + + measures_snapshots_all_final = sqldf("select * from measures_snapshots_all where generation=99") + + + for (i in 1:length(measures_names)) + { + + for (j in 1:length(measures_names)) + { + + if(i != j) + { + + graph <- ggplot(measures_snapshots_all_final, aes_string(x=measures_names[j], y= measures_names[i]))+ + geom_density_2d(aes(colour = method ), alpha=0.7, size=3 )+ + scale_color_manual(values = experiments_type_colors )+ + labs( x = measures_labels[j], y= measures_labels[i] )+ + theme(legend.position="none" , axis.text=element_text(size=21),axis.title=element_text(size=22), + plot.subtitle=element_text(size=25 )) + + coord_cartesian(ylim = c(0, 1), xlim = c(0, 1)) + ggsave(paste( output_directory ,'/',measures_names[i],'_', measures_names[j],'.tiff', sep=''), graph , + device='tiff', height = 6, width = 6) + } + + } + } + + + + + + \ No newline at end of file diff --git a/experiments/karines_experiments/scatter.R b/experiments/karines_experiments/scatter.R index 5a3fb8deda..e5a678305a 100644 --- a/experiments/karines_experiments/scatter.R +++ b/experiments/karines_experiments/scatter.R @@ -4,11 +4,11 @@ library(sqldf) base_directory <-paste('data', sep='') -analysis = 'analysis1' +analysis = 'analysis_journal2_tilted' output_directory = paste(base_directory,'/',analysis ,sep='') -experiments_type = c( 'baseline','plastic') +experiments_type = c( 'baseline2','plastic2') labels_type = c( 'Baseline','Plastic') @@ -17,8 +17,8 @@ environments = c( 'plane','tilted5') labels = c('Speed (cm/s) in Flat', 'Speed (cm/s) in Tilted') -runs = list( c(21:30), - c(21:30)) +runs = list( c(1:20), + c(1:20)) diff --git a/experiments/karines_experiments/scatter2.R b/experiments/karines_experiments/scatter2.R index ab70887559..4203e22a28 100644 --- a/experiments/karines_experiments/scatter2.R +++ b/experiments/karines_experiments/scatter2.R @@ -4,11 +4,11 @@ library(sqldf) base_directory <-paste('data', sep='') -analysis = 'analysis1' +analysis = 'analysis_journal2_tilted' output_directory = paste(base_directory,'/',analysis ,sep='') -experiments_type = c( 'baseline','plastic') +experiments_type = c( 'baseline2','plastic2') labels_type = c( 'Baseline','Plastic') @@ -17,8 +17,8 @@ environments = c( 'plane','tilted5') labels = c('Speed (cm/s) in Flat', 'Speed (cm/s) in Tilted') -runs = list( c(21:30), - c(21:30)) +runs = list( c(1:20), c(1:20)) + @@ -70,7 +70,7 @@ for (exp in 1:length(experiments_type)) graph = ggplot(measures_all, aes(x=speed_plane, y=speed_tilted5, colour=generation.x))+ geom_point(alpha=0.5, size=3)+ labs(subtitle=labels_type[exp], x=labels[1], y=labels[2])+ - coord_cartesian(ylim = c(-5, 5), xlim = c(-5, 5)) + coord_cartesian(ylim = c(-2, 2), xlim = c(-2.5, 3.5)) ggsave(paste( output_directory,'/',experiments_type[exp],'_scatter.pdf', sep=''), graph , device='pdf', height = 10, width = 10) diff --git a/experiments/karines_experiments/summary_measures_journal1_lava.R b/experiments/karines_experiments/summary_measures_journal1_lava.R new file mode 100644 index 0000000000..dbdc8ab835 --- /dev/null +++ b/experiments/karines_experiments/summary_measures_journal1_lava.R @@ -0,0 +1,575 @@ +library(ggplot2) +library(sqldf) +library(plyr) +library(dplyr) +library(trend) +library(purrr) +library(ggsignif) + +base_directory <-paste('data', sep='') + +analysis = 'analysis_journal1_lava' + +output_directory = paste(base_directory,'/',analysis ,sep='') + +#### CHANGE THE PARAMETERS HERE #### + + +experiments_type = c('flat', 'lava','baseline2_lava') + +environments = list( c( 'plane'), + c('lava'), + c( 'plane','lava') ) + +methods = c() +for (exp in 1:length(experiments_type)) +{ + for (env in 1:length(environments[[exp]])) + { + methods = c(methods, paste(experiments_type[exp], environments[[exp]][env], sep='_')) + } +} + +initials = c( 'bp', 'bt', 'pp', 'pt') + +experiments_labels = c( 'Non-S: Flat', 'Non-S: Lava', + 'Seasonal: Flat', 'Seasonal: Lava') + +experiments_labels2 = c( 'Non-S: Flat', 'Non-S: Lava', + 'Seasonal', 'Seasonal') + +runs = list( c(1:20) , + c(1:20) , + c(1:20) ) + +gens = 1#100 +pop = 100 + +#### CHANGE THE PARAMETERS HERE #### + +sig = 0.05 +line_size = 30 +show_markers = TRUE#FALSE +show_legends = FALSE +experiments_type_colors = c( '#00e700' , '#009900', '#ffb83b', '#fd8a3b') # DARK: light green,dark green, light red, dark red + +measures_names = c( + 'displacement_velocity_hill', + 'head_balance', + 'contacts', + 'displacement_velocity', + 'branching', + 'branching_modules_count', + 'limbs', + 'extremities', + 'length_of_limbs', + 'extensiveness', + 'coverage', + 'joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'proportion', + 'width', + 'height', + 'absolute_size', + 'sensors', + 'symmetry', + 'avg_period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'fitness', + 'cons_fitness' +) + +# add proper labels soon... +measures_labels = c( + 'Speed (cm/s)', + 'Balance', + 'Contacts', + 'displacement_velocity', + 'Branching', + 'branching_modules_count', + 'Rel number of limbs', + 'extremities', + 'Rel. Length of Limbs', + 'extensiveness', + 'coverage', + 'Rel. Number of Joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'Proportion', + 'width', + 'height', + 'Size', + 'sensors', + 'Symmetry', + 'Average Period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'Fitness', + 'Number of slaves' +) + + +measures_snapshots_all = NULL + +for (exp in 1:length(experiments_type)) +{ + for(run in runs[[exp]]) + { + for (env in 1:length(environments[[exp]])) + { + input_directory <- paste(base_directory, '/', + experiments_type[exp], '_',sep='') + + measures = read.table(paste(input_directory, run, '/data_fullevolution/', + environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE, fill=TRUE) + for( m in 1:length(measures_names)) + { + measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) + } + + snapshots = read.table(paste(input_directory, run,'/selectedpop_', + environments[[exp]][env],"/snapshots_ids.tsv", sep=''), header = TRUE) + + measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') + + measures_snapshots$run = run + measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 + measures_snapshots$run = as.factor(measures_snapshots$run) + measures_snapshots$method = paste(experiments_type[exp], environments[[exp]][env],sep='_') + + if ( is.null(measures_snapshots_all)){ + measures_snapshots_all = measures_snapshots + }else{ + measures_snapshots_all = rbind(measures_snapshots_all, measures_snapshots) + } + } + } +} + + +fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) + + +measures_snapshots_all = sqldf("select * from measures_snapshots_all where cons_fitness IS NOT NULL") + + +# densities + +measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=42 + and method !='", methods[length(methods)],"'",sep='' )) #99!!!! + +measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') +measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') + +for (i in 1:length(measures_names_densities)) +{ + + for (j in 1:length(measures_names_densities)) + { + + if(i != j) + { + + graph <- ggplot(measures_snapshots_all_densities, aes_string(x=measures_names_densities[j], y= measures_names_densities[i]))+ + geom_density_2d(aes(colour = method ), alpha=0.7, size=3 )+ + scale_color_manual(values = c(experiments_type_colors[4:4], experiments_type_colors[1:2]) )+ + labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ + theme(legend.position="bottom" , axis.text=element_text(size=21),axis.title=element_text(size=22), + plot.subtitle=element_text(size=25 )) + + coord_cartesian(ylim = c(0, 1), xlim = c(0, 1)) + ggsave(paste( output_directory ,'/density_',measures_names_densities[i],'_', measures_names_densities[j],'.png', sep=''), graph , + device='png', height = 6, width = 6) + } + + } +} + + + +measures_averages_gens_1 = list() +measures_averages_gens_2 = list() + +measures_ini = list() +measures_fin = list() + +for (met in 1:length(methods)) +{ + + measures_aux = c() + query ='select run, generation' + for (i in 1:length(measures_names)) + { + query = paste(query,', avg(',measures_names[i],') as ', methods[met], '_',measures_names[i],'_avg', sep='') + } + query = paste(query,' from measures_snapshots_all + where method="', methods[met],'" group by run, generation', sep='') + + temp = sqldf(query) + + measures_averages_gens_1[[met]] = temp + + temp = measures_averages_gens_1[[met]] + + temp$generation = as.numeric(temp$generation) + + measures_ini[[met]] = sqldf(paste("select * from temp where generation=0")) + measures_fin[[met]] = sqldf(paste("select * from temp where generation=",gens-1)) + query = 'select generation' + for (i in 1:length(measures_names)) + { + # later renames vars _avg_SUMMARY, just to make it in the same style as the quantile variables + query = paste(query,', avg(', methods[met], '_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_avg', sep='') + query = paste(query,', max(', methods[met],'_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_max', sep='') + query = paste(query,', stdev(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_stdev', sep='') + query = paste(query,', median(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_median', sep='') + + measures_aux = c(measures_aux, paste(methods[met],'_',measures_names[i],'_avg', sep='') ) + } + query = paste(query,' from temp group by generation', sep="") + + temp2 = sqldf(query) + + p <- c(0.25, 0.75) + p_names <- map_chr(p, ~paste0('Q',.x*100, sep="")) + p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>% + set_names(nm = p_names) + + quantiles = data.frame(temp %>% + group_by(generation) %>% + summarize_at(vars(measures_aux), funs(!!!p_funs)) ) + + measures_averages_gens_2[[met]] = sqldf('select * from temp2 inner join quantiles using (generation)') + +} + + +for (met in 1:length(methods)) +{ + if(met==1){ + measures_averages_gens = measures_averages_gens_2[[1]] + }else{ + measures_averages_gens = merge(measures_averages_gens, measures_averages_gens_2[[met]], all=TRUE, by = "generation") + } +} + +file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") + +#tests trends in curves and difference between ini and fin generations + + +# ini VS fin +array_wilcoxon = list() +array_wilcoxon2 = list() + +# curve +array_mann = list() + + +for (m in 1:length(methods)) +{ + + array_wilcoxon[[m]] = list() + array_mann[[m]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(experiments_type[m],measures_names[i],'ini avg ',as.character( + mean(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon[[m]][[i]] = wilcox.test(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'iniVSfin',measures_names[i],'wilcox p: ',as.character(round(array_wilcoxon[[m]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'iniVSfin',measures_names[i],'wilcox est: ',as.character(round(array_wilcoxon[[m]][[i]]$statistic,4)), sep=' ') + + ), file) + + + #tests trends + array_mann[[m]][[i]] = mk.test(c(array(measures_averages_gens_2[[m]][paste(methods[m],"_",measures_names[i],'_median',sep='')]) )[[1]], + continuity = TRUE) + + + writeLines(c( + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median p', as.character(round(array_mann[[m]][[i]]$p.value,4)),sep=' '), + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median s', as.character(round(array_mann[[m]][[i]]$statistic,4)),sep=' ') + ), file) + + } + +} + + + +# tests final generation among experiments_type + +aux_m = length(methods) + +if (aux_m>1) +{ + + # fins + array_wilcoxon2[[1]] = list() + array_wilcoxon2[[2]] = list() + + aux_m = aux_m -1 + count_pairs = 0 + for(m in 1:aux_m) + { + aux = m+1 + for(m2 in aux:length(methods)) + { + + count_pairs = count_pairs+1 + array_wilcoxon2[[1]][[count_pairs]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + writeLines(paste(methods[m2],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon2[[1]][[count_pairs]][[i]] = wilcox.test(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'VS',methods,measures_names[i],'fin avg wilcox p: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'VS',methods[m2],measures_names[i],'fin avg wilcox est: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$statistic,4)), sep=' ') + + ), file) + + } + + + array_wilcoxon2[[2]][[count_pairs]] = paste(initials[m],initials[m2],sep='') + + } + } + +} + +close(file) + +# plots measures + +for (type_summary in c('means','quants')) +{ + + + for (i in 1:length(measures_names)) + { + tests1 = '' + tests2 = '' + tests3 = '' + break_aux = 0 + + graph <- ggplot(data=measures_averages_gens, aes(x=generation)) + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg','-',methods[m],'_',measures_names[i],'_stdev',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg','+',methods[m],'_',measures_names[i],'_stdev',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + }else + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg_Q25',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg_Q75',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + } + } + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) + } + + }else{ + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') , colour=shQuote(experiments_labels[m]) ),size=2 ) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') ),size=2, color = experiments_type_colors[m] ) + } + } + + if (length(array_mann)>0) + { + if (length(array_mann[[m]])>0) + { + if(!is.na(array_mann[[m]][[i]]$p.value)) + { + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } + } + } + } + } + + if (length(array_wilcoxon[[m]])>0) + { + for(m in 1:length(methods)) + { + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + { + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } + } + } + } + + if (length(array_wilcoxon2)>0) + { + for(p in 1:length(array_wilcoxon2[[1]])) + { + if (length(array_wilcoxon2[[1]][[p]])>0) + { + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + { + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') + } + } + } + } + } + + max_y = 0 + min_y = 0 + if(measures_names[i]=='displacement_velocity_hill' ){ + max_y = 3 + min_y = -0.5 + } + + graph = graph + labs( y=measures_labels[i], x="Generation") + if (max_y>0) { + graph = graph + coord_cartesian(ylim = c(min_y, max_y)) + } + + if(show_markers == TRUE){ + graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) + } + graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=30),axis.title=element_text(size=39), + plot.subtitle=element_text(size=25 )) + + ggsave(paste( output_directory,'/',type_summary,'_' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 10, width = 10) + } + +} + + + + +for (i in 1:length(measures_names)) +{ + + all_final_values = data.frame() + if (measures_names[i] == 'displacement_velocity_hill') { fin=length(methods) + }else{ fin=length(methods)-1 } + + for (exp in 1:fin) + { + temp = data.frame( c(measures_fin[[exp]][paste(methods[exp],'_',measures_names[i],'_avg', sep='')])) + colnames(temp) <- 'values' + if (measures_names[i] == 'displacement_velocity_hill') { temp$type = experiments_labels[exp] + }else{ temp$type = experiments_labels2[exp] } + + all_final_values = rbind(all_final_values, temp) + } + + + max_y = 0 + # if(measures_names[i]=='proportion' || measures_names[i]=='head_balance' || measures_names[i]=='joints' ){ max_y = 1.1 } + + g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4, notch=TRUE) + + labs( x="Environment", y=measures_labels[i], title="Final generation") + + if (measures_names[i] == 'displacement_velocity_hill') { g1 = g1 + scale_color_manual(values=experiments_type_colors) + }else{ g1 = g1 + scale_color_manual(values= c(experiments_type_colors[1:2],experiments_type_colors[4:4])) } + + g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , + plot.title=element_text(size=40), axis.text=element_text(size=45), + axis.title=element_text(size=50), + axis.text.x = element_text(angle = 20, hjust = 1 ), + plot.margin=margin(t = 0.5, r = 0.5, b = 0.5, l = 0.5, unit = "cm") + )+ + stat_summary(fun.y = mean, geom="point" ,shape = 16, size=11) + + if (measures_names[i] == 'displacement_velocity_hill') { comps = list(c("Non-S: Flat", "Seasonal: Flat"), + c("Non-S: Lava", "Seasonal: Lava"), + c("Non-S: Lava", "Non-S: Flat"), + c("Seasonal: Lava", "Seasonal: Flat")) + aux_width=13 + }else{ comps = list(c("Non-S: Flat", "Non-S: Lava"), + c("Non-S: Flat", "Seasonal"), + c("Non-S: Lava", "Seasonal")) + aux_width=10 + } + + + g1 = g1 + geom_signif( test="wilcox.test", size=2, textsize=22, + comparisons = comps, + map_signif_level=c("***"=0.001,"**"=0.01, "*"=0.05) ) + if (max_y>0) { + g1 = g1 + coord_cartesian(ylim = c(0, max_y)) + } + + ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = aux_width) + +} + diff --git a/experiments/karines_experiments/summary_measures_journal1_tilted.R b/experiments/karines_experiments/summary_measures_journal1_tilted.R index 892cb13ce6..34f78e6244 100644 --- a/experiments/karines_experiments/summary_measures_journal1_tilted.R +++ b/experiments/karines_experiments/summary_measures_journal1_tilted.R @@ -137,7 +137,6 @@ measures_snapshots_all = NULL for (exp in 1:length(experiments_type)) { - #for(run in runs) for(run in runs[[exp]]) { for (env in 1:length(environments[[exp]])) @@ -146,7 +145,7 @@ for (exp in 1:length(experiments_type)) experiments_type[exp], '_',sep='') measures = read.table(paste(input_directory, run, '/data_fullevolution/', - environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE) + environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE, fill=TRUE) for( m in 1:length(measures_names)) { measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) @@ -179,6 +178,40 @@ measures_snapshots_all = sqldf("select * from measures_snapshots_all where cons_ + +# densities + +measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=42 + and method !='", methods[length(methods)],"'",sep='' )) #99!!!! + +measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') +measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') + +for (i in 1:length(measures_names_densities)) +{ + + for (j in 1:length(measures_names_densities)) + { + + if(i != j) + { + + graph <- ggplot(measures_snapshots_all_densities, aes_string(x=measures_names_densities[j], y= measures_names_densities[i]))+ + geom_density_2d(aes(colour = method ), alpha=0.7, size=3 )+ + scale_color_manual(values = c(experiments_type_colors[4:4], experiments_type_colors[1:2]) )+ + labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ + theme(legend.position="bottom" , axis.text=element_text(size=21),axis.title=element_text(size=22), + plot.subtitle=element_text(size=25 )) + + coord_cartesian(ylim = c(0, 1), xlim = c(0, 1)) + ggsave(paste( output_directory ,'/density_',measures_names_densities[i],'_', measures_names_densities[j],'.png', sep=''), graph , + device='png', height = 6, width = 6) + } + + } +} + + + measures_averages_gens_1 = list() measures_averages_gens_2 = list() @@ -458,11 +491,15 @@ for (type_summary in c('means','quants')) } max_y = 0 - #if(measures_names[i]=='proportion' || measures_names[i]=='balance' || measures_names[i]=='joints' ){ max_y = 1.1 } + min_y = 0 + if(measures_names[i]=='displacement_velocity_hill' ){ + max_y = 3 + min_y = -0.5 + } graph = graph + labs( y=measures_labels[i], x="Generation") if (max_y>0) { - graph = graph + coord_cartesian(ylim = c(0, max_y)) + graph = graph + coord_cartesian(ylim = c(min_y, max_y)) } if(show_markers == TRUE){ diff --git a/experiments/karines_experiments/summary_measures_journal2_lava.R b/experiments/karines_experiments/summary_measures_journal2_lava.R new file mode 100644 index 0000000000..58ebe2efa3 --- /dev/null +++ b/experiments/karines_experiments/summary_measures_journal2_lava.R @@ -0,0 +1,566 @@ + library(ggplot2) + library(sqldf) + library(plyr) + library(dplyr) + library(trend) + library(purrr) + library(ggsignif) + + base_directory <-paste('data', sep='') + +analysis = 'analysis_journal2_lava' + +output_directory = paste(base_directory,'/',analysis ,sep='') + +#### CHANGE THE PARAMETERS HERE #### + + +experiments_type = c( 'baseline2_lava', 'plastic2_lava') + +environments = list(c( 'plane','lava'), c( 'plane','lava') ) + +methods = c() +for (exp in 1:length(experiments_type)) +{ + for (env in 1:length(environments[[exp]])) + { + methods = c(methods, paste(experiments_type[exp], environments[[exp]][env], sep='_')) + } +} + +initials = c( 'bp', 'bt', 'pp', 'pt') + +experiments_labels = c( 'Baseline: Flat', 'Baseline: Lava', + 'Plastic: Flat', 'Plastic: Lava') + +experiments_labels2 = c( 'Baseline', 'Baseline', + 'Plastic: Flat', 'Plastic: Lava') + + runs = list( c(1:20), c(1:20) ) + + gens = 10#100 + pop = 100 + + #### CHANGE THE PARAMETERS HERE #### + + sig = 0.05 + line_size = 30 + show_markers = TRUE#FALSE + show_legends = FALSE + experiments_type_colors = c( '#00e700' , '#009900', '#ffb83b', '#fd8a3b') # DARK: light green,dark green, light red, dark red + + measures_names = c( + 'displacement_velocity_hill', + 'head_balance', + 'contacts', + 'displacement_velocity', + 'branching', + 'branching_modules_count', + 'limbs', + 'extremities', + 'length_of_limbs', + 'extensiveness', + 'coverage', + 'joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'proportion', + 'width', + 'height', + 'absolute_size', + 'sensors', + 'symmetry', + 'avg_period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'fitness', + 'cons_fitness' + ) + + # add proper labels soon... + measures_labels = c( + 'Speed (cm/s)', + 'Balance', + 'Contacts', + 'displacement_velocity', + 'Branching', + 'branching_modules_count', + 'Rel number of limbs', + 'extremities', + 'Rel. Length of Limbs', + 'extensiveness', + 'coverage', + 'Rel. Number of Joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'Proportion', + 'width', + 'height', + 'Size', + 'sensors', + 'Symmetry', + 'Average Period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'Fitness', + 'Number of slaves' + ) + + + measures_snapshots_all = NULL + + for (exp in 1:length(experiments_type)) + { + for(run in runs[[exp]]) + { + for (env in 1:length(environments[[exp]])) + { + input_directory <- paste(base_directory, '/', + experiments_type[exp], '_',sep='') + + measures = read.table(paste(input_directory, run, '/data_fullevolution/', + environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE, fill=TRUE) + for( m in 1:length(measures_names)) + { + measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) + } + + snapshots = read.table(paste(input_directory, run,'/selectedpop_', + environments[[exp]][env],"/snapshots_ids.tsv", sep=''), header = TRUE) + + measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') + + measures_snapshots$run = run + measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 + measures_snapshots$run = as.factor(measures_snapshots$run) + measures_snapshots$method = paste(experiments_type[exp], environments[[exp]][env],sep='_') + + if ( is.null(measures_snapshots_all)){ + measures_snapshots_all = measures_snapshots + }else{ + measures_snapshots_all = rbind(measures_snapshots_all, measures_snapshots) + } + } + } + } + + + fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) + + + measures_snapshots_all = sqldf("select * from measures_snapshots_all where cons_fitness IS NOT NULL") + + + # densities + + measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=42 + and method !='", methods[length(methods)],"'",sep='' )) #99!!!! + + measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') + measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') + + for (i in 1:length(measures_names_densities)) + { + + for (j in 1:length(measures_names_densities)) + { + + if(i != j) + { + + graph <- ggplot(measures_snapshots_all_densities, aes_string(x=measures_names_densities[j], y= measures_names_densities[i]))+ + geom_density_2d(aes(colour = method ), alpha=0.7, size=3 )+ + scale_color_manual(values = experiments_type_colors[-1] )+ + labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ + theme(legend.position="bottom" , axis.text=element_text(size=21),axis.title=element_text(size=22), + plot.subtitle=element_text(size=25 )) + + coord_cartesian(ylim = c(0, 1), xlim = c(0, 1)) + ggsave(paste( output_directory ,'/density_',measures_names_densities[i],'_', measures_names_densities[j],'.png', sep=''), graph , + device='png', height = 6, width = 6) + } + + } + } + + + + measures_averages_gens_1 = list() + measures_averages_gens_2 = list() + + measures_ini = list() + measures_fin = list() + + for (met in 1:length(methods)) + { + + measures_aux = c() + query ='select run, generation' + for (i in 1:length(measures_names)) + { + query = paste(query,', avg(',measures_names[i],') as ', methods[met], '_',measures_names[i],'_avg', sep='') + } + query = paste(query,' from measures_snapshots_all + where method="', methods[met],'" group by run, generation', sep='') + + temp = sqldf(query) + + measures_averages_gens_1[[met]] = temp + + temp = measures_averages_gens_1[[met]] + + temp$generation = as.numeric(temp$generation) + + measures_ini[[met]] = sqldf(paste("select * from temp where generation=0")) + measures_fin[[met]] = sqldf(paste("select * from temp where generation=",gens-1)) + query = 'select generation' + for (i in 1:length(measures_names)) + { + # later renames vars _avg_SUMMARY, just to make it in the same style as the quantile variables + query = paste(query,', avg(', methods[met], '_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_avg', sep='') + query = paste(query,', max(', methods[met],'_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_max', sep='') + query = paste(query,', stdev(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_stdev', sep='') + query = paste(query,', median(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_median', sep='') + + measures_aux = c(measures_aux, paste(methods[met],'_',measures_names[i],'_avg', sep='') ) + } + query = paste(query,' from temp group by generation', sep="") + + temp2 = sqldf(query) + + p <- c(0.25, 0.75) + p_names <- map_chr(p, ~paste0('Q',.x*100, sep="")) + p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>% + set_names(nm = p_names) + + quantiles = data.frame(temp %>% + group_by(generation) %>% + summarize_at(vars(measures_aux), funs(!!!p_funs)) ) + + measures_averages_gens_2[[met]] = sqldf('select * from temp2 inner join quantiles using (generation)') + + } + + + for (met in 1:length(methods)) + { + if(met==1){ + measures_averages_gens = measures_averages_gens_2[[1]] + }else{ + measures_averages_gens = merge(measures_averages_gens, measures_averages_gens_2[[met]], by = "generation") + } + } + + file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") + + #tests trends in curves and difference between ini and fin generations + + + # ini VS fin + array_wilcoxon = list() + array_wilcoxon2 = list() + + # curve + array_mann = list() + + + for (m in 1:length(methods)) + { + + array_wilcoxon[[m]] = list() + array_mann[[m]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(experiments_type[m],measures_names[i],'ini avg ',as.character( + mean(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon[[m]][[i]] = wilcox.test(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'iniVSfin',measures_names[i],'wilcox p: ',as.character(round(array_wilcoxon[[m]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'iniVSfin',measures_names[i],'wilcox est: ',as.character(round(array_wilcoxon[[m]][[i]]$statistic,4)), sep=' ') + + ), file) + + + #tests trends + array_mann[[m]][[i]] = mk.test(c(array(measures_averages_gens_2[[m]][paste(methods[m],"_",measures_names[i],'_median',sep='')]) )[[1]], + continuity = TRUE) + + + writeLines(c( + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median p', as.character(round(array_mann[[m]][[i]]$p.value,4)),sep=' '), + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median s', as.character(round(array_mann[[m]][[i]]$statistic,4)),sep=' ') + ), file) + + } + + } + + + + # tests final generation among experiments_type + + aux_m = length(methods) + + if (aux_m>1) + { + + # fins + array_wilcoxon2[[1]] = list() + array_wilcoxon2[[2]] = list() + + aux_m = aux_m -1 + count_pairs = 0 + for(m in 1:aux_m) + { + aux = m+1 + for(m2 in aux:length(methods)) + { + + count_pairs = count_pairs+1 + array_wilcoxon2[[1]][[count_pairs]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + writeLines(paste(methods[m2],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon2[[1]][[count_pairs]][[i]] = wilcox.test(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'VS',methods,measures_names[i],'fin avg wilcox p: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'VS',methods[m2],measures_names[i],'fin avg wilcox est: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$statistic,4)), sep=' ') + + ), file) + + } + + + array_wilcoxon2[[2]][[count_pairs]] = paste(initials[m],initials[m2],sep='') + + } + } + + } + + close(file) + + # plots measures + + for (type_summary in c('means','quants')) + { + + + for (i in 1:length(measures_names)) + { + tests1 = '' + tests2 = '' + tests3 = '' + break_aux = 0 + + graph <- ggplot(data=measures_averages_gens, aes(x=generation)) + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg','-',methods[m],'_',measures_names[i],'_stdev',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg','+',methods[m],'_',measures_names[i],'_stdev',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + }else + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg_Q25',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg_Q75',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + } + } + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) + } + + }else{ + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') , colour=shQuote(experiments_labels[m]) ),size=2 ) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') ),size=2, color = experiments_type_colors[m] ) + } + } + + if (length(array_mann)>0) + { + if (length(array_mann[[m]])>0) + { + if(!is.na(array_mann[[m]][[i]]$p.value)) + { + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } + } + } + } + } + + if (length(array_wilcoxon[[m]])>0) + { + for(m in 1:length(methods)) + { + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + { + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } + } + } + } + + if (length(array_wilcoxon2)>0) + { + for(p in 1:length(array_wilcoxon2[[1]])) + { + if (length(array_wilcoxon2[[1]][[p]])>0) + { + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + { + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') + } + } + } + } + } + + max_y = 0 + min_y = 0 + if(measures_names[i]=='displacement_velocity_hill' ){ + max_y = 3 + min_y = -0.5 + } + + graph = graph + labs( y=measures_labels[i], x="Generation") + if (max_y>0) { + graph = graph + coord_cartesian(ylim = c(min_y, max_y)) + } + + if(show_markers == TRUE){ + graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) + } + graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=30),axis.title=element_text(size=39), + plot.subtitle=element_text(size=25 )) + + ggsave(paste( output_directory,'/',type_summary,'_' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 10, width = 10) + } + + } + + + + + for (i in 1:length(measures_names)) + { + + all_final_values = data.frame() + if (measures_names[i] == 'displacement_velocity_hill') { ini=1 + }else{ ini=2 } + + for (exp in ini:length(methods)) + { + temp = data.frame( c(measures_fin[[exp]][paste(methods[exp],'_',measures_names[i],'_avg', sep='')])) + colnames(temp) <- 'values' + if (measures_names[i] == 'displacement_velocity_hill') { temp$type = experiments_labels[exp] + }else{ temp$type = experiments_labels2[exp] } + + all_final_values = rbind(all_final_values, temp) + } + + + max_y = 0 + # min_y = -0.5 + #if(measures_names[i]=='displacement_velocity_hill' ){ max_y = 3 } + + g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4, notch=TRUE) + + labs( x="Environment", y=measures_labels[i], title="Final generation") + + if (measures_names[i] == 'displacement_velocity_hill') { g1 = g1 + scale_color_manual(values=experiments_type_colors) + }else{ g1 = g1 + scale_color_manual(values=experiments_type_colors[-1]) } + + g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , + plot.title=element_text(size=40), axis.text=element_text(size=45), + axis.title=element_text(size=50), + axis.text.x = element_text(angle = 20, hjust = 1))+ + stat_summary(fun.y = mean, geom="point" ,shape = 16, size=11) + + if (measures_names[i] == 'displacement_velocity_hill') { comps = list(c("Baseline: Flat", "Plastic: Flat"), + c("Baseline: Lava", "Plastic: Lava")) + }else{ comps = list(c("Baseline", "Plastic: Flat"), + c("Baseline", "Plastic: Lava"), + c("Plastic: Flat", "Plastic: Lava")) } + + + g1 = g1 + geom_signif( test="wilcox.test", size=2, textsize=22, + comparisons = comps, + map_signif_level=c("***"=0.001,"**"=0.01, "*"=0.05) ) + if (max_y>0) { + g1 = g1 + coord_cartesian(ylim = c(0, max_y)) + } + + ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = 10) + + } + + \ No newline at end of file diff --git a/experiments/karines_experiments/summary_measures_journal2_tilted.R b/experiments/karines_experiments/summary_measures_journal2_tilted.R index 3cc570b9a9..76bd8a5c6d 100644 --- a/experiments/karines_experiments/summary_measures_journal2_tilted.R +++ b/experiments/karines_experiments/summary_measures_journal2_tilted.R @@ -133,7 +133,6 @@ experiments_labels2 = c( 'Baseline', 'Baseline', for (exp in 1:length(experiments_type)) { - #for(run in runs) for(run in runs[[exp]]) { for (env in 1:length(environments[[exp]])) @@ -142,7 +141,7 @@ experiments_labels2 = c( 'Baseline', 'Baseline', experiments_type[exp], '_',sep='') measures = read.table(paste(input_directory, run, '/data_fullevolution/', - environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE) + environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE, fill=TRUE) for( m in 1:length(measures_names)) { measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) @@ -175,6 +174,39 @@ experiments_labels2 = c( 'Baseline', 'Baseline', + # densities + + measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=42 + and method !='", methods[1],"'",sep='' )) #99!!!! + + measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') + measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') + + for (i in 1:length(measures_names_densities)) + { + + for (j in 1:length(measures_names_densities)) + { + + if(i != j) + { + + graph <- ggplot(measures_snapshots_all_densities, aes_string(x=measures_names_densities[j], y= measures_names_densities[i]))+ + geom_density_2d(aes(colour = method ), alpha=0.7, size=3 )+ + scale_color_manual(values = experiments_type_colors[-1] )+ + labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ + theme(legend.position="bottom" , axis.text=element_text(size=21),axis.title=element_text(size=22), + plot.subtitle=element_text(size=25 )) + + coord_cartesian(ylim = c(0, 1), xlim = c(0, 1)) + ggsave(paste( output_directory ,'/density_',measures_names_densities[i],'_', measures_names_densities[j],'.png', sep=''), graph , + device='png', height = 6, width = 6) + } + + } + } + + + measures_averages_gens_1 = list() measures_averages_gens_2 = list() @@ -454,11 +486,15 @@ experiments_labels2 = c( 'Baseline', 'Baseline', } max_y = 0 - #if(measures_names[i]=='proportion' || measures_names[i]=='balance' || measures_names[i]=='joints' ){ max_y = 1.1 } - + min_y = 0 + if(measures_names[i]=='displacement_velocity_hill' ){ + max_y = 3 + min_y = -0.5 + } + graph = graph + labs( y=measures_labels[i], x="Generation") if (max_y>0) { - graph = graph + coord_cartesian(ylim = c(0, max_y)) + graph = graph + coord_cartesian(ylim = c(min_y, max_y)) } if(show_markers == TRUE){ @@ -494,7 +530,8 @@ experiments_labels2 = c( 'Baseline', 'Baseline', max_y = 0 - # if(measures_names[i]=='proportion' || measures_names[i]=='head_balance' || measures_names[i]=='joints' ){ max_y = 1.1 } + # min_y = -0.5 + #if(measures_names[i]=='displacement_velocity_hill' ){ max_y = 3 } g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4, notch=TRUE) + @@ -522,7 +559,7 @@ experiments_labels2 = c( 'Baseline', 'Baseline', if (max_y>0) { g1 = g1 + coord_cartesian(ylim = c(0, max_y)) } - g1 + ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = 10) } From 26e88fd237020804e685e5bb74215c782a57c4c3 Mon Sep 17 00:00:00 2001 From: Karine Date: Mon, 27 Jan 2020 15:39:19 +0100 Subject: [PATCH 35/45] fix scripts and put lava back --- experiments/karines_experiments/baseline2.py | 6 +- .../karines_experiments/baseline2_lava.py | 8 +- ...strobots_summary_renders_journal1_tilted.r | 2 +- .../consolidate_experiments.py | 23 ++-- experiments/karines_experiments/flat.py | 4 +- experiments/karines_experiments/lava.py | 4 +- experiments/karines_experiments/plastic2.py | 5 +- .../karines_experiments/run-experiments | 128 ++++++++++++++++++ .../summary_measures_journal1_tilted.R | 38 +++--- .../summary_measures_journal2_tilted.R | 28 ++-- experiments/karines_experiments/tilted.py | 4 +- pyrevolve/angle/manage/world.py | 52 +++---- pyrevolve/evolution/population.py | 24 +++- pyrevolve/tol/manage/measures.py | 2 +- 14 files changed, 242 insertions(+), 86 deletions(-) diff --git a/experiments/karines_experiments/baseline2.py b/experiments/karines_experiments/baseline2.py index 346ac36b32..8be050dec6 100755 --- a/experiments/karines_experiments/baseline2.py +++ b/experiments/karines_experiments/baseline2.py @@ -68,11 +68,15 @@ async def run(): gen_num = 0 next_robot_id = 1 - def fitness_function(robot_manager, robot): + def fitness_function_plane(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) return fitness.displacement_velocity_hill(robot_manager, robot, False) + + fitness_function = {'plane': fitness_function_plane, + 'tilted5': fitness_function_plane} + population_conf = PopulationConfig( population_size=population_size, genotype_constructor=random_initialization, diff --git a/experiments/karines_experiments/baseline2_lava.py b/experiments/karines_experiments/baseline2_lava.py index c95bebcf9c..9c684a33a7 100755 --- a/experiments/karines_experiments/baseline2_lava.py +++ b/experiments/karines_experiments/baseline2_lava.py @@ -69,8 +69,8 @@ async def run(): next_robot_id = 1 def fitness_function_plane(robot_manager, robot): - contacts = measures.contacts(robot_manager, robot) - assert(contacts != 0) + #contacts = measures.contacts(robot_manager, robot) + #assert(contacts != 0) return fitness.displacement_velocity_hill(robot_manager, robot, False) def fitness_function_lava(robot_manager, robot): @@ -78,14 +78,14 @@ def fitness_function_lava(robot_manager, robot): assert(contacts != 0) return fitness.floor_is_lava(robot_manager, robot, False) - fitness_functions = {'plane': fitness_function_plane, + fitness_function = {'plane': fitness_function_plane, 'lava': fitness_function_lava} population_conf = PopulationConfig( population_size=population_size, genotype_constructor=random_initialization, genotype_conf=genotype_conf, - fitness_function=fitness_functions, + fitness_function=fitness_function, mutation_operator=standard_mutation, mutation_conf=mutation_conf, crossover_operator=standard_crossover, diff --git a/experiments/karines_experiments/bestrobots_summary_renders_journal1_tilted.r b/experiments/karines_experiments/bestrobots_summary_renders_journal1_tilted.r index 32668b1e5a..89f7fcdc8e 100644 --- a/experiments/karines_experiments/bestrobots_summary_renders_journal1_tilted.r +++ b/experiments/karines_experiments/bestrobots_summary_renders_journal1_tilted.r @@ -15,7 +15,7 @@ environments = list(c( 'plane'), base_directory <- paste('data/', sep='') experiments = c(1:20) -gens = 42#100 +gens = 100 pop = 100 num_top = 1 diff --git a/experiments/karines_experiments/consolidate_experiments.py b/experiments/karines_experiments/consolidate_experiments.py index 995b499084..4fe53384ac 100644 --- a/experiments/karines_experiments/consolidate_experiments.py +++ b/experiments/karines_experiments/consolidate_experiments.py @@ -4,15 +4,22 @@ # set these variables according to your experiments # dirpath = 'data/' experiments_type = [ - 'baseline2', - 'plastic2', - 'flat', - 'tilted' + # 'baseline2', + # 'plastic2', + # 'flat', + # 'tilted' + 'lava', + 'baseline2_lava', + 'plastic2_lava' ] -environments = { 'baseline2': ['plane','tilted5'], - 'plastic2': ['plane','tilted5'], - 'flat': ['plane'], - 'tilted': ['tilted5'] +environments = { + # 'baseline2': ['plane','tilted5'], + # 'plastic2': ['plane','tilted5'], + # 'flat': ['plane'], + # 'tilted': ['tilted5'], + 'baseline2': ['plane','lava'], + 'plastic2': ['plane','lava'], + 'lava': ['lava'] } runs = range(1, 21) diff --git a/experiments/karines_experiments/flat.py b/experiments/karines_experiments/flat.py index a7a10ca1a1..e96146b204 100755 --- a/experiments/karines_experiments/flat.py +++ b/experiments/karines_experiments/flat.py @@ -66,11 +66,13 @@ async def run(): gen_num = 0 next_robot_id = 1 - def fitness_function(robot_manager, robot): + def fitness_function_plane(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) return fitness.displacement_velocity_hill(robot_manager, robot, False) + fitness_function = {'plane': fitness_function_plane} + population_conf = PopulationConfig( population_size=population_size, genotype_constructor=random_initialization, diff --git a/experiments/karines_experiments/lava.py b/experiments/karines_experiments/lava.py index e0b8d01626..cff2367289 100755 --- a/experiments/karines_experiments/lava.py +++ b/experiments/karines_experiments/lava.py @@ -71,13 +71,13 @@ def fitness_function_lava(robot_manager, robot): assert(contacts != 0) return fitness.floor_is_lava(robot_manager, robot, False) - fitness_functions = {'lava': fitness_function_lava} + fitness_function = {'lava': fitness_function_lava} population_conf = PopulationConfig( population_size=population_size, genotype_constructor=random_initialization, genotype_conf=genotype_conf, - fitness_function=fitness_functions, + fitness_function=fitness_function, mutation_operator=standard_mutation, mutation_conf=mutation_conf, crossover_operator=standard_crossover, diff --git a/experiments/karines_experiments/plastic2.py b/experiments/karines_experiments/plastic2.py index 5289307500..0e4385be1a 100755 --- a/experiments/karines_experiments/plastic2.py +++ b/experiments/karines_experiments/plastic2.py @@ -69,11 +69,14 @@ async def run(): gen_num = 0 next_robot_id = 1 - def fitness_function(robot_manager, robot): + def fitness_function_plane(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) return fitness.displacement_velocity_hill(robot_manager, robot, False) + fitness_function = {'plane': fitness_function_plane, + 'tilted5': fitness_function_plane} + population_conf = PopulationConfig( population_size=population_size, genotype_constructor=random_initialization, diff --git a/experiments/karines_experiments/run-experiments b/experiments/karines_experiments/run-experiments index 92f4f00b33..27b46e2f08 100755 --- a/experiments/karines_experiments/run-experiments +++ b/experiments/karines_experiments/run-experiments @@ -125,6 +125,134 @@ while true done +while true + do + for i in {1..5}; do + ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/lava.py --n-cores 4 --port-start 11111 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {6..10}; do + ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/lava.py --n-cores 4 --port-start 11121 --evaluation-time 50; + + sleep 5s + done +done + + + +while true + do + for i in {11..15}; do + ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/lava.py --n-cores 4 --port-start 11131 --evaluation-time 50; + + sleep 5s + done +done + + + +while true + do + for i in {16..20}; do + ./revolve.py --experiment-name karines_experiments/data/lava_$i --run $i --manager experiments/karines_experiments/lava.py --n-cores 4 --port-start 11141 --evaluation-time 50; + + sleep 5s + done +done + +### + + +while true + do + for i in {1..2}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_lava_$i --run $i --manager experiments/karines_experiments/baseline2_lava.py --n-cores 4 --port-start 11111 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {3..4}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_lava_$i --run $i --manager experiments/karines_experiments/baseline2_lava.py --n-cores 4 --port-start 11121 --evaluation-time 50; + + sleep 5s + done +done + + + +while true + do + for i in {5..6}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_lava_$i --run $i --manager experiments/karines_experiments/baseline2_lava.py --n-cores 4 --port-start 11131 --evaluation-time 50; + + sleep 5s + done +done + + + +while true + do + for i in {7..8}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_lava_$i --run $i --manager experiments/karines_experiments/baseline2_lava.py --n-cores 4 --port-start 11141 --evaluation-time 50; + + sleep 5s + done +done + +while true + do + for i in {9..11}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_lava_$i --run $i --manager experiments/karines_experiments/baseline2_lava.py --n-cores 4 --port-start 11151 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {12..14}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_lava_$i --run $i --manager experiments/karines_experiments/baseline2_lava.py --n-cores 4 --port-start 11161 --evaluation-time 50; + + sleep 5s + done +done + + + +while true + do + for i in {15..17}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_lava_$i --run $i --manager experiments/karines_experiments/baseline2_lava.py --n-cores 4 --port-start 11171 --evaluation-time 50; + + sleep 5s + done +done + + + +while true + do + for i in {18..20}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_lava_$i --run $i --manager experiments/karines_experiments/baseline2_lava.py --n-cores 4 --port-start 11181 --evaluation-time 50; + + sleep 5s + done +done + + + while true do sleep 900s; diff --git a/experiments/karines_experiments/summary_measures_journal1_tilted.R b/experiments/karines_experiments/summary_measures_journal1_tilted.R index 34f78e6244..a57ff469ef 100644 --- a/experiments/karines_experiments/summary_measures_journal1_tilted.R +++ b/experiments/karines_experiments/summary_measures_journal1_tilted.R @@ -42,14 +42,14 @@ runs = list( c(1:20) , c(1:20) , c(1:20) ) -gens = 1#100 +gens = 100 pop = 100 #### CHANGE THE PARAMETERS HERE #### sig = 0.05 line_size = 30 -show_markers = TRUE#FALSE +show_markers = FALSE show_legends = FALSE experiments_type_colors = c( '#00e700' , '#009900', '#ffb83b', '#fd8a3b') # DARK: light green,dark green, light red, dark red @@ -174,15 +174,15 @@ for (exp in 1:length(experiments_type)) fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) -measures_snapshots_all = sqldf("select * from measures_snapshots_all where cons_fitness IS NOT NULL") +measures_snapshots_all = sqldf("select * from measures_snapshots_all where generation<=99 and cons_fitness IS NOT NULL") # densities -measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=42 - and method !='", methods[length(methods)],"'",sep='' )) #99!!!! +measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=99 + and method !='", methods[length(methods)],"'",sep='' )) measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') @@ -391,6 +391,8 @@ if (aux_m>1) close(file) + + # plots measures for (type_summary in c('means','quants')) @@ -490,12 +492,7 @@ for (type_summary in c('means','quants')) } } - max_y = 0 - min_y = 0 - if(measures_names[i]=='displacement_velocity_hill' ){ - max_y = 3 - min_y = -0.5 - } + max_y = 0 graph = graph + labs( y=measures_labels[i], x="Generation") if (max_y>0) { @@ -520,39 +517,40 @@ for (i in 1:length(measures_names)) { all_final_values = data.frame() - if (measures_names[i] == 'displacement_velocity_hill') { fin=length(methods) + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') { fin=length(methods) }else{ fin=length(methods)-1 } for (exp in 1:fin) { temp = data.frame( c(measures_fin[[exp]][paste(methods[exp],'_',measures_names[i],'_avg', sep='')])) colnames(temp) <- 'values' - if (measures_names[i] == 'displacement_velocity_hill') { temp$type = experiments_labels[exp] + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') + { temp$type = experiments_labels[exp] }else{ temp$type = experiments_labels2[exp] } all_final_values = rbind(all_final_values, temp) } - - max_y = 0 - # if(measures_names[i]=='proportion' || measures_names[i]=='head_balance' || measures_names[i]=='joints' ){ max_y = 1.1 } + + max_y = max(all_final_values$values) * 1.1 g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + - geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4, notch=TRUE) + + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4) + #notch=TRUE labs( x="Environment", y=measures_labels[i], title="Final generation") - if (measures_names[i] == 'displacement_velocity_hill') { g1 = g1 + scale_color_manual(values=experiments_type_colors) + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') + { g1 = g1 + scale_color_manual(values=experiments_type_colors) }else{ g1 = g1 + scale_color_manual(values= c(experiments_type_colors[1:2],experiments_type_colors[4:4])) } g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , plot.title=element_text(size=40), axis.text=element_text(size=45), axis.title=element_text(size=50), axis.text.x = element_text(angle = 20, hjust = 1 ), - plot.margin=margin(t = 0.5, r = 0.5, b = 0.5, l = 0.5, unit = "cm") + plot.margin=margin(t = 0.5, r = 0.5, b = 0.5, l = 0.9, unit = "cm") )+ stat_summary(fun.y = mean, geom="point" ,shape = 16, size=11) - if (measures_names[i] == 'displacement_velocity_hill') { comps = list(c("Non-S: Flat", "Seasonal: Flat"), + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') { comps = list(c("Non-S: Flat", "Seasonal: Flat"), c("Non-S: Tilted", "Seasonal: Tilted"), c("Non-S: Tilted", "Non-S: Flat"), c("Seasonal: Tilted", "Seasonal: Flat")) diff --git a/experiments/karines_experiments/summary_measures_journal2_tilted.R b/experiments/karines_experiments/summary_measures_journal2_tilted.R index 76bd8a5c6d..b877ed6701 100644 --- a/experiments/karines_experiments/summary_measures_journal2_tilted.R +++ b/experiments/karines_experiments/summary_measures_journal2_tilted.R @@ -38,7 +38,7 @@ experiments_labels2 = c( 'Baseline', 'Baseline', runs = list( c(1:20), c(1:20) ) - gens = 10#100 + gens = 100 pop = 100 #### CHANGE THE PARAMETERS HERE #### @@ -170,14 +170,14 @@ experiments_labels2 = c( 'Baseline', 'Baseline', fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) - measures_snapshots_all = sqldf("select * from measures_snapshots_all where cons_fitness IS NOT NULL") + measures_snapshots_all = sqldf("select * from measures_snapshots_all where generation<= 99 and cons_fitness IS NOT NULL") # densities - measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=42 - and method !='", methods[1],"'",sep='' )) #99!!!! + measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=99 + and method !='", methods[1],"'",sep='' )) measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') @@ -487,10 +487,7 @@ experiments_labels2 = c( 'Baseline', 'Baseline', max_y = 0 min_y = 0 - if(measures_names[i]=='displacement_velocity_hill' ){ - max_y = 3 - min_y = -0.5 - } + graph = graph + labs( y=measures_labels[i], x="Generation") if (max_y>0) { @@ -515,29 +512,27 @@ experiments_labels2 = c( 'Baseline', 'Baseline', { all_final_values = data.frame() - if (measures_names[i] == 'displacement_velocity_hill') { ini=1 + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') { ini=1 }else{ ini=2 } for (exp in ini:length(methods)) { temp = data.frame( c(measures_fin[[exp]][paste(methods[exp],'_',measures_names[i],'_avg', sep='')])) colnames(temp) <- 'values' - if (measures_names[i] == 'displacement_velocity_hill') { temp$type = experiments_labels[exp] + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') { temp$type = experiments_labels[exp] }else{ temp$type = experiments_labels2[exp] } all_final_values = rbind(all_final_values, temp) } - max_y = 0 - # min_y = -0.5 - #if(measures_names[i]=='displacement_velocity_hill' ){ max_y = 3 } + max_y = max(all_final_values$values) * 1.1 g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + - geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4, notch=TRUE) + + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4) + labs( x="Environment", y=measures_labels[i], title="Final generation") - if (measures_names[i] == 'displacement_velocity_hill') { g1 = g1 + scale_color_manual(values=experiments_type_colors) + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') { g1 = g1 + scale_color_manual(values=experiments_type_colors) }else{ g1 = g1 + scale_color_manual(values=experiments_type_colors[-1]) } g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , @@ -546,13 +541,12 @@ experiments_labels2 = c( 'Baseline', 'Baseline', axis.text.x = element_text(angle = 20, hjust = 1))+ stat_summary(fun.y = mean, geom="point" ,shape = 16, size=11) - if (measures_names[i] == 'displacement_velocity_hill') { comps = list(c("Baseline: Flat", "Plastic: Flat"), + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') { comps = list(c("Baseline: Flat", "Plastic: Flat"), c("Baseline: Tilted", "Plastic: Tilted")) }else{ comps = list(c("Baseline", "Plastic: Flat"), c("Baseline", "Plastic: Tilted"), c("Plastic: Flat", "Plastic: Tilted")) } - g1 = g1 + geom_signif( test="wilcox.test", size=2, textsize=22, comparisons = comps, map_signif_level=c("***"=0.001,"**"=0.01, "*"=0.05) ) diff --git a/experiments/karines_experiments/tilted.py b/experiments/karines_experiments/tilted.py index fef3500226..46baeee4cf 100755 --- a/experiments/karines_experiments/tilted.py +++ b/experiments/karines_experiments/tilted.py @@ -66,11 +66,13 @@ async def run(): gen_num = 0 next_robot_id = 1 - def fitness_function(robot_manager, robot): + def fitness_function_tilted(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) return fitness.displacement_velocity_hill(robot_manager, robot, False) + fitness_function = {'tilted5': fitness_function_tilted} + population_conf = PopulationConfig( population_size=population_size, genotype_constructor=random_initialization, diff --git a/pyrevolve/angle/manage/world.py b/pyrevolve/angle/manage/world.py index 12539ce419..31c8fd9a9b 100644 --- a/pyrevolve/angle/manage/world.py +++ b/pyrevolve/angle/manage/world.py @@ -11,7 +11,7 @@ from asyncio import Future from datetime import datetime from pygazebo.msg import gz_string_pb2 -#from pygazebo.msg.contacts_pb2 import Contacts +from pygazebo.msg.contacts_pb2 import Contacts from pyrevolve.SDF.math import Vector3 from pyrevolve.spec.msgs import BoundingBox @@ -208,11 +208,11 @@ async def _init(self): self._update_states ) - # self.contact_subscriber = await self.manager.subscribe( - # '/gazebo/default/physics/contacts', - # 'gazebo.msgs.Contacts', - # self._update_contacts - # ) + self.contact_subscriber = await self.manager.subscribe( + '/gazebo/default/physics/contacts', + 'gazebo.msgs.Contacts', + self._update_contacts + ) # Awaiting this immediately will lock the program update_state_future = self.set_state_update_frequency( @@ -230,7 +230,7 @@ async def _init(self): # Wait for connections await self.pose_subscriber.wait_for_connection() - #await self.contact_subscriber.wait_for_connection() + await self.contact_subscriber.wait_for_connection() await update_state_future if self.do_restore: @@ -239,7 +239,7 @@ async def _init(self): async def disconnect(self): await super().disconnect() await self.pose_subscriber.remove() - #await self.contact_subscriber.remove() + await self.contact_subscriber.remove() await self.battery_handler.stop() async def create_snapshot(self, pause_when_saving=True): @@ -648,24 +648,24 @@ def _update_states(self, msg): robot_manager.dead = True self.call_update_triggers() - # - # def _update_contacts(self, msg): - # """ - # Handles the contacts with the ground info message by updating robot contacts. - # :param msg: - # :return: - # """ - # contacts = Contacts() - # contacts.ParseFromString(msg) - # # if there was any contact in that instant - # if contacts.contact: - # # fetches one or more contact points for each module that has contacts - # for module_contacts in contacts.contact: - # robot_name = module_contacts.collision1.split('::')[0] - # robot_manager = self.robot_managers.get(robot_name, None) - # if not robot_manager: - # continue - # robot_manager.update_contacts(self, module_contacts) + + def _update_contacts(self, msg): + """ + Handles the contacts with the ground info message by updating robot contacts. + :param msg: + :return: + """ + contacts = Contacts() + contacts.ParseFromString(msg) + # if there was any contact in that instant + if contacts.contact: + # fetches one or more contact points for each module that has contacts + for module_contacts in contacts.contact: + robot_name = module_contacts.collision1.split('::')[0] + robot_manager = self.robot_managers.get(robot_name, None) + if not robot_manager: + continue + robot_manager.update_contacts(self, module_contacts) def add_update_trigger(self, callback): """ diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index fb90f5f40d..b4668d10fe 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -368,18 +368,36 @@ async def evaluate(self, new_individuals, gen_num, environment, type_simulation self.conf.experiment_management.export_fitness(individual, environment) self.conf.experiment_management.export_individual(individual, environment) + # async def evaluate_single_robot(self, individual, environment): + # """ + # :param individual: individual + # :return: Returns future of the evaluation, future returns (fitness, [behavioural] measurements) + # """ + # + # if self.analyzer_queue is not None: + # collisions, _bounding_box = await self.analyzer_queue.test_robot(individual, + # self.conf) + # if collisions > 0: + # logger.info(f"discarding robot {individual} because there are {collisions} self collisions") + # return None, None + # + # return await self.simulator_queue[environment].test_robot(individual, self.conf) + + async def evaluate_single_robot(self, individual, environment): """ :param individual: individual :return: Returns future of the evaluation, future returns (fitness, [behavioural] measurements) """ + conf = copy.deepcopy(self.conf) + conf.fitness_function = conf.fitness_function[environment] + if self.analyzer_queue is not None: collisions, _bounding_box = await self.analyzer_queue.test_robot(individual, - self.conf) + conf) if collisions > 0: logger.info(f"discarding robot {individual} because there are {collisions} self collisions") return None, None - return await self.simulator_queue[environment].test_robot(individual, self.conf) - + return await self.simulator_queue[environment].test_robot(individual, conf) \ No newline at end of file diff --git a/pyrevolve/tol/manage/measures.py b/pyrevolve/tol/manage/measures.py index 64130b8cdb..05b32cd0cd 100644 --- a/pyrevolve/tol/manage/measures.py +++ b/pyrevolve/tol/manage/measures.py @@ -22,7 +22,7 @@ def __init__(self, robot_manager = None, robot = None): self.displacement_velocity = displacement_velocity(robot_manager) self.displacement_velocity_hill = displacement_velocity_hill(robot_manager) self.head_balance = head_balance(robot_manager) - self.contacts = -1 #contacts(robot_manager, robot) + self.contacts = contacts(robot_manager, robot) else: self.velocity = None self.displacement = None From a0a6496812cbec1208c3eb9fa4a0a21598ecb732 Mon Sep 17 00:00:00 2001 From: karinemiras Date: Tue, 4 Feb 2020 18:26:43 +0100 Subject: [PATCH 36/45] reproducible experiments --- .../.DS_Store | Bin 0 -> 10244 bytes .../baseline2.py | 156 +++++ ...strobots_summary_renders_journal1_tilted.r | 86 +++ .../consolidate_experiments.py | 138 +++++ .../flat.py | 152 +++++ .../run-experiments | 79 +++ .../summary_measures_journal1_tilted.R | 578 ++++++++++++++++++ .../tilted.py | 152 +++++ 8 files changed, 1341 insertions(+) create mode 100644 experiments/Environmental_influences_on_evolvable_robots/.DS_Store create mode 100755 experiments/Environmental_influences_on_evolvable_robots/baseline2.py create mode 100644 experiments/Environmental_influences_on_evolvable_robots/bestrobots_summary_renders_journal1_tilted.r create mode 100644 experiments/Environmental_influences_on_evolvable_robots/consolidate_experiments.py create mode 100755 experiments/Environmental_influences_on_evolvable_robots/flat.py create mode 100755 experiments/Environmental_influences_on_evolvable_robots/run-experiments create mode 100644 experiments/Environmental_influences_on_evolvable_robots/summary_measures_journal1_tilted.R create mode 100755 experiments/Environmental_influences_on_evolvable_robots/tilted.py diff --git a/experiments/Environmental_influences_on_evolvable_robots/.DS_Store b/experiments/Environmental_influences_on_evolvable_robots/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7c4ca6919d3d01fd514c88a4918d2083e14b66c0 GIT binary patch literal 10244 zcmeI1O>Yx15QfK4iSltM7tSkA2%)CUFNmseLmXPcHIO!kwA&DEHW9h)Pv;qbpzdx$ zL)op^)|Tw?+B5dP@5F15BO>Nxd2uX~h{!%!<-se84N3bo*U}T;@&;+J7fEF*Gnq(V zMm6o&5E+OJLrQAlCQS{!28M z)Msd}DP0wk;llH(D9LG5_i9R`g$LZ~4kRH0!?#&-m{{BkNDc&H09;loM9z zp>%N#w#h~CV{3EZ%V#&%P&ap&I)cDkr3bVJ>}I-Fbnlq5>y>}o-Ne5OrohOpx^VOy zcFy4_x9c)vU7mJuZ`_O`@UWp5i_{%3KJx%Ir(NmK<>HX;p z)y3aQ6PN?9|2)>6d{F*|Jq{n#G2h(>m9g-_+rM51I!5^{(?vftg**77k@4`y!%j~f zyhQK+KW_j3|6!95(M1LxIRj>Ics4wN1b??)qeJi76Y@8*Ce= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/Environmental_influences_on_evolvable_robots/bestrobots_summary_renders_journal1_tilted.r b/experiments/Environmental_influences_on_evolvable_robots/bestrobots_summary_renders_journal1_tilted.r new file mode 100644 index 0000000000..89f7fcdc8e --- /dev/null +++ b/experiments/Environmental_influences_on_evolvable_robots/bestrobots_summary_renders_journal1_tilted.r @@ -0,0 +1,86 @@ + +library(sqldf) +require('magick') + +##### change paths/labels/params here ##### + + +paths = c( 'flat', 'tilted', 'baseline2') + +environments = list(c( 'plane'), + c( 'tilted5'), + c( 'plane') +) + +base_directory <- paste('data/', sep='') + +experiments = c(1:20) +gens = 100 +pop = 100 +num_top = 1 + +analysis = 'analysis_journal1_tilted' + +##### change paths/labels/params here ##### + +output_directory = paste(base_directory,analysis, sep='') + + +file <-file(paste(output_directory,'/best.txt',sep=''), open="w") + +# for each method +for(m in 1:length(paths)) +{ + # for each repetition + for (exp in experiments) + { + + input_directory1 <- paste(base_directory, paths[m],'_',exp, '/data_fullevolution/',environments[[m]][1],sep='') + input_directory2 <- paste(base_directory, paths[m],'_',exp, '/selectedpop_', sep='') + + ids_gens = data.frame() + list = strsplit(list.files(paste(input_directory2, environments[[m]][1],'/selectedpop_',gens-1, sep='')), ' ') + for(geno in 1:pop) + { + genome = data.frame(cbind(c(gens), c(strsplit(strsplit(list [[geno]],'_')[[1]][3],'.png')[[1]][1] ))) + names(genome)<-c('generation','robot_id') + ids_gens = rbind(ids_gens,genome) + } + + measures = read.table(paste(input_directory1,"/all_measures.tsv", sep=''), header = TRUE) + bests = sqldf(paste("select robot_id, cons_fitness from measures inner join ids_gens using (robot_id) order by cons_fitness desc limit",num_top)) + + for(b in 1:nrow(bests)) + { + + writeLines( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] ), file ) + print( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] )) + + phenotype= bests[b,'robot_id'] + + for (env in 1:length(environments[[m]])) + { + patha = paste(input_directory2, environments[[m]][env], "/selectedpop_",gens-1,sep="") + + body <- list.files(patha, paste("body_robot_",phenotype,".png$",sep=""), full.names = TRUE) + body = image_read(body) + body = image_scale(body, "100x100") + body = image_border(image_background(body, "white"), "white", "5x5") + + if(b == 1 && env == 1) + { + bodies = body + }else{ + bodies = c(bodies, body) + } + } + } + + side_by_side = image_append(bodies, stack=F) + image_write(side_by_side, path = paste(output_directory,"/",paths[m],'_', environments[[m]][env], "_bodies_best_",exp,".png",sep=''), format = "png") + + } +} + + +close(file) diff --git a/experiments/Environmental_influences_on_evolvable_robots/consolidate_experiments.py b/experiments/Environmental_influences_on_evolvable_robots/consolidate_experiments.py new file mode 100644 index 0000000000..8b5189f207 --- /dev/null +++ b/experiments/Environmental_influences_on_evolvable_robots/consolidate_experiments.py @@ -0,0 +1,138 @@ +import os +import math + +# set these variables according to your experiments # +dirpath = 'data/' +experiments_type = [ + 'baseline2', + 'flat', + 'tilted' +] +environments = { + 'baseline2': ['plane','tilted5'], + 'flat': ['plane'], + 'tilted': ['tilted5'] } + +runs = range(1, 21) + + +# set these variables according to your experiments # + +def build_headers(path1, path2): + + file_summary = open(path1 + "/all_measures.tsv", "w+") + file_summary.write('robot_id\t') + + behavior_headers = [] + behavior_headers.append('velocity') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('displacement_velocity') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('displacement_velocity_hill') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('head_balance') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('contacts') + file_summary.write(behavior_headers[-1]+'\t') + # use this instead? but what if the guy is none? + # with open(path + '/data_fullevolution/descriptors/behavior_desc_robot_1.txt') as file: + # for line in file: + # measure, value = line.strip().split(' ') + # behavior_headers.append(measure) + # file_summary.write(measure+'\t') + + phenotype_headers = [] + with open(path1 + '/descriptors/phenotype_desc_robot_1.txt') as file: + for line in file: + measure, value = line.strip().split(' ') + phenotype_headers.append(measure) + file_summary.write(measure+'\t') + file_summary.write('fitness\t cons_fitness\n') + file_summary.close() + + file_summary = open(path2 + "/snapshots_ids.tsv", "w+") + file_summary.write('generation\trobot_id\n') + file_summary.close() + + return behavior_headers, phenotype_headers + +for exp in experiments_type: + + for env in environments[exp]: + + for run in runs: + + path0 = dirpath + str(exp) + '_' + str(run) + '/data_fullevolution' + path1 = dirpath + str(exp) + '_' + str(run) + '/data_fullevolution/' + env + path2 = dirpath + str(exp) + '_' + str(run) + '/selectedpop_' + env + + behavior_headers, phenotype_headers = build_headers(path1, path2) + + file_summary = open(path1 + "/all_measures.tsv", "a") + for r, d, f in os.walk(path0+'/consolidated_fitness'): + for file in f: + + robot_id = file.split('.')[0].split('_')[-1] + file_summary.write(robot_id+'\t') + + bh_file = path1+'/descriptors/behavior_desc_robot_'+robot_id+'.txt' + if os.path.isfile(bh_file): + with open(bh_file) as file: + for line in file: + if line != 'None': + measure, value = line.strip().split(' ') + file_summary.write(value+'\t') + else: + for h in behavior_headers: + file_summary.write('None'+'\t') + else: + for h in behavior_headers: + file_summary.write('None'+'\t') + + pt_file = path1+'/descriptors/phenotype_desc_robot_'+robot_id+'.txt' + if os.path.isfile(pt_file): + with open(pt_file) as file: + for line in file: + measure, value = line.strip().split(' ') + file_summary.write(value+'\t') + else: + for h in phenotype_headers: + file_summary.write('None'+'\t') + + f_file = open(path1+'/fitness/fitness_robot_'+robot_id+'.txt', 'r') + fitness = f_file.read() + file_summary.write(fitness + '\t') + + cf_file = open(path0+'/consolidated_fitness/consolidated_fitness_robot_'+robot_id+'.txt', 'r') + cons_fitness = cf_file.read() + file_summary.write(cons_fitness + '\n') + + num_files = len(f) + list_gens = [] + for r, d, f in os.walk(path2): + for dir in d: + if 'selectedpop' in dir: + gen = dir.split('_')[1] + list_gens.append(int(gen)) + list_gens.sort() + if len(list_gens)>0: + gen = list_gens[-1] + else: + gen = -1 + print(exp, run, num_files, gen, num_files-(gen*50+100)) + + file_summary.close() + + file_summary = open(path2 + "/snapshots_ids.tsv", "a") + for r, d, f in os.walk(path2): + for dir in d: + if 'selectedpop' in dir: + gen = dir.split('_')[1] + for r2, d2, f2 in os.walk(path2 + '/selectedpop_' + str(gen)): + for file in f2: + if 'body' in file: + id = file.split('.')[0].split('_')[-1] + file_summary.write(gen+'\t'+id+'\n') + + file_summary.close() + diff --git a/experiments/Environmental_influences_on_evolvable_robots/flat.py b/experiments/Environmental_influences_on_evolvable_robots/flat.py new file mode 100755 index 0000000000..e96146b204 --- /dev/null +++ b/experiments/Environmental_influences_on_evolvable_robots/flat.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + front = None + + # environment world and z-start + environments = {'plane': 0.03} + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=False, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function_plane(robot_manager, robot): + #contacts = measures.contacts(robot_manager, robot) + #assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + fitness_function = {'plane': fitness_function_plane} + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/Environmental_influences_on_evolvable_robots/run-experiments b/experiments/Environmental_influences_on_evolvable_robots/run-experiments new file mode 100755 index 0000000000..6a69187b26 --- /dev/null +++ b/experiments/Environmental_influences_on_evolvable_robots/run-experiments @@ -0,0 +1,79 @@ + #!/bin/bash + +while true + do + for i in {1..5}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 11000 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {6..10}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 11050 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {11..15}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 11100 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {16..20}; do + ./revolve.py --experiment-name karines_experiments/data/baseline2_$i --run $i --manager experiments/karines_experiments/baseline2.py --n-cores 4 --port-start 11150 --evaluation-time 50; + + sleep 5s + done +done + + + +while true + do + for i in {1..10}; do + ./revolve.py --experiment-name karines_experiments/data/flat_$i --run $i --manager experiments/karines_experiments/flat.py --n-cores 4 --port-start 11400 --evaluation-time 50; + + sleep 5s + done +done + +while true + do + for i in {11..20}; do + ./revolve.py --experiment-name karines_experiments/data/flat_$i --run $i --manager experiments/karines_experiments/flat.py --n-cores 4 --port-start 11500 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {1..10}; do + ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/tilted.py --n-cores 4 --port-start 11600 --evaluation-time 50; + + sleep 5s + done +done + +while true + do + for i in {11..20}; do + ./revolve.py --experiment-name karines_experiments/data/tilted_$i --run $i --manager experiments/karines_experiments/tilted.py --n-cores 4 --port-start 11700 --evaluation-time 50; + + sleep 5s + done +done \ No newline at end of file diff --git a/experiments/Environmental_influences_on_evolvable_robots/summary_measures_journal1_tilted.R b/experiments/Environmental_influences_on_evolvable_robots/summary_measures_journal1_tilted.R new file mode 100644 index 0000000000..18883e700c --- /dev/null +++ b/experiments/Environmental_influences_on_evolvable_robots/summary_measures_journal1_tilted.R @@ -0,0 +1,578 @@ +library(ggplot2) +library(sqldf) +library(plyr) +library(dplyr) +library(trend) +library(purrr) +library(ggsignif) + +base_directory <-paste('data', sep='') + +analysis = 'analysis_journal1_tilted' + +output_directory = paste(base_directory,'/',analysis ,sep='') + +#### CHANGE THE PARAMETERS HERE #### + + +experiments_type = c('flat', 'tilted','baseline2') + +environments = list( c( 'plane'), + c('tilted5'), + c( 'plane','tilted5') ) + +methods = c() +for (exp in 1:length(experiments_type)) +{ + for (env in 1:length(environments[[exp]])) + { + methods = c(methods, paste(experiments_type[exp], environments[[exp]][env], sep='_')) + } +} + +initials = c( 'bp', 'bt', 'pp', 'pt') + +experiments_labels = c( 'Static: Flat', 'Static: Tilted', + 'Seasonal: Flat', 'Seasonal: Tilted') + +experiments_labels2 = c( 'Static: Flat', 'Static: Tilted', + 'Seasonal', 'Seasonal') + +runs = list( c(1:20) , + c(1:20) , + c(1:20) ) + +gens = 100 +pop = 100 + +#### CHANGE THE PARAMETERS HERE #### + +sig = 0.05 +line_size = 30 +show_markers = FALSE +show_legends = FALSE +experiments_type_colors = c( '#00e700' , '#009900', '#ffb83b', '#fd8a3b') # DARK: light green,dark green, light red, dark red + +measures_names = c( + 'displacement_velocity_hill', + 'head_balance', + 'contacts', + 'displacement_velocity', + 'branching', + 'branching_modules_count', + 'limbs', + 'extremities', + 'length_of_limbs', + 'extensiveness', + 'coverage', + 'joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'proportion', + 'width', + 'height', + 'absolute_size', + 'sensors', + 'symmetry', + 'avg_period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'fitness', + 'cons_fitness' +) + +# add proper labels soon... +measures_labels = c( + 'Speed (cm/s)', + 'Balance', + 'Contacts', + 'displacement_velocity', + 'Branching', + 'branching_modules_count', + 'Rel number of limbs', + 'extremities', + 'Rel. Length of Limbs', + 'extensiveness', + 'coverage', + 'Rel. Number of Joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'Proportion', + 'width', + 'height', + 'Size', + 'sensors', + 'Symmetry', + 'Average Period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'Fitness', + 'Number of slaves' +) + + +measures_snapshots_all = NULL + +for (exp in 1:length(experiments_type)) +{ + for(run in runs[[exp]]) + { + for (env in 1:length(environments[[exp]])) + { + input_directory <- paste(base_directory, '/', + experiments_type[exp], '_',sep='') + + measures = read.table(paste(input_directory, run, '/data_fullevolution/', + environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE, fill=TRUE) + for( m in 1:length(measures_names)) + { + measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) + } + + snapshots = read.table(paste(input_directory, run,'/selectedpop_', + environments[[exp]][env],"/snapshots_ids.tsv", sep=''), header = TRUE) + + measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') + + measures_snapshots$run = run + measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 + measures_snapshots$run = as.factor(measures_snapshots$run) + measures_snapshots$method = paste(experiments_type[exp], environments[[exp]][env],sep='_') + + if ( is.null(measures_snapshots_all)){ + measures_snapshots_all = measures_snapshots + }else{ + measures_snapshots_all = rbind(measures_snapshots_all, measures_snapshots) + } + } + } +} + + +fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) + + +measures_snapshots_all = sqldf("select * from measures_snapshots_all where generation<=99 and cons_fitness IS NOT NULL") + + + + +# densities + +measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=99 + and method !='", methods[length(methods)],"'",sep='' )) + +measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') +measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') + +for (i in 1:length(measures_names_densities)) +{ + + for (j in 1:length(measures_names_densities)) + { + + if(i != j) + { + + graph <- ggplot(measures_snapshots_all_densities, aes_string(x=measures_names_densities[j], y= measures_names_densities[i]))+ + geom_density_2d(aes(colour = method ), alpha=0.7, size=3 )+ + scale_color_manual(values = c(experiments_type_colors[4:4], experiments_type_colors[1:2]) )+ + labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ + theme(legend.position="none" , axis.text=element_text(size=21),axis.title=element_text(size=22), + plot.subtitle=element_text(size=25 )) + + coord_cartesian(ylim = c(0, 1), xlim = c(0, 1)) + ggsave(paste( output_directory ,'/density_',measures_names_densities[i],'_', measures_names_densities[j],'.png', sep=''), graph , + device='png', height = 6, width = 6) + } + + } +} + + + +measures_averages_gens_1 = list() +measures_averages_gens_2 = list() + +measures_ini = list() +measures_fin = list() + +for (met in 1:length(methods)) +{ + + measures_aux = c() + query ='select run, generation' + for (i in 1:length(measures_names)) + { + query = paste(query,', avg(',measures_names[i],') as ', methods[met], '_',measures_names[i],'_avg', sep='') + } + query = paste(query,' from measures_snapshots_all + where method="', methods[met],'" group by run, generation', sep='') + + temp = sqldf(query) + + measures_averages_gens_1[[met]] = temp + + temp = measures_averages_gens_1[[met]] + + temp$generation = as.numeric(temp$generation) + + measures_ini[[met]] = sqldf(paste("select * from temp where generation=0")) + measures_fin[[met]] = sqldf(paste("select * from temp where generation=",gens-1)) + query = 'select generation' + for (i in 1:length(measures_names)) + { + # later renames vars _avg_SUMMARY, just to make it in the same style as the quantile variables + query = paste(query,', avg(', methods[met], '_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_avg', sep='') + query = paste(query,', max(', methods[met],'_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_max', sep='') + query = paste(query,', stdev(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_stdev', sep='') + query = paste(query,', median(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_median', sep='') + + measures_aux = c(measures_aux, paste(methods[met],'_',measures_names[i],'_avg', sep='') ) + } + query = paste(query,' from temp group by generation', sep="") + + temp2 = sqldf(query) + + p <- c(0.25, 0.75) + p_names <- map_chr(p, ~paste0('Q',.x*100, sep="")) + p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>% + set_names(nm = p_names) + + quantiles = data.frame(temp %>% + group_by(generation) %>% + summarize_at(vars(measures_aux), funs(!!!p_funs)) ) + + measures_averages_gens_2[[met]] = sqldf('select * from temp2 inner join quantiles using (generation)') + +} + + +for (met in 1:length(methods)) +{ + if(met==1){ + measures_averages_gens = measures_averages_gens_2[[1]] + }else{ + measures_averages_gens = merge(measures_averages_gens, measures_averages_gens_2[[met]], all=TRUE, by = "generation") + } +} + +file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") + +#tests trends in curves and difference between ini and fin generations + + +# ini VS fin +array_wilcoxon = list() +array_wilcoxon2 = list() + +# curve +array_mann = list() + + +for (m in 1:length(methods)) +{ + + array_wilcoxon[[m]] = list() + array_mann[[m]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(experiments_type[m],measures_names[i],'ini avg ',as.character( + mean(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon[[m]][[i]] = wilcox.test(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'iniVSfin',measures_names[i],'wilcox p: ',as.character(round(array_wilcoxon[[m]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'iniVSfin',measures_names[i],'wilcox est: ',as.character(round(array_wilcoxon[[m]][[i]]$statistic,4)), sep=' ') + + ), file) + + + #tests trends + array_mann[[m]][[i]] = mk.test(c(array(measures_averages_gens_2[[m]][paste(methods[m],"_",measures_names[i],'_median',sep='')]) )[[1]], + continuity = TRUE) + + + writeLines(c( + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median p', as.character(round(array_mann[[m]][[i]]$p.value,4)),sep=' '), + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median s', as.character(round(array_mann[[m]][[i]]$statistic,4)),sep=' ') + ), file) + + } + +} + + + +# tests final generation among experiments_type + +aux_m = length(methods) + +if (aux_m>1) +{ + + # fins + array_wilcoxon2[[1]] = list() + array_wilcoxon2[[2]] = list() + + aux_m = aux_m -1 + count_pairs = 0 + for(m in 1:aux_m) + { + aux = m+1 + for(m2 in aux:length(methods)) + { + + count_pairs = count_pairs+1 + array_wilcoxon2[[1]][[count_pairs]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + writeLines(paste(methods[m2],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon2[[1]][[count_pairs]][[i]] = wilcox.test(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'VS',methods,measures_names[i],'fin avg wilcox p: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'VS',methods[m2],measures_names[i],'fin avg wilcox est: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$statistic,4)), sep=' ') + + ), file) + + } + + + array_wilcoxon2[[2]][[count_pairs]] = paste(initials[m],initials[m2],sep='') + + } + } + +} + +close(file) + + + +# plots measures + +for (type_summary in c('means','quants')) +{ + + + for (i in 1:length(measures_names)) + { + tests1 = '' + tests2 = '' + tests3 = '' + break_aux = 0 + + graph <- ggplot(data=measures_averages_gens, aes(x=generation)) + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg','-',methods[m],'_',measures_names[i],'_stdev',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg','+',methods[m],'_',measures_names[i],'_stdev',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + }else + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg_Q25',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg_Q75',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + } + } + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) + } + + }else{ + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') , colour=shQuote(experiments_labels[m]) ),size=2 ) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') ),size=2, color = experiments_type_colors[m] ) + } + } + + if (length(array_mann)>0) + { + if (length(array_mann[[m]])>0) + { + if(!is.na(array_mann[[m]][[i]]$p.value)) + { + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } + } + } + } + } + + if (length(array_wilcoxon[[m]])>0) + { + for(m in 1:length(methods)) + { + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + { + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } + } + } + } + + if (length(array_wilcoxon2)>0) + { + for(p in 1:length(array_wilcoxon2[[1]])) + { + if (length(array_wilcoxon2[[1]][[p]])>0) + { + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + { + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') + } + } + } + } + } + + max_y = 0 + + graph = graph + labs( y=measures_labels[i], x="Generation") + if (max_y>0) { + graph = graph + coord_cartesian(ylim = c(min_y, max_y)) + } + + if(show_markers == TRUE){ + graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) + } + graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=30),axis.title=element_text(size=39), + plot.subtitle=element_text(size=25 )) + + ggsave(paste( output_directory,'/',type_summary,'_' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 10, width = 10) + } + +} + + + + +for (i in 1:length(measures_names)) +{ + + all_final_values = data.frame() + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') { fin=length(methods) + }else{ fin=length(methods)-1 } + + for (exp in 1:fin) + { + temp = data.frame( c(measures_fin[[exp]][paste(methods[exp],'_',measures_names[i],'_avg', sep='')])) + colnames(temp) <- 'values' + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') + { temp$type = experiments_labels[exp] + }else{ temp$type = experiments_labels2[exp] } + + all_final_values = rbind(all_final_values, temp) + } + + + max_y = max(all_final_values$values) * 1.1 + + g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4) + #notch=TRUE + labs( x="Environment", y=measures_labels[i], title="Final generation") + + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') + { g1 = g1 + scale_color_manual(values=c(experiments_type_colors[3:4], experiments_type_colors[1:2]) ) + }else{ g1 = g1 + scale_color_manual(values= c(experiments_type_colors[4:4],experiments_type_colors[1:2])) } + + + if (measures_names[i] == 'displacement_velocity_hill' || measures_names[i] == 'head_balance') { comps = list(c("Static: Flat", "Seasonal: Flat"), + c("Static: Tilted", "Seasonal: Tilted"), + c("Static: Tilted", "Static: Flat"), + c("Seasonal: Tilted", "Seasonal: Flat")) + aux_width=15 + border_l = 2.5 + }else{ comps = list(c("Static: Flat", "Static: Tilted"), + c("Static: Flat", "Seasonal"), + c("Static: Tilted", "Seasonal")) + aux_width=11 + border_l = 1.3 + } + + + g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , + plot.title=element_text(size=40), axis.text=element_text(size=45), + axis.title=element_text(size=50), + axis.text.x = element_text(angle = 20, hjust = 1 ), + plot.margin=margin(t = 0.5, r = 0.5, b = 0.5, l = border_l, unit = "cm") + )+ + stat_summary(fun.y = mean, geom="point" ,shape = 16, size=11) + + g1 = g1 + geom_signif( test="wilcox.test", size=2, textsize=22, + comparisons = comps, + map_signif_level=c("***"=0.001,"**"=0.01, "*"=0.05) ) + if (max_y>0) { + g1 = g1 + coord_cartesian(ylim = c(0, max_y)) + } + g1 + ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = aux_width) + +} + diff --git a/experiments/Environmental_influences_on_evolvable_robots/tilted.py b/experiments/Environmental_influences_on_evolvable_robots/tilted.py new file mode 100755 index 0000000000..46baeee4cf --- /dev/null +++ b/experiments/Environmental_influences_on_evolvable_robots/tilted.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 100 + population_size = 100 + offspring_size = 50 + front = None + + # environment world and z-start + environments = {'tilted5': 0.1} + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=False, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function_tilted(robot_manager, robot): + #contacts = measures.contacts(robot_manager, robot) + #assert(contacts != 0) + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + fitness_function = {'tilted5': fitness_function_tilted} + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... From 764c4855464c40a6706ef46023f391adec32677a Mon Sep 17 00:00:00 2001 From: karinemiras Date: Mon, 10 Feb 2020 18:15:52 +0100 Subject: [PATCH 37/45] plasticoding setup --- .../plasticoding_frontiers2020/.DS_Store | Bin 0 -> 6148 bytes .../baseline_big.py | 155 +++++ ...bots_summary_renders_journal2_tilted_big.r | 0 .../consolidate_experiments.py | 138 +++++ .../plasticoding_frontiers2020/plastic_big.py | 155 +++++ .../run-experiments | 35 ++ .../summary_measures_journal2_tilted_big_2.R | 243 ++++++++ .../summary_measures_journal2_tilted_big_3.R | 560 ++++++++++++++++++ 8 files changed, 1286 insertions(+) create mode 100644 experiments/plasticoding_frontiers2020/.DS_Store create mode 100755 experiments/plasticoding_frontiers2020/baseline_big.py create mode 100644 experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r create mode 100644 experiments/plasticoding_frontiers2020/consolidate_experiments.py create mode 100755 experiments/plasticoding_frontiers2020/plastic_big.py create mode 100755 experiments/plasticoding_frontiers2020/run-experiments create mode 100644 experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R create mode 100644 experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R diff --git a/experiments/plasticoding_frontiers2020/.DS_Store b/experiments/plasticoding_frontiers2020/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r b/experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r new file mode 100644 index 0000000000..e69de29bb2 diff --git a/experiments/plasticoding_frontiers2020/consolidate_experiments.py b/experiments/plasticoding_frontiers2020/consolidate_experiments.py new file mode 100644 index 0000000000..21df238414 --- /dev/null +++ b/experiments/plasticoding_frontiers2020/consolidate_experiments.py @@ -0,0 +1,138 @@ +import os +import math + +# set these variables according to your experiments # +dirpath = 'data/' +experiments_type = [ + + 'plastic_big' +,'baseline_big' +] +environments = { + + 'plastic_big': ['plane','tilted5'] + ,'baseline_big': ['plane','tilted5'] + } +runs = range(1, 21) + + +# set these variables according to your experiments # + +def build_headers(path1, path2): + + file_summary = open(path1 + "/all_measures.tsv", "w+") + file_summary.write('robot_id\t') + + behavior_headers = [] + behavior_headers.append('velocity') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('displacement_velocity') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('displacement_velocity_hill') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('head_balance') + file_summary.write(behavior_headers[-1]+'\t') + behavior_headers.append('contacts') + file_summary.write(behavior_headers[-1]+'\t') + # use this instead? but what if the guy is none? + # with open(path + '/data_fullevolution/descriptors/behavior_desc_robot_1.txt') as file: + # for line in file: + # measure, value = line.strip().split(' ') + # behavior_headers.append(measure) + # file_summary.write(measure+'\t') + + phenotype_headers = [] + with open(path1 + '/descriptors/phenotype_desc_robot_1.txt') as file: + for line in file: + measure, value = line.strip().split(' ') + phenotype_headers.append(measure) + file_summary.write(measure+'\t') + file_summary.write('fitness\t cons_fitness\n') + file_summary.close() + + file_summary = open(path2 + "/snapshots_ids.tsv", "w+") + file_summary.write('generation\trobot_id\n') + file_summary.close() + + return behavior_headers, phenotype_headers + +for exp in experiments_type: + + for env in environments[exp]: + + for run in runs: + + path0 = dirpath + str(exp) + '_' + str(run) + '/data_fullevolution' + path1 = dirpath + str(exp) + '_' + str(run) + '/data_fullevolution/' + env + path2 = dirpath + str(exp) + '_' + str(run) + '/selectedpop_' + env + + behavior_headers, phenotype_headers = build_headers(path1, path2) + + file_summary = open(path1 + "/all_measures.tsv", "a") + for r, d, f in os.walk(path0+'/consolidated_fitness'): + for file in f: + + robot_id = file.split('.')[0].split('_')[-1] + file_summary.write(robot_id+'\t') + + bh_file = path1+'/descriptors/behavior_desc_robot_'+robot_id+'.txt' + if os.path.isfile(bh_file): + with open(bh_file) as file: + for line in file: + if line != 'None': + measure, value = line.strip().split(' ') + file_summary.write(value+'\t') + else: + for h in behavior_headers: + file_summary.write('None'+'\t') + else: + for h in behavior_headers: + file_summary.write('None'+'\t') + + pt_file = path1+'/descriptors/phenotype_desc_robot_'+robot_id+'.txt' + if os.path.isfile(pt_file): + with open(pt_file) as file: + for line in file: + measure, value = line.strip().split(' ') + file_summary.write(value+'\t') + else: + for h in phenotype_headers: + file_summary.write('None'+'\t') + + f_file = open(path1+'/fitness/fitness_robot_'+robot_id+'.txt', 'r') + fitness = f_file.read() + file_summary.write(fitness + '\t') + + cf_file = open(path0+'/consolidated_fitness/consolidated_fitness_robot_'+robot_id+'.txt', 'r') + cons_fitness = cf_file.read() + file_summary.write(cons_fitness + '\n') + + num_files = len(f) + list_gens = [] + for r, d, f in os.walk(path2): + for dir in d: + if 'selectedpop' in dir: + gen = dir.split('_')[1] + list_gens.append(int(gen)) + list_gens.sort() + if len(list_gens)>0: + gen = list_gens[-1] + else: + gen = -1 + print(exp, run, num_files, gen, num_files-(gen*100+100)) + + file_summary.close() + + file_summary = open(path2 + "/snapshots_ids.tsv", "a") + for r, d, f in os.walk(path2): + for dir in d: + if 'selectedpop' in dir: + gen = dir.split('_')[1] + for r2, d2, f2 in os.walk(path2 + '/selectedpop_' + str(gen)): + for file in f2: + if 'body' in file: + id = file.split('.')[0].split('_')[-1] + file_summary.write(gen+'\t'+id+'\n') + + file_summary.close() + diff --git a/experiments/plasticoding_frontiers2020/plastic_big.py b/experiments/plasticoding_frontiers2020/plastic_big.py new file mode 100755 index 0000000000..50f9d841f4 --- /dev/null +++ b/experiments/plasticoding_frontiers2020/plastic_big.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys +import time + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 200 + population_size = 100 + offspring_size = 100 + front = 'slaves' + + # environment world and z-start + environments = {'plane': 0.03, + 'tilted5': 0.1 + } + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=True, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function_plane(robot_manager, robot): + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + fitness_function = {'plane': fitness_function_plane, + 'tilted5': fitness_function_plane} + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/plasticoding_frontiers2020/run-experiments b/experiments/plasticoding_frontiers2020/run-experiments new file mode 100755 index 0000000000..86bb03c846 --- /dev/null +++ b/experiments/plasticoding_frontiers2020/run-experiments @@ -0,0 +1,35 @@ + #!/bin/bash + + +while true + do + for i in {1..20}; do + ./revolve.py --experiment-name karines_experiments/data/baseline_big_$i --run $i --manager experiments/karines_experiments/baseline_big.py --n-cores 4 --port-start 11000 --evaluation-time 50; + + sleep 5s + done +done + + +while true + do + for i in {1..20}; do + ./revolve.py --experiment-name karines_experiments/data/plastic_big_$i --run $i --manager experiments/karines_experiments/plastic_big.py --n-cores 4 --port-start 11141 --evaluation-time 50; + + sleep 5s + done +done + + + + + +while true + do + sleep 900s; + kill $( ps aux | grep 'gzserver' | awk '{print $2}'); + kill $( ps aux | grep 'revolve.py' | awk '{print $2}'); + sleep 60s; +done + + diff --git a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R new file mode 100644 index 0000000000..93b86f4236 --- /dev/null +++ b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R @@ -0,0 +1,243 @@ + library(ggplot2) + library(sqldf) + library(plyr) + library(dplyr) + library(trend) + library(purrr) + library(ggsignif) + + base_directory <-paste('data', sep='') + +analysis = 'analysis_journal2_tilted_big_2' + +output_directory = paste(base_directory,'/',analysis ,sep='') + +#### CHANGE THE PARAMETERS HERE #### + +experiments_type = c('baseline_big', 'plastic_big' ) + +environments = list( c( 'plane'), c( 'plane') ) + +methods = c() +for (exp in 1:length(experiments_type)) +{ + for (env in 1:length(environments[[exp]])) + { + methods = c(methods, paste(experiments_type[exp], environments[[exp]][env], sep='_')) + } +} + +initials = c( 'b', 'p' ) + +experiments_labels = c( 'Baseline' , 'Plastic') + + runs = list( c(1:20), c(1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,21,22) ) + + gens = 200 + pop = 100 + + #### CHANGE THE PARAMETERS HERE #### + + sig = 0.05 + line_size = 30 + show_markers = FALSE + show_legends = FALSE + experiments_type_colors = c( '#00ff00', '#006600' ) # light green; dark green; + + measures_names = c( + 'displacement_velocity_hill', + 'head_balance', + 'contacts', + 'displacement_velocity', + 'branching', + 'branching_modules_count', + 'limbs', + 'extremities', + 'length_of_limbs', + 'extensiveness', + 'coverage', + 'joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'proportion', + 'width', + 'height', + 'absolute_size', + 'sensors', + 'symmetry', + 'avg_period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'fitness', + 'cons_fitness' + ) + + # add proper labels soon... + measures_labels = c( + 'Speed (cm/s)', + 'Balance', + 'Contacts', + 'displacement_velocity', + 'Branching', + 'branching_modules_count', + 'Rel number of limbs', + 'extremities', + 'Rel. Length of Limbs', + 'extensiveness', + 'coverage', + 'Rel. Number of Joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'Proportion', + 'width', + 'height', + 'Size', + 'sensors', + 'Symmetry', + 'Average Period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'Fitness', + 'Number of slaves' + ) + + + measures_snapshots_all = NULL + + for (exp in 1:length(experiments_type)) + { + for(run in runs[[exp]]) + { + for (env in 1:length(environments[[exp]])) + { + input_directory <- paste(base_directory, '/', + experiments_type[exp], '_',sep='') + + measures = read.table(paste(input_directory, run, '/data_fullevolution/', + environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE, fill=TRUE) + for( m in 1:length(measures_names)) + { + measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) + } + + snapshots = read.table(paste(input_directory, run,'/selectedpop_', + environments[[exp]][env],"/snapshots_ids.tsv", sep=''), header = TRUE) + + measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') + + measures_snapshots$run = run + measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 + measures_snapshots$run = as.factor(measures_snapshots$run) + measures_snapshots$method = paste(experiments_type[exp], environments[[exp]][env],sep='_') + + if ( is.null(measures_snapshots_all)){ + measures_snapshots_all = measures_snapshots + }else{ + measures_snapshots_all = rbind(measures_snapshots_all, measures_snapshots) + } + } + } + } + + + fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) + + + measures_snapshots_all = sqldf("select * from measures_snapshots_all where cons_fitness IS NOT NULL") + + + + # densities + + measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=199 ",sep='' )) + + measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') + measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') + + for (i in 1:length(measures_names_densities)) + { + + for (j in 1:length(measures_names_densities)) + { + + if(i != j) + { + + graph <- ggplot(measures_snapshots_all_densities, aes_string(x=measures_names_densities[j], y= measures_names_densities[i]))+ + geom_density_2d(aes(colour = method ), alpha=0.7, size=3 )+ + scale_color_manual(values = experiments_type_colors )+ + labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ + theme(legend.position="none" , axis.text=element_text(size=21),axis.title=element_text(size=22), + plot.subtitle=element_text(size=25 )) + + coord_cartesian(ylim = c(0, 1), xlim = c(0, 1)) + ggsave(paste( output_directory ,'/density_',measures_names_densities[i],'_', measures_names_densities[j],'.png', sep=''), graph , + device='png', height = 6, width = 6) + } + + } + } + + measures_averages_gens_1 = list() + measures_averages_gens_2 = list() + + measures_ini = list() + measures_fin = list() + + for (met in 1:length(methods)) + { + + measures_aux = c() + query ='select run, generation' + for (i in 1:length(measures_names)) + { + query = paste(query,', avg(',measures_names[i],') as ', methods[met], '_',measures_names[i],'_avg', sep='') + } + query = paste(query,' from measures_snapshots_all + where method="', methods[met],'" group by run, generation', sep='') + + temp = sqldf(query) + + measures_averages_gens_1[[met]] = temp + + temp = measures_averages_gens_1[[met]] + + temp$generation = as.numeric(temp$generation) + + measures_ini[[met]] = sqldf(paste("select * from temp where generation=0")) + measures_fin[[met]] = sqldf(paste("select * from temp where generation=",gens-1)) + query = 'select generation' + for (i in 1:length(measures_names)) + { + # later renames vars _avg_SUMMARY, just to make it in the same style as the quantile variables + query = paste(query,', avg(', methods[met], '_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_avg', sep='') + query = paste(query,', max(', methods[met],'_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_max', sep='') + query = paste(query,', stdev(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_stdev', sep='') + query = paste(query,', median(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_median', sep='') + + \ No newline at end of file diff --git a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R new file mode 100644 index 0000000000..6f57f18d83 --- /dev/null +++ b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R @@ -0,0 +1,560 @@ + library(ggplot2) + library(sqldf) + library(plyr) + library(dplyr) + library(trend) + library(purrr) + library(ggsignif) + + base_directory <-paste('data', sep='') + +analysis = 'analysis_journal2_tilted_big_3' + +output_directory = paste(base_directory,'/',analysis ,sep='') + +#### CHANGE THE PARAMETERS HERE #### + +experiments_type = c( 'baseline_big', 'plastic_big' ) + +environments = list( c( 'tilted5'), c( 'tilted5') ) + +methods = c() +for (exp in 1:length(experiments_type)) +{ + for (env in 1:length(environments[[exp]])) + { + methods = c(methods, paste(experiments_type[exp], environments[[exp]][env], sep='_')) + } +} + +initials = c( 'b', 'p' ) + +experiments_labels = c( 'Baseline' , 'Plastic') + + runs = list( c(1:20), c(1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,21,22) ) + + gens = 200 + pop = 100 + + #### CHANGE THE PARAMETERS HERE #### + + sig = 0.05 + line_size = 30 + show_markers = FALSE + show_legends = FALSE + experiments_type_colors = c( '#ff9933', '#cc0000' ) # orange ; dark red + + measures_names = c( + 'displacement_velocity_hill', + 'head_balance', + 'contacts', + 'displacement_velocity', + 'branching', + 'branching_modules_count', + 'limbs', + 'extremities', + 'length_of_limbs', + 'extensiveness', + 'coverage', + 'joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'proportion', + 'width', + 'height', + 'absolute_size', + 'sensors', + 'symmetry', + 'avg_period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'fitness', + 'cons_fitness' + ) + + # add proper labels soon... + measures_labels = c( + 'Speed (cm/s)', + 'Balance', + 'Contacts', + 'displacement_velocity', + 'Branching', + 'branching_modules_count', + 'Rel number of limbs', + 'extremities', + 'Rel. Length of Limbs', + 'extensiveness', + 'coverage', + 'Rel. Number of Joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'Proportion', + 'width', + 'height', + 'Size', + 'sensors', + 'Symmetry', + 'Average Period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'Fitness', + 'Number of slaves' + ) + + + measures_snapshots_all = NULL + + for (exp in 1:length(experiments_type)) + { + for(run in runs[[exp]]) + { + for (env in 1:length(environments[[exp]])) + { + input_directory <- paste(base_directory, '/', + experiments_type[exp], '_',sep='') + + measures = read.table(paste(input_directory, run, '/data_fullevolution/', + environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE, fill=TRUE) + for( m in 1:length(measures_names)) + { + measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) + } + + snapshots = read.table(paste(input_directory, run,'/selectedpop_', + environments[[exp]][env],"/snapshots_ids.tsv", sep=''), header = TRUE) + + measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') + + measures_snapshots$run = run + measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 + measures_snapshots$run = as.factor(measures_snapshots$run) + measures_snapshots$method = paste(experiments_type[exp], environments[[exp]][env],sep='_') + + if ( is.null(measures_snapshots_all)){ + measures_snapshots_all = measures_snapshots + }else{ + measures_snapshots_all = rbind(measures_snapshots_all, measures_snapshots) + } + } + } + } + + + fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) + + + measures_snapshots_all = sqldf("select * from measures_snapshots_all where cons_fitness IS NOT NULL") + + + + # densities + + measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=199 ",sep='' )) + + measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') + measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') + + for (i in 1:length(measures_names_densities)) + { + + for (j in 1:length(measures_names_densities)) + { + + if(i != j) + { + + graph <- ggplot(measures_snapshots_all_densities, aes_string(x=measures_names_densities[j], y= measures_names_densities[i]))+ + geom_density_2d(aes(colour = method ), alpha=0.7, size=3 )+ + scale_color_manual(values = experiments_type_colors )+ + labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ + theme(legend.position="none" , axis.text=element_text(size=21),axis.title=element_text(size=22), + plot.subtitle=element_text(size=25 )) + + coord_cartesian(ylim = c(0, 1), xlim = c(0, 1)) + ggsave(paste( output_directory ,'/density_',measures_names_densities[i],'_', measures_names_densities[j],'.png', sep=''), graph , + device='png', height = 6, width = 6) + } + + } + } + + measures_averages_gens_1 = list() + measures_averages_gens_2 = list() + + measures_ini = list() + measures_fin = list() + + for (met in 1:length(methods)) + { + + measures_aux = c() + query ='select run, generation' + for (i in 1:length(measures_names)) + { + query = paste(query,', avg(',measures_names[i],') as ', methods[met], '_',measures_names[i],'_avg', sep='') + } + query = paste(query,' from measures_snapshots_all + where method="', methods[met],'" group by run, generation', sep='') + + temp = sqldf(query) + + measures_averages_gens_1[[met]] = temp + + temp = measures_averages_gens_1[[met]] + + temp$generation = as.numeric(temp$generation) + + measures_ini[[met]] = sqldf(paste("select * from temp where generation=0")) + measures_fin[[met]] = sqldf(paste("select * from temp where generation=",gens-1)) + query = 'select generation' + for (i in 1:length(measures_names)) + { + # later renames vars _avg_SUMMARY, just to make it in the same style as the quantile variables + query = paste(query,', avg(', methods[met], '_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_avg', sep='') + query = paste(query,', max(', methods[met],'_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_max', sep='') + query = paste(query,', stdev(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_stdev', sep='') + query = paste(query,', median(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_median', sep='') + + measures_aux = c(measures_aux, paste(methods[met],'_',measures_names[i],'_avg', sep='') ) + } + query = paste(query,' from temp group by generation', sep="") + + temp2 = sqldf(query) + + p <- c(0.25, 0.75) + p_names <- map_chr(p, ~paste0('Q',.x*100, sep="")) + p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>% + set_names(nm = p_names) + + quantiles = data.frame(temp %>% + group_by(generation) %>% + summarize_at(vars(measures_aux), funs(!!!p_funs)) ) + + measures_averages_gens_2[[met]] = sqldf('select * from temp2 inner join quantiles using (generation)') + + } + + + for (met in 1:length(methods)) + { + if(met==1){ + measures_averages_gens = measures_averages_gens_2[[1]] + }else{ + measures_averages_gens = merge(measures_averages_gens, measures_averages_gens_2[[met]], all=TRUE, by = "generation") + } + } + + file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") + + #tests trends in curves and difference between ini and fin generations + + + # ini VS fin + array_wilcoxon = list() + array_wilcoxon2 = list() + + # curve + array_mann = list() + + + for (m in 1:length(methods)) + { + + array_wilcoxon[[m]] = list() + array_mann[[m]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(experiments_type[m],measures_names[i],'ini avg ',as.character( + mean(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon[[m]][[i]] = wilcox.test(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'iniVSfin',measures_names[i],'wilcox p: ',as.character(round(array_wilcoxon[[m]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'iniVSfin',measures_names[i],'wilcox est: ',as.character(round(array_wilcoxon[[m]][[i]]$statistic,4)), sep=' ') + + ), file) + + + #tests trends + array_mann[[m]][[i]] = mk.test(c(array(measures_averages_gens_2[[m]][paste(methods[m],"_",measures_names[i],'_median',sep='')]) )[[1]], + continuity = TRUE) + + + writeLines(c( + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median p', as.character(round(array_mann[[m]][[i]]$p.value,4)),sep=' '), + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median s', as.character(round(array_mann[[m]][[i]]$statistic,4)),sep=' ') + ), file) + + } + + } + + + + # tests final generation among experiments_type + + aux_m = length(methods) + + if (aux_m>1) + { + + # fins + array_wilcoxon2[[1]] = list() + array_wilcoxon2[[2]] = list() + + aux_m = aux_m -1 + count_pairs = 0 + for(m in 1:aux_m) + { + aux = m+1 + for(m2 in aux:length(methods)) + { + + count_pairs = count_pairs+1 + array_wilcoxon2[[1]][[count_pairs]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + writeLines(paste(methods[m2],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon2[[1]][[count_pairs]][[i]] = wilcox.test(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'VS',methods[m],measures_names[i],'fin avg wilcox p: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'VS',methods[m2],measures_names[i],'fin avg wilcox est: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$statistic,4)), sep=' ') + + ), file) + + } + + + array_wilcoxon2[[2]][[count_pairs]] = paste(initials[m],initials[m2],sep='') + + } + } + + } + + close(file) + + # plots measures + + for (type_summary in c('means','quants')) + { + for (i in 1:length(measures_names)) + { + tests1 = '' + tests2 = '' + tests3 = '' + break_aux = 0 + + graph <- ggplot(data=measures_averages_gens, aes(x=generation)) + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg','-',methods[m],'_',measures_names[i],'_stdev',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg','+',methods[m],'_',measures_names[i],'_stdev',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + }else + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg_Q25',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg_Q75',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + } + } + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) + } + + }else{ + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') , colour=shQuote(experiments_labels[m]) ),size=2 ) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') ),size=2, color = experiments_type_colors[m] ) + } + } + + if (length(array_mann)>0) + { + if (length(array_mann[[m]])>0) + { + if(!is.na(array_mann[[m]][[i]]$p.value)) + { + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } + } + } + } + } + + if (length(array_wilcoxon[[m]])>0) + { + for(m in 1:length(methods)) + { + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + { + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } + } + } + } + + if (length(array_wilcoxon2)>0) + { + for(p in 1:length(array_wilcoxon2[[1]])) + { + if (length(array_wilcoxon2[[1]][[p]])>0) + { + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + { + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') + } + } + } + } + } + + + max_y = 0 + min_y = 0 + if (measures_names[i] == 'displacement_velocity_hill' ) { + max_y = 2.5 + min_y = -0.5} + if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' || measures_names[i] == 'joints') { max_y = 1} + if (measures_names[i] == 'head_balance') { min_y = 0.6 } + if (measures_names[i] == 'proportion' ) { max_y = 1} + if (measures_names[i] == 'absolute_size' ) { max_y = 16} + + + graph = graph + labs( y=measures_labels[i], x="Generation", title="Tilted Season") + if (max_y>0) { + graph = graph + coord_cartesian(ylim = c(min_y, max_y)) + } + + if(show_markers == TRUE){ + graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) + } + graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=27),axis.title=element_text(size=25), + plot.subtitle=element_text(size=25 ),plot.title=element_text(size=25 )) + + ggsave(paste( output_directory,'/',type_summary,'_' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 10, width = 10) + + } + + } + + + + for (i in 1:length(measures_names)) + { + + + + all_final_values = data.frame() + for (exp in 1:length(methods)) + { + temp = data.frame( c(measures_fin[[exp]][paste(methods[exp],'_',measures_names[i],'_avg', sep='')])) + colnames(temp) <- 'values' + + temp$type = experiments_labels[exp] + all_final_values = rbind(all_final_values, temp) + } + + g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4) + + labs( x="Environment", y=measures_labels[i], title="Flat Season") + + max_y = 0 + min_y = 0 + if (measures_names[i] == 'displacement_velocity_hill' ) { + g1 = g1 + geom_hline(yintercept=1.32, linetype="dashed", color = "red") + max_y = 4.8 + min_y = -0.5} + if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' || measures_names[i] == 'joints') { max_y = 1.1} + if (measures_names[i] == 'proportion' ) { max_y = 1} + if (measures_names[i] == 'absolute_size' ) { max_y = 16} + + + g1 = g1 + scale_color_manual(values= experiments_type_colors ) + + g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , + plot.title=element_text(size=45), axis.text=element_text(size=45), + axis.title=element_text(size=50), + axis.text.x = element_text(angle = 20, hjust = 0.9), + plot.margin=margin(t = 0.5, r = 0.5, b = 0.5, l = 1.3, unit = "cm"))+ + stat_summary(fun.y = mean, geom="point" ,shape = 16, size=11) + + comps = list( c( 'Baseline', 'Plastic') ) + + g1 = g1 + geom_signif( test="wilcox.test", size=2, textsize=22, + comparisons = comps, + map_signif_level=c("***"=0.001,"**"=0.01, "*"=0.05) ) + if (max_y>0) { + g1 = g1 + coord_cartesian(ylim = c(min_y, max_y)) + } + ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = 10) + + } + + \ No newline at end of file From ffad29e4257c5486d5982efbafa842644bd9f44c Mon Sep 17 00:00:00 2001 From: karinemiras Date: Wed, 12 Feb 2020 16:30:15 +0100 Subject: [PATCH 38/45] reproducible code --- .../baseline_big.py | 0 ...bots_summary_renders_journal2_tilted_big.r | 86 +++ .../consolidate_experiments.py | 6 +- .../plasticoding_frontiers2020/flat_big.py | 150 +++++ .../plasticoding_frontiers2020/plastic_big.py | 0 .../run-experiments | 25 +- .../summary_measures_journal2_tilted_big_1.R | 528 ++++++++++++++++++ .../summary_measures_journal2_tilted_big_2.R | 365 +++++++++++- .../summary_measures_journal2_tilted_big_3.R | 51 +- .../plasticoding_frontiers2020/tilted_big.py | 150 +++++ 10 files changed, 1315 insertions(+), 46 deletions(-) mode change 100755 => 100644 experiments/plasticoding_frontiers2020/baseline_big.py create mode 100644 experiments/plasticoding_frontiers2020/flat_big.py mode change 100755 => 100644 experiments/plasticoding_frontiers2020/plastic_big.py mode change 100755 => 100644 experiments/plasticoding_frontiers2020/run-experiments create mode 100644 experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_1.R create mode 100644 experiments/plasticoding_frontiers2020/tilted_big.py diff --git a/experiments/plasticoding_frontiers2020/baseline_big.py b/experiments/plasticoding_frontiers2020/baseline_big.py old mode 100755 new mode 100644 diff --git a/experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r b/experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r index e69de29bb2..1faba877a2 100644 --- a/experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r +++ b/experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r @@ -0,0 +1,86 @@ + +library(sqldf) +require('magick') + +##### change paths/labels/params here ##### + + +paths = c( 'baseline_big', 'plastic_big' ) + +environments = list( + c( 'plane','tilted5'), + c( 'plane','tilted5') +) + +base_directory <- paste('journal2/', sep='') + +runs = list( c(1:20), c(1:20) ) +gens = 200 +pop = 100 +num_top = 1 + +analysis = 'images' + +##### change paths/labels/params here ##### + +output_directory = paste(base_directory,analysis, sep='') + + +file <-file(paste(output_directory,'/best.txt',sep=''), open="w") + +# for each method +for(m in 1:length(paths)) +{ + # for each repetition + for (exp in runs[[m]]) + { + + input_directory1 <- paste(base_directory, paths[m],'_',exp, '/data_fullevolution/',environments[[m]][1],sep='') + input_directory2 <- paste(base_directory, paths[m],'_',exp, '/selectedpop_', sep='') + + ids_gens = data.frame() + list = strsplit(list.files(paste(input_directory2, environments[[m]][1],'/selectedpop_',gens-1, sep='')), ' ') + for(geno in 1:pop) + { + genome = data.frame(cbind(c(gens), c(strsplit(strsplit(list [[geno]],'_')[[1]][3],'.png')[[1]][1] ))) + names(genome)<-c('generation','robot_id') + ids_gens = rbind(ids_gens,genome) + } + + measures = read.table(paste(input_directory1,"/all_measures.tsv", sep=''), header = TRUE, fill=TRUE) + bests = sqldf(paste("select robot_id, cons_fitness from measures inner join ids_gens using (robot_id) order by cons_fitness desc limit",num_top)) + + for(b in 1:nrow(bests)) + { + + writeLines( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] ), file ) + print( paste(paths[m],'exp',exp,bests[b,'robot_id'] ,bests[b,'cons_fitness'] )) + + phenotype= bests[b,'robot_id'] + + for (env in 1:length(environments[[m]])) + { + patha = paste(input_directory2, environments[[m]][env], "/selectedpop_",gens-1,sep="") + + body <- list.files(patha, paste("body_robot_",phenotype,".png$",sep=""), full.names = TRUE) + body = image_read(body) + body = image_scale(body, "100x100") + body = image_border(image_background(body, "white"), "white", "5x5") + + if(b == 1 && env == 1) + { + bodies = body + }else{ + bodies = c(bodies, body) + } + } + } + + side_by_side = image_append(bodies, stack=F) + image_write(side_by_side, path = paste(output_directory,"/",paths[m],'_', environments[[m]][env], "_bodies_best_",exp,".png",sep=''), format = "png") + + } +} + + +close(file) diff --git a/experiments/plasticoding_frontiers2020/consolidate_experiments.py b/experiments/plasticoding_frontiers2020/consolidate_experiments.py index 21df238414..fbdd9dc878 100644 --- a/experiments/plasticoding_frontiers2020/consolidate_experiments.py +++ b/experiments/plasticoding_frontiers2020/consolidate_experiments.py @@ -4,12 +4,14 @@ # set these variables according to your experiments # dirpath = 'data/' experiments_type = [ - + 'flat_big', +'tilted_big', 'plastic_big' ,'baseline_big' ] environments = { - + 'flat_big': ['plane'], +'tilted_big': ['tilted5'], 'plastic_big': ['plane','tilted5'] ,'baseline_big': ['plane','tilted5'] } diff --git a/experiments/plasticoding_frontiers2020/flat_big.py b/experiments/plasticoding_frontiers2020/flat_big.py new file mode 100644 index 0000000000..9449d9ff61 --- /dev/null +++ b/experiments/plasticoding_frontiers2020/flat_big.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 200 + population_size = 100 + offspring_size = 100 + front = None + + # environment world and z-start + environments = {'plane': 0.03} + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=False, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function_plane(robot_manager, robot): + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + fitness_function = {'plane': fitness_function_plane} + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... diff --git a/experiments/plasticoding_frontiers2020/plastic_big.py b/experiments/plasticoding_frontiers2020/plastic_big.py old mode 100755 new mode 100644 diff --git a/experiments/plasticoding_frontiers2020/run-experiments b/experiments/plasticoding_frontiers2020/run-experiments old mode 100755 new mode 100644 index 86bb03c846..a48cea1da7 --- a/experiments/plasticoding_frontiers2020/run-experiments +++ b/experiments/plasticoding_frontiers2020/run-experiments @@ -20,16 +20,25 @@ while true done done - - - + while true + do + for i in {1..20}; do + ./revolve.py --experiment-name karines_experiments/data/flat_big_$i --run $i --manager experiments/karines_experiments/flat_big.py --n-cores 4 --port-start 11141 --evaluation-time 50; -while true + sleep 5s + done +done + + + while true do - sleep 900s; - kill $( ps aux | grep 'gzserver' | awk '{print $2}'); - kill $( ps aux | grep 'revolve.py' | awk '{print $2}'); - sleep 60s; + for i in {1..20}; do + ./revolve.py --experiment-name karines_experiments/data/tilted_big_$i --run $i --manager experiments/karines_experiments/tilted_big.py --n-cores 4 --port-start 11141 --evaluation-time 50; + + sleep 5s + done done + + diff --git a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_1.R b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_1.R new file mode 100644 index 0000000000..0beb61d404 --- /dev/null +++ b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_1.R @@ -0,0 +1,528 @@ + library(ggplot2) + library(sqldf) + library(plyr) + library(dplyr) + library(trend) + library(purrr) + library(ggsignif) + + base_directory <-paste('journal2', sep='') + +analysis = 'analysis_journal2_tilted_big_1' + +output_directory = paste(base_directory,'/',analysis ,sep='') + +#### CHANGE THE PARAMETERS HERE #### + + +experiments_type = c( 'flat_big', 'tilted_big' ) + +environments = list(c( 'plane'), c('tilted5') ) + +methods = c() +for (exp in 1:length(experiments_type)) +{ + for (env in 1:length(environments[[exp]])) + { + methods = c(methods, paste(experiments_type[exp], environments[[exp]][env], sep='_')) + } +} + +initials = c( 'p', 't' ) + +experiments_labels = c( 'Static: Flat', 'Static: Tilted') + + runs = list( c(1:20), c(1:20) ) + + gens = 200 + pop = 100 + + #### CHANGE THE PARAMETERS HERE #### + + sig = 0.05 + line_size = 30 + show_markers = TRUE#FALSE + show_legends = FALSE + experiments_type_colors = c( '#009999' , '#cc9900' ) # weird green and weird yellow + + measures_names = c( + 'displacement_velocity_hill', + 'head_balance', + 'contacts', + 'displacement_velocity', + 'branching', + 'branching_modules_count', + 'limbs', + 'extremities', + 'length_of_limbs', + 'extensiveness', + 'coverage', + 'joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'proportion', + 'width', + 'height', + 'absolute_size', + 'sensors', + 'symmetry', + 'avg_period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'fitness', + 'cons_fitness' + ) + + # add proper labels soon... + measures_labels = c( + 'Speed (cm/s)', + 'Balance', + 'Contacts', + 'displacement_velocity', + 'Branching', + 'branching_modules_count', + 'Rel number of limbs', + 'extremities', + 'Rel. Length of Limbs', + 'extensiveness', + 'coverage', + 'Rel. Number of Joints', + 'hinge_count', + 'active_hinges_count', + 'brick_count', + 'touch_sensor_count', + 'brick_sensor_count', + 'Proportion', + 'width', + 'height', + 'Size', + 'sensors', + 'Symmetry', + 'Average Period', + 'dev_period', + 'avg_phase_offset', + 'dev_phase_offset', + 'avg_amplitude', + 'dev_amplitude', + 'avg_intra_dev_params', + 'avg_inter_dev_params', + 'sensors_reach', + 'recurrence', + 'synaptic_reception', + 'Fitness', + 'Number of slaves' + ) + + + measures_snapshots_all = NULL + + for (exp in 1:length(experiments_type)) + { + for(run in runs[[exp]]) + { + for (env in 1:length(environments[[exp]])) + { + input_directory <- paste(base_directory, '/', + experiments_type[exp], '_',sep='') + + measures = read.table(paste(input_directory, run, '/data_fullevolution/', + environments[[exp]][env], "/all_measures.tsv", sep=''), header = TRUE, fill=TRUE) + for( m in 1:length(measures_names)) + { + measures[measures_names[m]] = as.numeric(as.character(measures[[measures_names[m]]])) + } + + snapshots = read.table(paste(input_directory, run,'/selectedpop_', + environments[[exp]][env],"/snapshots_ids.tsv", sep=''), header = TRUE) + + measures_snapshots = sqldf('select * from snapshots inner join measures using(robot_id) order by generation') + + measures_snapshots$run = run + measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 + measures_snapshots$run = as.factor(measures_snapshots$run) + measures_snapshots$method = paste(experiments_type[exp], environments[[exp]][env],sep='_') + + if ( is.null(measures_snapshots_all)){ + measures_snapshots_all = measures_snapshots + }else{ + measures_snapshots_all = rbind(measures_snapshots_all, measures_snapshots) + } + } + } + } + + + fail_test = sqldf(paste("select method,run,generation,count(*) as c from measures_snapshots_all group by 1,2,3 having c<",gens," order by 4")) + + + measures_snapshots_all = sqldf("select * from measures_snapshots_all where cons_fitness IS NOT NULL") + + + + + measures_averages_gens_1 = list() + measures_averages_gens_2 = list() + + measures_ini = list() + measures_fin = list() + + for (met in 1:length(methods)) + { + + measures_aux = c() + query ='select run, generation' + for (i in 1:length(measures_names)) + { + query = paste(query,', avg(',measures_names[i],') as ', methods[met], '_',measures_names[i],'_avg', sep='') + } + query = paste(query,' from measures_snapshots_all + where method="', methods[met],'" group by run, generation', sep='') + + temp = sqldf(query) + + measures_averages_gens_1[[met]] = temp + + temp = measures_averages_gens_1[[met]] + + temp$generation = as.numeric(temp$generation) + + measures_ini[[met]] = sqldf(paste("select * from temp where generation=0")) + measures_fin[[met]] = sqldf(paste("select * from temp where generation=",gens-1)) + query = 'select generation' + for (i in 1:length(measures_names)) + { + # later renames vars _avg_SUMMARY, just to make it in the same style as the quantile variables + query = paste(query,', avg(', methods[met], '_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_avg', sep='') + query = paste(query,', max(', methods[met],'_',measures_names[i],'_avg) as ' + ,methods[met],'_',measures_names[i],'_max', sep='') + query = paste(query,', stdev(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_stdev', sep='') + query = paste(query,', median(', methods[met],'_',measures_names[i],'_avg) as ' + , methods[met],'_',measures_names[i],'_median', sep='') + + measures_aux = c(measures_aux, paste(methods[met],'_',measures_names[i],'_avg', sep='') ) + } + query = paste(query,' from temp group by generation', sep="") + + temp2 = sqldf(query) + + p <- c(0.25, 0.75) + p_names <- map_chr(p, ~paste0('Q',.x*100, sep="")) + p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>% + set_names(nm = p_names) + + quantiles = data.frame(temp %>% + group_by(generation) %>% + summarize_at(vars(measures_aux), funs(!!!p_funs)) ) + + measures_averages_gens_2[[met]] = sqldf('select * from temp2 inner join quantiles using (generation)') + + } + + + for (met in 1:length(methods)) + { + if(met==1){ + measures_averages_gens = measures_averages_gens_2[[1]] + }else{ + measures_averages_gens = merge(measures_averages_gens, measures_averages_gens_2[[met]], all=TRUE, by = "generation") + } + } + + file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") + + #tests trends in curves and difference between ini and fin generations + + + # ini VS fin + array_wilcoxon = list() + array_wilcoxon2 = list() + + # curve + array_mann = list() + + + for (m in 1:length(methods)) + { + + array_wilcoxon[[m]] = list() + array_mann[[m]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(experiments_type[m],measures_names[i],'ini avg ',as.character( + mean(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon[[m]][[i]] = wilcox.test(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'iniVSfin',measures_names[i],'wilcox p: ',as.character(round(array_wilcoxon[[m]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'iniVSfin',measures_names[i],'wilcox est: ',as.character(round(array_wilcoxon[[m]][[i]]$statistic,4)), sep=' ') + + ), file) + + + #tests trends + array_mann[[m]][[i]] = mk.test(c(array(measures_averages_gens_2[[m]][paste(methods[m],"_",measures_names[i],'_median',sep='')]) )[[1]], + continuity = TRUE) + + + writeLines(c( + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median p', as.character(round(array_mann[[m]][[i]]$p.value,4)),sep=' '), + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median s', as.character(round(array_mann[[m]][[i]]$statistic,4)),sep=' ') + ), file) + + } + + } + + + + # tests final generation among experiments_type + + aux_m = length(methods) + + if (aux_m>1) + { + + # fins + array_wilcoxon2[[1]] = list() + array_wilcoxon2[[2]] = list() + + aux_m = aux_m -1 + count_pairs = 0 + for(m in 1:aux_m) + { + aux = m+1 + for(m2 in aux:length(methods)) + { + + count_pairs = count_pairs+1 + array_wilcoxon2[[1]][[count_pairs]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + writeLines(paste(methods[m2],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon2[[1]][[count_pairs]][[i]] = wilcox.test(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'VS',methods[m],measures_names[i],'fin avg wilcox p: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'VS',methods[m2],measures_names[i],'fin avg wilcox est: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$statistic,4)), sep=' ') + + ), file) + + } + + + array_wilcoxon2[[2]][[count_pairs]] = paste(initials[m],initials[m2],sep='') + + } + } + + } + + close(file) + + # plots measures + + for (type_summary in c('means','quants')) + { + + + for (i in 1:length(measures_names)) + { + tests1 = '' + tests2 = '' + tests3 = '' + break_aux = 0 + + graph <- ggplot(data=measures_averages_gens, aes(x=generation)) + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg','-',methods[m],'_',measures_names[i],'_stdev',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg','+',methods[m],'_',measures_names[i],'_stdev',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + }else + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg_Q25',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg_Q75',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + } + } + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) + } + + }else{ + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') , colour=shQuote(experiments_labels[m]) ),size=2 ) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') ),size=2, color = experiments_type_colors[m] ) + } + } + + if (length(array_mann)>0) + { + if (length(array_mann[[m]])>0) + { + if(!is.na(array_mann[[m]][[i]]$p.value)) + { + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } + } + } + } + } + + if (length(array_wilcoxon[[m]])>0) + { + for(m in 1:length(methods)) + { + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + { + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } + } + } + } + + if (length(array_wilcoxon2)>0) + { + for(p in 1:length(array_wilcoxon2[[1]])) + { + if (length(array_wilcoxon2[[1]][[p]])>0) + { + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + { + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') + } + } + } + } + } + + max_y = 0 + min_y = 0 + if (measures_names[i] == 'displacement_velocity_hill' ) { + max_y = 6 + min_y = -0.5} + if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' || measures_names[i] == 'joints') { max_y = 1.1} + if (measures_names[i] == 'proportion' ) { max_y = 1} + if (measures_names[i] == 'absolute_size' ) { max_y = 16} + + + graph = graph + labs( y=measures_labels[i], x="Generation") + if (max_y>0) { + graph = graph + coord_cartesian(ylim = c(min_y, max_y)) + } + + if(show_markers == TRUE){ + graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) + } + graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=27),axis.title=element_text(size=25), + plot.subtitle=element_text(size=25 )) + + ggsave(paste( output_directory,'/',type_summary,'_' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 10, width = 10) + } + + } + + + + + for (i in 1:length(measures_names)) + { + + max_y = 0 + min_y = 0 + if (measures_names[i] == 'displacement_velocity_hill' ) { + max_y = 6 + min_y = -0.5} + if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' || measures_names[i] == 'joints') { max_y = 1.1} + if (measures_names[i] == 'proportion' ) { max_y = 1} + if (measures_names[i] == 'absolute_size' ) { max_y = 16} + + all_final_values = data.frame() + for (exp in 1:length(methods)) + { + temp = data.frame( c(measures_fin[[exp]][paste(methods[exp],'_',measures_names[i],'_avg', sep='')])) + colnames(temp) <- 'values' + + temp$type = experiments_labels[exp] + all_final_values = rbind(all_final_values, temp) + } + + g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4) + + labs( x="Environment", y=measures_labels[i]) + + g1 = g1 + scale_color_manual(values=experiments_type_colors) + + g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , + plot.title=element_text(size=40), axis.text=element_text(size=45), + axis.title=element_text(size=50), + axis.text.x = element_text(angle = 20, hjust = 1))+ + stat_summary(fun.y = mean, geom="point" ,shape = 16, size=11) + + comps = list(c( 'Static: Flat', 'Static: Tilted') ) + + g1 = g1 + geom_signif( test="wilcox.test", size=2, textsize=22, + comparisons = comps, + map_signif_level=c("***"=0.001,"**"=0.01, "*"=0.05) ) + if (max_y>0) { + g1 = g1 + coord_cartesian(ylim = c(min_y, max_y)) + } + + ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = 10) + + } + + \ No newline at end of file diff --git a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R index 93b86f4236..834dcbb729 100644 --- a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R +++ b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R @@ -6,7 +6,7 @@ library(purrr) library(ggsignif) - base_directory <-paste('data', sep='') + base_directory <-paste('journal2', sep='') analysis = 'analysis_journal2_tilted_big_2' @@ -30,8 +30,9 @@ for (exp in 1:length(experiments_type)) initials = c( 'b', 'p' ) experiments_labels = c( 'Baseline' , 'Plastic') +experiments_labels2 = c( 'Baseline: Flat' , 'Plastic: Flat') - runs = list( c(1:20), c(1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,21,22) ) + runs = list( c(1:20), c(1:20) ) gens = 200 pop = 100 @@ -106,7 +107,7 @@ experiments_labels = c( 'Baseline' , 'Plastic') 'width', 'height', 'Size', - 'sensors', + 'Sensors', 'Symmetry', 'Average Period', 'dev_period', @@ -116,8 +117,8 @@ experiments_labels = c( 'Baseline' , 'Plastic') 'dev_amplitude', 'avg_intra_dev_params', 'avg_inter_dev_params', - 'sensors_reach', - 'recurrence', + 'Sensors Reach', + 'Recurrence', 'synaptic_reception', 'Fitness', 'Number of slaves' @@ -151,6 +152,7 @@ experiments_labels = c( 'Baseline' , 'Plastic') measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 measures_snapshots$run = as.factor(measures_snapshots$run) measures_snapshots$method = paste(experiments_type[exp], environments[[exp]][env],sep='_') + measures_snapshots$method_label = experiments_labels2[exp] if ( is.null(measures_snapshots_all)){ measures_snapshots_all = measures_snapshots @@ -171,10 +173,10 @@ experiments_labels = c( 'Baseline' , 'Plastic') # densities - measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=199 ",sep='' )) + measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=199",sep='' )) - measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') - measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') + measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs', 'recurrence', 'sensors', 'sensors_reach','displacement_velocity_hill') + measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs', 'Recurrence', 'Sensors', 'Sensors Reach', 'Speed (cm/s)') for (i in 1:length(measures_names_densities)) { @@ -184,16 +186,21 @@ experiments_labels = c( 'Baseline' , 'Plastic') if(i != j) { + + summary = sqldf(paste('select method_label,',measures_names_densities[j], ' as x,', measures_names_densities[i], + " as y, count(*) as n from measures_snapshots_all_densities + group by 1,2 order by n", sep='')) - graph <- ggplot(measures_snapshots_all_densities, aes_string(x=measures_names_densities[j], y= measures_names_densities[i]))+ - geom_density_2d(aes(colour = method ), alpha=0.7, size=3 )+ - scale_color_manual(values = experiments_type_colors )+ - labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ - theme(legend.position="none" , axis.text=element_text(size=21),axis.title=element_text(size=22), - plot.subtitle=element_text(size=25 )) + - coord_cartesian(ylim = c(0, 1), xlim = c(0, 1)) + graph = ggplot(data=summary,aes(x=x ,y=y ,fill=n)) + + stat_density_2d(geom = "raster", aes(fill = stat(density)), contour = FALSE)+ + labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ + theme(legend.position="none" , strip.text = element_text( size = 20 ), plot.title=element_text(size=25), + axis.text=element_text(size=17),axis.title=element_text(size=20) ) + + coord_cartesian(ylim = c(0, 1), xlim = c(0, 1))+ facet_grid(. ~ method_label) + ggsave(paste( output_directory ,'/density_',measures_names_densities[i],'_', measures_names_densities[j],'.png', sep=''), graph , - device='png', height = 6, width = 6) + device='png', height = 6, width = 10) + } } @@ -240,4 +247,328 @@ experiments_labels = c( 'Baseline' , 'Plastic') query = paste(query,', median(', methods[met],'_',measures_names[i],'_avg) as ' , methods[met],'_',measures_names[i],'_median', sep='') - \ No newline at end of file + measures_aux = c(measures_aux, paste(methods[met],'_',measures_names[i],'_avg', sep='') ) + } + query = paste(query,' from temp group by generation', sep="") + + temp2 = sqldf(query) + + p <- c(0.25, 0.75) + p_names <- map_chr(p, ~paste0('Q',.x*100, sep="")) + p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>% + set_names(nm = p_names) + + quantiles = data.frame(temp %>% + group_by(generation) %>% + summarize_at(vars(measures_aux), funs(!!!p_funs)) ) + + measures_averages_gens_2[[met]] = sqldf('select * from temp2 inner join quantiles using (generation)') + + } + + + for (met in 1:length(methods)) + { + if(met==1){ + measures_averages_gens = measures_averages_gens_2[[1]] + }else{ + measures_averages_gens = merge(measures_averages_gens, measures_averages_gens_2[[met]], all=TRUE, by = "generation") + } + } + + file <-file(paste(output_directory,'/trends.txt',sep=''), open="w") + + #tests trends in curves and difference between ini and fin generations + + + # ini VS fin + array_wilcoxon = list() + array_wilcoxon2 = list() + + # curve + array_mann = list() + + + for (m in 1:length(methods)) + { + + array_wilcoxon[[m]] = list() + array_mann[[m]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(experiments_type[m],measures_names[i],'ini avg ',as.character( + mean(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon[[m]][[i]] = wilcox.test(c(array(measures_ini[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'iniVSfin',measures_names[i],'wilcox p: ',as.character(round(array_wilcoxon[[m]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'iniVSfin',measures_names[i],'wilcox est: ',as.character(round(array_wilcoxon[[m]][[i]]$statistic,4)), sep=' ') + + ), file) + + + #tests trends + array_mann[[m]][[i]] = mk.test(c(array(measures_averages_gens_2[[m]][paste(methods[m],"_",measures_names[i],'_median',sep='')]) )[[1]], + continuity = TRUE) + + + writeLines(c( + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median p', as.character(round(array_mann[[m]][[i]]$p.value,4)),sep=' '), + paste(experiments_type[m],measures_names[i], ' Mann-Kendall median s', as.character(round(array_mann[[m]][[i]]$statistic,4)),sep=' ') + ), file) + + } + + } + + + + # tests final generation among experiments_type + + aux_m = length(methods) + + if (aux_m>1) + { + + # fins + array_wilcoxon2[[1]] = list() + array_wilcoxon2[[2]] = list() + + aux_m = aux_m -1 + count_pairs = 0 + for(m in 1:aux_m) + { + aux = m+1 + for(m2 in aux:length(methods)) + { + + count_pairs = count_pairs+1 + array_wilcoxon2[[1]][[count_pairs]] = list() + + for (i in 1:length(measures_names)) + { + + writeLines(paste(methods[m],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + writeLines(paste(methods[m2],measures_names[i],'fin avg ',as.character( + mean(c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]) )[[1]]) ) ,sep=" "), file ) + + array_wilcoxon2[[1]][[count_pairs]][[i]] = wilcox.test(c(array(measures_fin[[m]][paste(methods[m],"_",measures_names[i],"_avg",sep='')]))[[1]] , + c(array(measures_fin[[m2]][paste(methods[m2],"_",measures_names[i],"_avg",sep='')]))[[1]] + ) + + writeLines(c( + paste(methods[m],'VS',methods[m],measures_names[i],'fin avg wilcox p: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$p.value,4)), sep=' ') + ,paste(methods[m],'VS',methods[m2],measures_names[i],'fin avg wilcox est: ',as.character(round(array_wilcoxon2[[1]][[count_pairs]][[i]]$statistic,4)), sep=' ') + + ), file) + + } + + + array_wilcoxon2[[2]][[count_pairs]] = paste(initials[m],initials[m2],sep='') + + } + } + + } + + close(file) + + + + # plots measures + + for (type_summary in c('means','quants')) + { + + + for (i in 1:length(measures_names)) + { + tests1 = '' + tests2 = '' + tests3 = '' + break_aux = 0 + + graph <- ggplot(data=measures_averages_gens, aes(x=generation)) + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg','-',methods[m],'_',measures_names[i],'_stdev',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg','+',methods[m],'_',measures_names[i],'_stdev',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + }else + { + graph = graph + geom_ribbon(aes_string(ymin=paste(methods[m],'_',measures_names[i],'_avg_Q25',sep=''), + ymax=paste(methods[m],'_',measures_names[i],'_avg_Q75',sep='') ), + fill=experiments_type_colors[m] , color=experiments_type_colors[m],alpha=0.2) + } + } + + for(m in 1:length(methods)) + { + if(type_summary == 'means') + { + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep=''), colour=shQuote(experiments_labels[m]) ), size=2) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_avg',sep='') ),size=2, color = experiments_type_colors[m]) + } + + }else{ + if(show_legends == TRUE){ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') , colour=shQuote(experiments_labels[m]) ),size=2 ) + }else{ + graph = graph + geom_line(aes_string(y=paste(methods[m],'_',measures_names[i],'_median',sep='') ),size=2, color = experiments_type_colors[m] ) + } + } + + if (length(array_mann)>0) + { + if (length(array_mann[[m]])>0) + { + if(!is.na(array_mann[[m]][[i]]$p.value)) + { + if(array_mann[[m]][[i]]$p.value<=sig) + { + if(array_mann[[m]][[i]]$statistic>0){ direction = "/ "} else { direction = "\\ "} + tests1 = paste(tests1, initials[m],direction,sep="") + } + } + } + } + } + + if (length(array_wilcoxon[[m]])>0) + { + for(m in 1:length(methods)) + { + if(!is.na(array_wilcoxon[[m]][[i]]$p.value)) + { + if(array_wilcoxon[[m]][[i]]$p.value<=sig) + { + tests2 = paste(tests2, initials[m],'C ', sep='') + } + } + } + } + + if (length(array_wilcoxon2)>0) + { + for(p in 1:length(array_wilcoxon2[[1]])) + { + if (length(array_wilcoxon2[[1]][[p]])>0) + { + if(!is.na(array_wilcoxon2[[1]][[p]][[i]]$p.value)) + { + if(array_wilcoxon2[[1]][[p]][[i]]$p.value<=sig) + { + if(nchar(tests3)>line_size && break_aux == 0){ + tests3 = paste(tests3, '\n') + break_aux = 1 + } + tests3 = paste(tests3, array_wilcoxon2[[2]][[p]],'D ',sep='') + } + } + } + } + } + + + max_y = 0 + min_y = 0 + if (measures_names[i] == 'displacement_velocity_hill' ) { + max_y = 2.5 + min_y = -0.5} + if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' || measures_names[i] == 'joints') { max_y = 1} + if (measures_names[i] == 'proportion' ) { max_y = 1} + if (measures_names[i] == 'absolute_size' ) { max_y = 16} + + + graph = graph + labs( y=measures_labels[i], x="Generation", title="Flat Season") + if (max_y>0) { + graph = graph + coord_cartesian(ylim = c(min_y, max_y)) + } + + if(show_markers == TRUE){ + graph = graph + labs( y=measures_labels[i], x="Generation", subtitle = paste(tests1,'\n', tests2, '\n', tests3, sep='')) + } + graph = graph + theme(legend.position="bottom" , legend.text=element_text(size=20), axis.text=element_text(size=27),axis.title=element_text(size=25), + plot.subtitle=element_text(size=25 ),plot.title=element_text(size=25 )) + + ggsave(paste( output_directory,'/',type_summary,'_' ,measures_names[i],'_generations.pdf', sep=''), graph , device='pdf', height = 10, width = 10) + + } + + } + + + + for (i in 1:length(measures_names)) + { + + + all_final_values = data.frame() + for (exp in 1:length(methods)) + { + temp = data.frame( c(measures_fin[[exp]][paste(methods[exp],'_',measures_names[i],'_avg', sep='')])) + colnames(temp) <- 'values' + + temp$type = experiments_labels[exp] + all_final_values = rbind(all_final_values, temp) + } + + g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4) + + labs( x="Environment", y=measures_labels[i], title="Flat Season") + + + max_y = 0 + min_y = 0 + if (measures_names[i] == 'displacement_velocity_hill' ) { + g1 = g1 + geom_hline(yintercept=1.32, linetype="dashed", color = "red") + max_y = 4.8 + min_y = -0.5} + if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' + || measures_names[i] == 'joints' || measures_names[i] == 'sensors_reach') { max_y = 1.15} + if (measures_names[i] == 'recurrence' ) { max_y = 0.8} + if (measures_names[i] == 'sensors' ) { max_y = 0.6} + if (measures_names[i] == 'proportion' ) { max_y = 1} + if (measures_names[i] == 'absolute_size' ) { max_y = 16} + + + g1 = g1 + scale_color_manual(values= experiments_type_colors ) + + g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , + plot.title=element_text(size=45), axis.text=element_text(size=45), + axis.title=element_text(size=50), + axis.text.x = element_text(angle = 20, hjust = 0.9), + plot.margin=margin(t = 0.5, r = 0.5, b = 0.5, l = 1.3, unit = "cm"))+ + stat_summary(fun.y = mean, geom="point" ,shape = 16, size=11) + + comps = list( c( 'Baseline', 'Plastic') ) + + g1 = g1 + geom_signif( test="wilcox.test", size=2, textsize=22, + comparisons = comps, + map_signif_level=c("***"=0.001,"**"=0.01, "*"=0.05) ) + if (max_y>0) { + g1 = g1 + coord_cartesian(ylim = c(min_y, max_y)) + } + + ggsave(paste(output_directory,"/",measures_names[i],"_boxes.pdf",sep = ""), g1, device = "pdf", height=18, width = 10) + + } + + \ No newline at end of file diff --git a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R index 6f57f18d83..95ac49c970 100644 --- a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R +++ b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R @@ -6,7 +6,7 @@ library(purrr) library(ggsignif) - base_directory <-paste('data', sep='') + base_directory <-paste('journal2', sep='') analysis = 'analysis_journal2_tilted_big_3' @@ -15,6 +15,7 @@ output_directory = paste(base_directory,'/',analysis ,sep='') #### CHANGE THE PARAMETERS HERE #### experiments_type = c( 'baseline_big', 'plastic_big' ) +experiments_labels2 = c( 'Baseline: Tilted' , 'Plastic: Tilted') environments = list( c( 'tilted5'), c( 'tilted5') ) @@ -30,8 +31,9 @@ for (exp in 1:length(experiments_type)) initials = c( 'b', 'p' ) experiments_labels = c( 'Baseline' , 'Plastic') +experiments_labels2 = c( 'Baseline: Tilted' , 'Plastic: Tilted') - runs = list( c(1:20), c(1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,21,22) ) + runs = list( c(1:20),c(1:20) ) gens = 200 pop = 100 @@ -106,7 +108,7 @@ experiments_labels = c( 'Baseline' , 'Plastic') 'width', 'height', 'Size', - 'sensors', + 'Sensors', 'Symmetry', 'Average Period', 'dev_period', @@ -116,8 +118,8 @@ experiments_labels = c( 'Baseline' , 'Plastic') 'dev_amplitude', 'avg_intra_dev_params', 'avg_inter_dev_params', - 'sensors_reach', - 'recurrence', + 'Sensors Reach', + 'Recurrence', 'synaptic_reception', 'Fitness', 'Number of slaves' @@ -151,6 +153,7 @@ experiments_labels = c( 'Baseline' , 'Plastic') measures_snapshots$displacement_velocity_hill = measures_snapshots$displacement_velocity_hill*100 measures_snapshots$run = as.factor(measures_snapshots$run) measures_snapshots$method = paste(experiments_type[exp], environments[[exp]][env],sep='_') + measures_snapshots$method_label = experiments_labels2[exp] if ( is.null(measures_snapshots_all)){ measures_snapshots_all = measures_snapshots @@ -171,10 +174,10 @@ experiments_labels = c( 'Baseline' , 'Plastic') # densities - measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=199 ",sep='' )) + measures_snapshots_all_densities = sqldf(paste("select * from measures_snapshots_all where generation=199",sep='' )) - measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs') - measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs') + measures_names_densities = c('length_of_limbs','proportion', 'absolute_size','head_balance','joints', 'limbs', 'recurrence', 'sensors', 'sensors_reach','displacement_velocity_hill') + measures_labels_densities = c('Rel. Length of Limbs','Proportion', 'Size','Balance','Rel. Number of Joints', 'Rel. Number of Limbs', 'Recurrence', 'Sensors', 'Sensors Reach', 'Speed (cm/s)') for (i in 1:length(measures_names_densities)) { @@ -185,20 +188,28 @@ experiments_labels = c( 'Baseline' , 'Plastic') if(i != j) { - graph <- ggplot(measures_snapshots_all_densities, aes_string(x=measures_names_densities[j], y= measures_names_densities[i]))+ - geom_density_2d(aes(colour = method ), alpha=0.7, size=3 )+ - scale_color_manual(values = experiments_type_colors )+ - labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ - theme(legend.position="none" , axis.text=element_text(size=21),axis.title=element_text(size=22), - plot.subtitle=element_text(size=25 )) + - coord_cartesian(ylim = c(0, 1), xlim = c(0, 1)) + summary = sqldf(paste('select method_label,',measures_names_densities[j], ' as x,', measures_names_densities[i], + " as y, count(*) as n from measures_snapshots_all_densities + group by 1,2 order by n", sep='')) + + graph = ggplot(data=summary,aes(x=x ,y=y ,fill=n)) + + stat_density_2d(geom = "raster", aes(fill = stat(density)), contour = FALSE)+ + labs( x = measures_labels_densities[j], y= measures_labels_densities[i] )+ + theme(legend.position="none" , strip.text = element_text( size = 20 ), plot.title=element_text(size=25), + axis.text=element_text(size=17),axis.title=element_text(size=20) ) + + coord_cartesian(ylim = c(0, 1), xlim = c(0, 1))+ facet_grid(. ~ method_label) + ggsave(paste( output_directory ,'/density_',measures_names_densities[i],'_', measures_names_densities[j],'.png', sep=''), graph , - device='png', height = 6, width = 6) + device='png', height = 6, width = 10) + + } } } + + measures_averages_gens_1 = list() measures_averages_gens_2 = list() @@ -510,7 +521,6 @@ experiments_labels = c( 'Baseline' , 'Plastic') { - all_final_values = data.frame() for (exp in 1:length(methods)) { @@ -523,7 +533,7 @@ experiments_labels = c( 'Baseline' , 'Plastic') g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4) + - labs( x="Environment", y=measures_labels[i], title="Flat Season") + labs( x="Environment", y=measures_labels[i], title="Tilted Season") max_y = 0 min_y = 0 @@ -531,7 +541,10 @@ experiments_labels = c( 'Baseline' , 'Plastic') g1 = g1 + geom_hline(yintercept=1.32, linetype="dashed", color = "red") max_y = 4.8 min_y = -0.5} - if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' || measures_names[i] == 'joints') { max_y = 1.1} + if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' + || measures_names[i] == 'joints' || measures_names[i] == 'sensors_reach') { max_y = 1.15} + if (measures_names[i] == 'recurrence' ) { max_y = 0.8} + if (measures_names[i] == 'sensors' ) { max_y = 0.6} if (measures_names[i] == 'proportion' ) { max_y = 1} if (measures_names[i] == 'absolute_size' ) { max_y = 16} diff --git a/experiments/plasticoding_frontiers2020/tilted_big.py b/experiments/plasticoding_frontiers2020/tilted_big.py new file mode 100644 index 0000000000..057a57522e --- /dev/null +++ b/experiments/plasticoding_frontiers2020/tilted_big.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +import asyncio + +from pyrevolve import parser +from pyrevolve.evolution import fitness +from pyrevolve.evolution.selection import multiple_selection, tournament_selection +from pyrevolve.evolution.population import Population, PopulationConfig +from pyrevolve.evolution.pop_management.steady_state import steady_state_population_management +from pyrevolve.experiment_management import ExperimentManagement +from pyrevolve.genotype.plasticoding.crossover.crossover import CrossoverConfig +from pyrevolve.genotype.plasticoding.crossover.standard_crossover import standard_crossover +from pyrevolve.genotype.plasticoding.initialization import random_initialization +from pyrevolve.genotype.plasticoding.mutation.mutation import MutationConfig +from pyrevolve.genotype.plasticoding.mutation.standard_mutation import standard_mutation +from pyrevolve.genotype.plasticoding.plasticoding import PlasticodingConfig +from pyrevolve.tol.manage import measures +from pyrevolve.util.supervisor.simulator_queue import SimulatorQueue +from pyrevolve.util.supervisor.analyzer_queue import AnalyzerQueue +from pyrevolve.custom_logging.logger import logger +import sys + +async def run(): + """ + The main coroutine, which is started below. + """ + + # experiment params # + num_generations = 200 + population_size = 100 + offspring_size = 100 + front = None + + # environment world and z-start + environments = {'tilted5': 0.1} + + genotype_conf = PlasticodingConfig( + max_structural_modules=15, + plastic=False, + ) + + mutation_conf = MutationConfig( + mutation_prob=0.8, + genotype_conf=genotype_conf, + ) + + crossover_conf = CrossoverConfig( + crossover_prob=0.8, + ) + # experiment params # + + # Parse command line / file input arguments + settings = parser.parse_args() + experiment_management = ExperimentManagement(settings, environments) + do_recovery = settings.recovery_enabled and not experiment_management.experiment_is_new() + + logger.info('Activated run '+settings.run+' of experiment '+settings.experiment_name) + + if do_recovery: + gen_num, has_offspring, next_robot_id = experiment_management.read_recovery_state(population_size, + offspring_size) + + if gen_num == num_generations-1: + logger.info('Experiment is already complete.') + return + else: + gen_num = 0 + next_robot_id = 1 + + def fitness_function_tilted(robot_manager, robot): + return fitness.displacement_velocity_hill(robot_manager, robot, False) + + fitness_function = {'tilted5': fitness_function_tilted} + + population_conf = PopulationConfig( + population_size=population_size, + genotype_constructor=random_initialization, + genotype_conf=genotype_conf, + fitness_function=fitness_function, + mutation_operator=standard_mutation, + mutation_conf=mutation_conf, + crossover_operator=standard_crossover, + crossover_conf=crossover_conf, + selection=lambda individuals: tournament_selection(individuals, environments, 2), + parent_selection=lambda individuals: multiple_selection(individuals, 2, tournament_selection, environments), + population_management=steady_state_population_management, + population_management_selector=tournament_selection, + evaluation_time=settings.evaluation_time, + offspring_size=offspring_size, + experiment_name=settings.experiment_name, + experiment_management=experiment_management, + environments=environments, + front=front + ) + + settings = parser.parse_args() + + simulator_queue = {} + analyzer_queue = None + + previous_port = None + for environment in environments: + + settings.world = environment + settings.z_start = environments[environment] + + if previous_port is None: + port = settings.port_start + previous_port = port + else: + port = previous_port+settings.n_cores + previous_port = port + + simulator_queue[environment] = SimulatorQueue(settings.n_cores, settings, port) + await simulator_queue[environment].start() + + analyzer_queue = AnalyzerQueue(1, settings, port+settings.n_cores) + await analyzer_queue.start() + + population = Population(population_conf, simulator_queue, analyzer_queue, next_robot_id) + + if do_recovery: + + if gen_num >= 0: + # loading a previous state of the experiment + await population.load_snapshot(gen_num) + logger.info('Recovered snapshot '+str(gen_num)+', pop with ' + str(len(population.individuals))+' individuals') + + if has_offspring: + individuals = await population.load_offspring(gen_num, population_size, offspring_size, next_robot_id) + gen_num += 1 + logger.info('Recovered unfinished offspring '+str(gen_num)) + + if gen_num == 0: + await population.init_pop(individuals) + else: + population = await population.next_gen(gen_num, individuals) + + experiment_management.export_snapshots(population.individuals, gen_num) + else: + # starting a new experiment + experiment_management.create_exp_folders() + await population.init_pop() + experiment_management.export_snapshots(population.individuals, gen_num) + + while gen_num < num_generations-1: + gen_num += 1 + population = await population.next_gen(gen_num) + experiment_management.export_snapshots(population.individuals, gen_num) + + # output result after completing all generations... From ae99a0985765997e5e5b557bc677f4cc1bc84c99 Mon Sep 17 00:00:00 2001 From: karinemiras Date: Mon, 17 Feb 2020 20:55:48 +0100 Subject: [PATCH 39/45] reproducible code --- ...bots_summary_renders_journal2_tilted_big.r | 2 +- .../summary_measures_journal2_tilted_big_2.R | 23 +++++++++------- .../summary_measures_journal2_tilted_big_3.R | 27 +++++++++++-------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r b/experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r index 1faba877a2..eff7bed226 100644 --- a/experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r +++ b/experiments/plasticoding_frontiers2020/bestrobots_summary_renders_journal2_tilted_big.r @@ -19,7 +19,7 @@ gens = 200 pop = 100 num_top = 1 -analysis = 'images' +analysis = 'nonstatic/images' ##### change paths/labels/params here ##### diff --git a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R index 834dcbb729..81216b481e 100644 --- a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R +++ b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_2.R @@ -8,7 +8,7 @@ base_directory <-paste('journal2', sep='') -analysis = 'analysis_journal2_tilted_big_2' +analysis = 'nonstatic/analysis_journal2_tilted_big_2' output_directory = paste(base_directory,'/',analysis ,sep='') @@ -492,10 +492,13 @@ experiments_labels2 = c( 'Baseline: Flat' , 'Plastic: Flat') if (measures_names[i] == 'displacement_velocity_hill' ) { max_y = 2.5 min_y = -0.5} - if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' || measures_names[i] == 'joints') { max_y = 1} - if (measures_names[i] == 'proportion' ) { max_y = 1} + if (measures_names[i] == 'head_balance' ) { + max_y = 1 + min_y = 0.6} if (measures_names[i] == 'absolute_size' ) { max_y = 16} - + if (measures_names[i] == 'recurrence' ) { max_y = 0.3} + if (measures_names[i] == 'sensors' ) { max_y = 0.3 } + if (measures_names[i] == 'sensors_reach' ) { max_y = 1 } graph = graph + labs( y=measures_labels[i], x="Generation", title="Flat Season") if (max_y>0) { @@ -534,21 +537,21 @@ experiments_labels2 = c( 'Baseline: Flat' , 'Plastic: Flat') geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4) + labs( x="Environment", y=measures_labels[i], title="Flat Season") - max_y = 0 min_y = 0 if (measures_names[i] == 'displacement_velocity_hill' ) { - g1 = g1 + geom_hline(yintercept=1.32, linetype="dashed", color = "red") + g1 = g1 + geom_hline(yintercept=3.63, linetype="dashed", color = "red", size=2) max_y = 4.8 min_y = -0.5} - if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' - || measures_names[i] == 'joints' || measures_names[i] == 'sensors_reach') { max_y = 1.15} + if (measures_names[i] == 'head_balance'){ + max_y = 1.15 + min_y = 0.55 + } + if (measures_names[i] == 'sensors_reach') { max_y = 1.15} if (measures_names[i] == 'recurrence' ) { max_y = 0.8} if (measures_names[i] == 'sensors' ) { max_y = 0.6} - if (measures_names[i] == 'proportion' ) { max_y = 1} if (measures_names[i] == 'absolute_size' ) { max_y = 16} - g1 = g1 + scale_color_manual(values= experiments_type_colors ) g1 = g1 + theme(legend.position="none" , text = element_text(size=45) , diff --git a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R index 95ac49c970..aef75a5867 100644 --- a/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R +++ b/experiments/plasticoding_frontiers2020/summary_measures_journal2_tilted_big_3.R @@ -8,7 +8,7 @@ base_directory <-paste('journal2', sep='') -analysis = 'analysis_journal2_tilted_big_3' +analysis = 'nonstatic/analysis_journal2_tilted_big_3' output_directory = paste(base_directory,'/',analysis ,sep='') @@ -489,13 +489,16 @@ experiments_labels2 = c( 'Baseline: Tilted' , 'Plastic: Tilted') max_y = 0 min_y = 0 - if (measures_names[i] == 'displacement_velocity_hill' ) { - max_y = 2.5 + if (measures_names[i] == 'displacement_velocity_hill' ) { + max_y = 2.5 min_y = -0.5} - if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' || measures_names[i] == 'joints') { max_y = 1} - if (measures_names[i] == 'head_balance') { min_y = 0.6 } - if (measures_names[i] == 'proportion' ) { max_y = 1} + if (measures_names[i] == 'head_balance' ) { + max_y = 1 + min_y = 0.6} if (measures_names[i] == 'absolute_size' ) { max_y = 16} + if (measures_names[i] == 'recurrence' ) { max_y = 0.3} + if (measures_names[i] == 'sensors' ) { max_y = 0.3 } + if (measures_names[i] == 'sensors_reach' ) { max_y = 1 } graph = graph + labs( y=measures_labels[i], x="Generation", title="Tilted Season") @@ -534,18 +537,20 @@ experiments_labels2 = c( 'Baseline: Tilted' , 'Plastic: Tilted') g1 <- ggplot(data=all_final_values, aes(x= type , y=values, color=type )) + geom_boxplot(position = position_dodge(width=0.9),lwd=2, outlier.size = 4) + labs( x="Environment", y=measures_labels[i], title="Tilted Season") - + max_y = 0 min_y = 0 if (measures_names[i] == 'displacement_velocity_hill' ) { - g1 = g1 + geom_hline(yintercept=1.32, linetype="dashed", color = "red") + g1 = g1 + geom_hline(yintercept=1.32, linetype="dashed", color = "red", size=2) max_y = 4.8 min_y = -0.5} - if (measures_names[i] == 'head_balance' || measures_names[i] == 'limbs' - || measures_names[i] == 'joints' || measures_names[i] == 'sensors_reach') { max_y = 1.15} + if (measures_names[i] == 'head_balance'){ + max_y = 1.15 + min_y = 0.55 + } + if (measures_names[i] == 'sensors_reach') { max_y = 1.15} if (measures_names[i] == 'recurrence' ) { max_y = 0.8} if (measures_names[i] == 'sensors' ) { max_y = 0.6} - if (measures_names[i] == 'proportion' ) { max_y = 1} if (measures_names[i] == 'absolute_size' ) { max_y = 16} From 5320db03c0eded39574590aab2e37647b1a3e8d7 Mon Sep 17 00:00:00 2001 From: Daan Zeeuwe Date: Wed, 13 May 2020 15:01:08 -0700 Subject: [PATCH 40/45] Removed cost from fitness functions --- .../baseline2.py | 2 +- .../flat.py | 2 +- .../tilted.py | 2 +- experiments/karines_experiments/baseline2.py | 2 +- experiments/karines_experiments/baseline2_lava.py | 4 ++-- experiments/karines_experiments/flat.py | 2 +- experiments/karines_experiments/lava.py | 2 +- experiments/karines_experiments/plastic2.py | 2 +- experiments/karines_experiments/plastic2_lava.py | 4 ++-- experiments/karines_experiments/tilted.py | 2 +- experiments/karines_experiments/watch_best.py | 2 +- .../plasticoding_frontiers2020/baseline_big.py | 2 +- experiments/plasticoding_frontiers2020/flat_big.py | 2 +- .../plasticoding_frontiers2020/plastic_big.py | 2 +- .../plasticoding_frontiers2020/tilted_big.py | 2 +- pyrevolve/evolution/fitness.py | 14 ++++---------- 16 files changed, 21 insertions(+), 27 deletions(-) diff --git a/experiments/Environmental_influences_on_evolvable_robots/baseline2.py b/experiments/Environmental_influences_on_evolvable_robots/baseline2.py index 8be050dec6..ab45e23c31 100755 --- a/experiments/Environmental_influences_on_evolvable_robots/baseline2.py +++ b/experiments/Environmental_influences_on_evolvable_robots/baseline2.py @@ -71,7 +71,7 @@ async def run(): def fitness_function_plane(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'plane': fitness_function_plane, diff --git a/experiments/Environmental_influences_on_evolvable_robots/flat.py b/experiments/Environmental_influences_on_evolvable_robots/flat.py index e96146b204..b9fcb277b8 100755 --- a/experiments/Environmental_influences_on_evolvable_robots/flat.py +++ b/experiments/Environmental_influences_on_evolvable_robots/flat.py @@ -69,7 +69,7 @@ async def run(): def fitness_function_plane(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'plane': fitness_function_plane} diff --git a/experiments/Environmental_influences_on_evolvable_robots/tilted.py b/experiments/Environmental_influences_on_evolvable_robots/tilted.py index 46baeee4cf..2f8700f0c2 100755 --- a/experiments/Environmental_influences_on_evolvable_robots/tilted.py +++ b/experiments/Environmental_influences_on_evolvable_robots/tilted.py @@ -69,7 +69,7 @@ async def run(): def fitness_function_tilted(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'tilted5': fitness_function_tilted} diff --git a/experiments/karines_experiments/baseline2.py b/experiments/karines_experiments/baseline2.py index 8be050dec6..ab45e23c31 100755 --- a/experiments/karines_experiments/baseline2.py +++ b/experiments/karines_experiments/baseline2.py @@ -71,7 +71,7 @@ async def run(): def fitness_function_plane(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'plane': fitness_function_plane, diff --git a/experiments/karines_experiments/baseline2_lava.py b/experiments/karines_experiments/baseline2_lava.py index 9c684a33a7..24b4c02736 100755 --- a/experiments/karines_experiments/baseline2_lava.py +++ b/experiments/karines_experiments/baseline2_lava.py @@ -71,12 +71,12 @@ async def run(): def fitness_function_plane(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) def fitness_function_lava(robot_manager, robot): contacts = measures.contacts(robot_manager, robot) assert(contacts != 0) - return fitness.floor_is_lava(robot_manager, robot, False) + return fitness.floor_is_lava(robot_manager, robot) fitness_function = {'plane': fitness_function_plane, 'lava': fitness_function_lava} diff --git a/experiments/karines_experiments/flat.py b/experiments/karines_experiments/flat.py index e96146b204..b9fcb277b8 100755 --- a/experiments/karines_experiments/flat.py +++ b/experiments/karines_experiments/flat.py @@ -69,7 +69,7 @@ async def run(): def fitness_function_plane(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'plane': fitness_function_plane} diff --git a/experiments/karines_experiments/lava.py b/experiments/karines_experiments/lava.py index cff2367289..cacd1eb200 100755 --- a/experiments/karines_experiments/lava.py +++ b/experiments/karines_experiments/lava.py @@ -69,7 +69,7 @@ async def run(): def fitness_function_lava(robot_manager, robot): contacts = measures.contacts(robot_manager, robot) assert(contacts != 0) - return fitness.floor_is_lava(robot_manager, robot, False) + return fitness.floor_is_lava(robot_manager, robot) fitness_function = {'lava': fitness_function_lava} diff --git a/experiments/karines_experiments/plastic2.py b/experiments/karines_experiments/plastic2.py index 0e4385be1a..754fd4c9e5 100755 --- a/experiments/karines_experiments/plastic2.py +++ b/experiments/karines_experiments/plastic2.py @@ -72,7 +72,7 @@ async def run(): def fitness_function_plane(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'plane': fitness_function_plane, 'tilted5': fitness_function_plane} diff --git a/experiments/karines_experiments/plastic2_lava.py b/experiments/karines_experiments/plastic2_lava.py index 413cbf8393..df0652c531 100755 --- a/experiments/karines_experiments/plastic2_lava.py +++ b/experiments/karines_experiments/plastic2_lava.py @@ -71,12 +71,12 @@ async def run(): def fitness_function_plane(robot_manager, robot): contacts = measures.contacts(robot_manager, robot) assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) def fitness_function_lava(robot_manager, robot): contacts = measures.contacts(robot_manager, robot) assert(contacts != 0) - return fitness.floor_is_lava(robot_manager, robot, False) + return fitness.floor_is_lava(robot_manager, robot) fitness_functions = {'plane': fitness_function_plane, 'lava': fitness_function_lava} diff --git a/experiments/karines_experiments/tilted.py b/experiments/karines_experiments/tilted.py index 46baeee4cf..2f8700f0c2 100755 --- a/experiments/karines_experiments/tilted.py +++ b/experiments/karines_experiments/tilted.py @@ -69,7 +69,7 @@ async def run(): def fitness_function_tilted(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'tilted5': fitness_function_tilted} diff --git a/experiments/karines_experiments/watch_best.py b/experiments/karines_experiments/watch_best.py index 4681cc7c04..e0b2997bee 100755 --- a/experiments/karines_experiments/watch_best.py +++ b/experiments/karines_experiments/watch_best.py @@ -63,7 +63,7 @@ async def run(): def fitness_function(robot_manager, robot): #contacts = measures.contacts(robot_manager, robot) #assert(contacts != 0) - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) population_conf = PopulationConfig( population_size=population_size, diff --git a/experiments/plasticoding_frontiers2020/baseline_big.py b/experiments/plasticoding_frontiers2020/baseline_big.py index bb527298eb..c40c150d36 100644 --- a/experiments/plasticoding_frontiers2020/baseline_big.py +++ b/experiments/plasticoding_frontiers2020/baseline_big.py @@ -70,7 +70,7 @@ async def run(): next_robot_id = 1 def fitness_function_plane(robot_manager, robot): - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'plane': fitness_function_plane, 'tilted5': fitness_function_plane} diff --git a/experiments/plasticoding_frontiers2020/flat_big.py b/experiments/plasticoding_frontiers2020/flat_big.py index 9449d9ff61..35369c12e5 100644 --- a/experiments/plasticoding_frontiers2020/flat_big.py +++ b/experiments/plasticoding_frontiers2020/flat_big.py @@ -67,7 +67,7 @@ async def run(): next_robot_id = 1 def fitness_function_plane(robot_manager, robot): - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'plane': fitness_function_plane} diff --git a/experiments/plasticoding_frontiers2020/plastic_big.py b/experiments/plasticoding_frontiers2020/plastic_big.py index 50f9d841f4..927a9e1cb5 100644 --- a/experiments/plasticoding_frontiers2020/plastic_big.py +++ b/experiments/plasticoding_frontiers2020/plastic_big.py @@ -70,7 +70,7 @@ async def run(): next_robot_id = 1 def fitness_function_plane(robot_manager, robot): - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'plane': fitness_function_plane, 'tilted5': fitness_function_plane} diff --git a/experiments/plasticoding_frontiers2020/tilted_big.py b/experiments/plasticoding_frontiers2020/tilted_big.py index 057a57522e..fcc769c2ce 100644 --- a/experiments/plasticoding_frontiers2020/tilted_big.py +++ b/experiments/plasticoding_frontiers2020/tilted_big.py @@ -67,7 +67,7 @@ async def run(): next_robot_id = 1 def fitness_function_tilted(robot_manager, robot): - return fitness.displacement_velocity_hill(robot_manager, robot, False) + return fitness.displacement_velocity_hill(robot_manager, robot) fitness_function = {'tilted5': fitness_function_tilted} diff --git a/pyrevolve/evolution/fitness.py b/pyrevolve/evolution/fitness.py index 3cdb74f39d..f939acb2db 100644 --- a/pyrevolve/evolution/fitness.py +++ b/pyrevolve/evolution/fitness.py @@ -62,7 +62,8 @@ def size_penalty(robot_manager, robot): return _size_penalty -def displacement_velocity_hill(robot_manager, robot, cost=False): + +def displacement_velocity_hill(robot_manager, robot): fitness = measures.displacement_velocity_hill(robot_manager) if fitness == 0 or robot.phenotype._morphological_measurements.measurements_to_dict()['hinge_count'] == 0: @@ -71,18 +72,11 @@ def displacement_velocity_hill(robot_manager, robot, cost=False): elif fitness < 0: fitness /= 10 - if cost and fitness != None: - _size_penalty = size_penalty(robot_manager, robot) ** 2 - if fitness >= 0: - fitness = fitness * _size_penalty - else: - fitness = fitness / _size_penalty - return fitness -def floor_is_lava(robot_manager, robot, cost=False): - _displacement_velocity_hill = displacement_velocity_hill(robot_manager, robot, cost) +def floor_is_lava(robot_manager, robot): + _displacement_velocity_hill = displacement_velocity_hill(robot_manager, robot) _contacts = measures.contacts(robot_manager, robot) _contacts = max(_contacts, 0.0001) From f02e1fb6b243df7eb6a7401f09ba77e110f20b18 Mon Sep 17 00:00:00 2001 From: Daan Zeeuwe Date: Wed, 13 May 2020 15:16:09 -0700 Subject: [PATCH 41/45] Removed unused reference to environment in plasticoding. --- pyrevolve/evolution/individual.py | 4 ++-- pyrevolve/evolution/population.py | 4 ++-- .../genotype/plasticoding/plasticoding.py | 22 +++---------------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/pyrevolve/evolution/individual.py b/pyrevolve/evolution/individual.py index df5900cbe7..a04d6d4c9b 100644 --- a/pyrevolve/evolution/individual.py +++ b/pyrevolve/evolution/individual.py @@ -17,13 +17,13 @@ def __init__(self, genotype, phenotype=None): self.parents = None self.failed_eval_attempt_count = 0 - def develop(self, environment): + def develop(self): """ Develops genotype into a intermediate phenotype """ if self.phenotype is None: - self.phenotype = self.genotype.develop(environment) + self.phenotype = self.genotype.develop() @property def id(self): diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index b4668d10fe..7fea232fad 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -100,7 +100,7 @@ def _new_individual(self, genotype): for environment in self.conf.environments: individual[environment] = copy.deepcopy(individual_temp) - individual[environment].develop(environment) + individual[environment].develop() if len(individual) == 1: self.conf.experiment_management.export_genotype(individual[environment]) @@ -109,7 +109,7 @@ def _new_individual(self, genotype): self.conf.experiment_management.export_phenotype(individual[environment], environment) self.conf.experiment_management.export_phenotype_images(os.path.join('data_fullevolution', - environment,'phenotype_images'), + environment, 'phenotype_images'), individual[environment]) individual[environment].phenotype.measure_phenotype(self.conf.experiment_name) individual[environment].phenotype.export_phenotype_measurements(self.conf.experiment_name, environment) diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index 03bae748b3..49d6761565 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -171,31 +171,15 @@ def check_validity(self): if self.phenotype._morphological_measurements.measurement_to_dict()['hinge_count'] > 0: self.valid = True - def develop(self, environment): - self.early_development(environment) + def develop(self): + self.early_development() phenotype = self.late_development() return phenotype - def early_development(self, environment): + def early_development(self): if self.conf.plastic: - # simulates sensing of environmental conditions - # ( it is a shortcut to save computational time, - # but imu sensors could for sure tell if it is hill or not) - if environment == 'plane': - hill = False - hot = False - if environment == 'tilted5': - hill = True - hot = False - if environment == 'lava': - hill = False - hot = True - if environment == 'lavatilted5': - hill = True - hot = True - grammar = {} for letter in self.grammar: From 5f8571f02f51105eb5da2b920962561aa1a81fad Mon Sep 17 00:00:00 2001 From: Daan Zeeuwe Date: Wed, 13 May 2020 15:28:45 -0700 Subject: [PATCH 42/45] Revert Changes to world and put them in a separate folder --- worlds/plane.realtime.world | 4 +- worlds/planobstacles.realtime.world | 7632 +++++++++++++++++ worlds/planobstacles.world | 7632 +++++++++++++++++ worlds/plasticoding/plane.realtime.world | 43 + .../planeobstacles.realtime.world | 0 .../{ => plasticoding}/planeobstacles.world | 0 .../planeobstacles2.realtime.world | 0 .../{ => plasticoding}/planeobstacles2.world | 0 worlds/plasticoding/tilted10.realtime.world | 41 + worlds/plasticoding/tilted10.world | 40 + worlds/plasticoding/tilted15.realtime.world | 40 + worlds/plasticoding/tilted15.world | 40 + worlds/plasticoding/tilted5.realtime.world | 40 + worlds/plasticoding/tilted5.world | 40 + worlds/tilted10.realtime.world | 4 +- worlds/tilted10.world | 4 +- worlds/tilted15.realtime.world | 6 +- worlds/tilted15.world | 4 +- worlds/tilted5.realtime.world | 4 +- worlds/tilted5.world | 2 +- 20 files changed, 15562 insertions(+), 14 deletions(-) create mode 100644 worlds/planobstacles.realtime.world create mode 100644 worlds/planobstacles.world create mode 100644 worlds/plasticoding/plane.realtime.world rename worlds/{ => plasticoding}/planeobstacles.realtime.world (100%) rename worlds/{ => plasticoding}/planeobstacles.world (100%) rename worlds/{ => plasticoding}/planeobstacles2.realtime.world (100%) rename worlds/{ => plasticoding}/planeobstacles2.world (100%) create mode 100644 worlds/plasticoding/tilted10.realtime.world create mode 100644 worlds/plasticoding/tilted10.world create mode 100644 worlds/plasticoding/tilted15.realtime.world create mode 100644 worlds/plasticoding/tilted15.world create mode 100644 worlds/plasticoding/tilted5.realtime.world create mode 100644 worlds/plasticoding/tilted5.world diff --git a/worlds/plane.realtime.world b/worlds/plane.realtime.world index 4a710a7b58..5864bebad4 100644 --- a/worlds/plane.realtime.world +++ b/worlds/plane.realtime.world @@ -7,10 +7,10 @@ - 0.005 + 0.001 - 1000 + 800 diff --git a/worlds/planobstacles.realtime.world b/worlds/planobstacles.realtime.world new file mode 100644 index 0000000000..b109b8ae6a --- /dev/null +++ b/worlds/planobstacles.realtime.world @@ -0,0 +1,7632 @@ + + + + + 0 + 0 + + + 0.003 + + + 1000 + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + -1 -1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 -0.87 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 -0.74 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 -0.61 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 -0.48 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 -0.22 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 -0.0899999999999999 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 0.0400000000000001 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 0.17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 0.43 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 0.56 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 0.69 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 0.82 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 0.95 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.82 -0.93 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 -0.8 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 -0.67 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 -0.54 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 -0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 -0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 -0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 0.63 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 0.76 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 0.89 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.57 -1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 -0.87 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 -0.74 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 -0.61 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 -0.48 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 -0.22 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 -0.0899999999999999 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 0.0400000000000001 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 0.17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 0.43 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 0.56 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 0.69 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 0.82 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 0.95 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.32 -0.93 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 -0.8 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 -0.67 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 -0.54 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 -0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 -0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 -0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 0.63 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 0.76 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 0.89 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.14 -1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 -0.87 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 -0.74 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 -0.61 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 -0.48 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 -0.22 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 -0.0899999999999999 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 0.0400000000000001 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 0.17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 0.43 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 0.56 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 0.69 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 0.82 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 0.95 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 -0.93 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 -0.8 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 -0.67 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 -0.54 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 -0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 -0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 -0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 0.63 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 0.76 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 0.89 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.29 -1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 -0.87 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 -0.74 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 -0.61 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 -0.48 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 -0.22 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 -0.0899999999999999 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 0.0400000000000001 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 0.17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 0.43 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 0.56 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 0.69 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 0.82 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 0.95 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.54 -0.93 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 -0.8 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 -0.67 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 -0.54 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 -0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 -0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 -0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 0.63 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 0.76 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 0.89 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.72 -1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 -0.87 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 -0.74 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 -0.61 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 -0.48 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 -0.22 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 -0.0899999999999999 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 0.0400000000000001 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 0.17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 0.43 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 0.56 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 0.69 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 0.82 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 0.95 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.9 -0.93 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 -0.8 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 -0.67 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 -0.54 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 -0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 -0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 -0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 0.63 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 0.76 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 0.89 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + + model://sun + + + model://tol_ground + + + + diff --git a/worlds/planobstacles.world b/worlds/planobstacles.world new file mode 100644 index 0000000000..096fb13436 --- /dev/null +++ b/worlds/planobstacles.world @@ -0,0 +1,7632 @@ + + + + + 0 + 0 + + + 0.003 + + + 0.0 + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + -1 -1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 -0.87 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 -0.74 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 -0.61 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 -0.48 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 -0.22 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 -0.0899999999999999 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 0.0400000000000001 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 0.17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 0.43 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 0.56 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 0.69 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -1 0.82 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.93 0.95 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.82 -0.93 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 -0.8 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 -0.67 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 -0.54 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 -0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 -0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 -0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 0.63 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.75 0.76 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.82 0.89 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.57 -1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 -0.87 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 -0.74 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 -0.61 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 -0.48 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 -0.22 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 -0.0899999999999999 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 0.0400000000000001 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 0.17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 0.43 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 0.56 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 0.69 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.5 0.82 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.57 0.95 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.32 -0.93 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 -0.8 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 -0.67 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 -0.54 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 -0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 -0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 -0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 0.63 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.32 0.76 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.25 0.89 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + -0.14 -1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 -0.87 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 -0.74 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 -0.61 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 -0.48 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 -0.22 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 -0.0899999999999999 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 0.0400000000000001 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 0.17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 0.43 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 0.56 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 0.69 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.14 0.82 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + -0.0699999999999999 0.95 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 -0.93 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 -0.8 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 -0.67 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 -0.54 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 -0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 -0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 -0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 0.63 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.11 0.76 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.0400000000000001 0.89 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.29 -1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 -0.87 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 -0.74 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 -0.61 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 -0.48 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 -0.22 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 -0.0899999999999999 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 0.0400000000000001 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 0.17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 0.43 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 0.56 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 0.69 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.36 0.82 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.29 0.95 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.54 -0.93 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 -0.8 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 -0.67 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 -0.54 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 -0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 -0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 -0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 0.63 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.54 0.76 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.61 0.89 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.72 -1 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 -0.87 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 -0.74 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 -0.61 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 -0.48 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 -0.35 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 -0.22 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 -0.0899999999999999 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 0.0400000000000001 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 0.17 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 0.3 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 0.43 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 0.56 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 0.69 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.72 0.82 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.79 0.95 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.01 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.01 + + + + + + + 0 + 0 + 1 + + + + 0.9 -0.93 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 -0.8 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 -0.67 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 -0.54 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 -0.41 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 -0.28 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 -0.15 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 -0.02 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 0.11 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 0.24 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 0.37 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 0.5 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 0.63 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.97 0.76 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + 0.9 0.89 0 0 0 0 + + + 1 + + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0.03 0.03 0.02 + + + 10 + + + + + + + + + + + + + + 0.03 0.03 0.02 + + + + + + + 0 + 0 + 1 + + + + + model://sun + + + model://tol_ground + + + + \ No newline at end of file diff --git a/worlds/plasticoding/plane.realtime.world b/worlds/plasticoding/plane.realtime.world new file mode 100644 index 0000000000..4a710a7b58 --- /dev/null +++ b/worlds/plasticoding/plane.realtime.world @@ -0,0 +1,43 @@ + + + + + 0 + 0 + + + + 0.005 + + + 1000 + + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + world + + + + + + + + + model://sun + + + model://tol_ground + + + + + diff --git a/worlds/planeobstacles.realtime.world b/worlds/plasticoding/planeobstacles.realtime.world similarity index 100% rename from worlds/planeobstacles.realtime.world rename to worlds/plasticoding/planeobstacles.realtime.world diff --git a/worlds/planeobstacles.world b/worlds/plasticoding/planeobstacles.world similarity index 100% rename from worlds/planeobstacles.world rename to worlds/plasticoding/planeobstacles.world diff --git a/worlds/planeobstacles2.realtime.world b/worlds/plasticoding/planeobstacles2.realtime.world similarity index 100% rename from worlds/planeobstacles2.realtime.world rename to worlds/plasticoding/planeobstacles2.realtime.world diff --git a/worlds/planeobstacles2.world b/worlds/plasticoding/planeobstacles2.world similarity index 100% rename from worlds/planeobstacles2.world rename to worlds/plasticoding/planeobstacles2.world diff --git a/worlds/plasticoding/tilted10.realtime.world b/worlds/plasticoding/tilted10.realtime.world new file mode 100644 index 0000000000..75ae943e00 --- /dev/null +++ b/worlds/plasticoding/tilted10.realtime.world @@ -0,0 +1,41 @@ + + + + + 0 + 0 + + + 0.005 + + + 1000 + + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + + + + model://sun + + + model://tilted10 + + + + + diff --git a/worlds/plasticoding/tilted10.world b/worlds/plasticoding/tilted10.world new file mode 100644 index 0000000000..29ee9f85bd --- /dev/null +++ b/worlds/plasticoding/tilted10.world @@ -0,0 +1,40 @@ + + + + + 0 + 0 + + + 0.005 + + + 0 + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + + + + model://sun + + + model://tilted10 + + + + + diff --git a/worlds/plasticoding/tilted15.realtime.world b/worlds/plasticoding/tilted15.realtime.world new file mode 100644 index 0000000000..02a4f994bb --- /dev/null +++ b/worlds/plasticoding/tilted15.realtime.world @@ -0,0 +1,40 @@ + + + + + 0 + 0 + + + 0.001 + + + 5000 + + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + + + + model://sun + + + model://tilted15 + + + + diff --git a/worlds/plasticoding/tilted15.world b/worlds/plasticoding/tilted15.world new file mode 100644 index 0000000000..5f596916f8 --- /dev/null +++ b/worlds/plasticoding/tilted15.world @@ -0,0 +1,40 @@ + + + + + 0 + 0 + + + 0.005 + + + 0 + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + + + + model://sun + + + model://tilted15 + + + + + diff --git a/worlds/plasticoding/tilted5.realtime.world b/worlds/plasticoding/tilted5.realtime.world new file mode 100644 index 0000000000..95d13320a5 --- /dev/null +++ b/worlds/plasticoding/tilted5.realtime.world @@ -0,0 +1,40 @@ + + + + + 0 + 0 + + + 0.005 + + + 1000 + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + + + + model://sun + + + model://tilted5 + + + + + diff --git a/worlds/plasticoding/tilted5.world b/worlds/plasticoding/tilted5.world new file mode 100644 index 0000000000..6810efd7d2 --- /dev/null +++ b/worlds/plasticoding/tilted5.world @@ -0,0 +1,40 @@ + + + + + 0 + 0 + + + 0.003 + + + 0 + + + + 0.1 + 10e-6 + + + 100 + 1e-8 + + + quick + + + + + + + + model://sun + + + model://tilted5 + + + + + diff --git a/worlds/tilted10.realtime.world b/worlds/tilted10.realtime.world index 75ae943e00..d863a30fad 100644 --- a/worlds/tilted10.realtime.world +++ b/worlds/tilted10.realtime.world @@ -6,7 +6,7 @@ 0 - 0.005 + 0.003 1000 @@ -36,6 +36,6 @@ model://tilted10 - + diff --git a/worlds/tilted10.world b/worlds/tilted10.world index 29ee9f85bd..be0e7b5695 100644 --- a/worlds/tilted10.world +++ b/worlds/tilted10.world @@ -6,7 +6,7 @@ 0 - 0.005 + 0.003 0 @@ -35,6 +35,6 @@ model://tilted10 - + diff --git a/worlds/tilted15.realtime.world b/worlds/tilted15.realtime.world index 02a4f994bb..2bbf7ba905 100644 --- a/worlds/tilted15.realtime.world +++ b/worlds/tilted15.realtime.world @@ -6,10 +6,10 @@ 0 - 0.001 + 0.003 - 5000 + 1000 @@ -35,6 +35,6 @@ model://tilted15 - + diff --git a/worlds/tilted15.world b/worlds/tilted15.world index 5f596916f8..caa8c554e2 100644 --- a/worlds/tilted15.world +++ b/worlds/tilted15.world @@ -6,7 +6,7 @@ 0 - 0.005 + 0.003 0 @@ -35,6 +35,6 @@ model://tilted15 - + diff --git a/worlds/tilted5.realtime.world b/worlds/tilted5.realtime.world index 95d13320a5..9324164ab7 100644 --- a/worlds/tilted5.realtime.world +++ b/worlds/tilted5.realtime.world @@ -6,7 +6,7 @@ 0 - 0.005 + 0.003 1000 @@ -35,6 +35,6 @@ model://tilted5 - + diff --git a/worlds/tilted5.world b/worlds/tilted5.world index 6810efd7d2..45fa5e9d45 100644 --- a/worlds/tilted5.world +++ b/worlds/tilted5.world @@ -35,6 +35,6 @@ model://tilted5 - + From dd47dcef2a1c4fa1cc212c3912270b54560ecda4 Mon Sep 17 00:00:00 2001 From: Daan Zeeuwe Date: Wed, 13 May 2020 15:36:51 -0700 Subject: [PATCH 43/45] Revert Changes to world and put them in a separate folder fixed small style issues --- worlds/planobstacles.realtime.world | 2 +- worlds/planobstacles.world | 2 +- worlds/tilted15.realtime.world | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/worlds/planobstacles.realtime.world b/worlds/planobstacles.realtime.world index b109b8ae6a..991747d10f 100644 --- a/worlds/planobstacles.realtime.world +++ b/worlds/planobstacles.realtime.world @@ -7627,6 +7627,6 @@ model://tol_ground - + diff --git a/worlds/planobstacles.world b/worlds/planobstacles.world index 096fb13436..ffa4a71a82 100644 --- a/worlds/planobstacles.world +++ b/worlds/planobstacles.world @@ -7629,4 +7629,4 @@ - \ No newline at end of file + diff --git a/worlds/tilted15.realtime.world b/worlds/tilted15.realtime.world index 2bbf7ba905..ee342f03b6 100644 --- a/worlds/tilted15.realtime.world +++ b/worlds/tilted15.realtime.world @@ -35,6 +35,7 @@ model://tilted15 + From 6402c6a046bb8d32860249b6eede1fc64f038f64 Mon Sep 17 00:00:00 2001 From: Daan Zeeuwe Date: Mon, 25 May 2020 00:58:33 -0700 Subject: [PATCH 44/45] revert changes --- pyrevolve/evolution/individual.py | 8 ++--- pyrevolve/evolution/population.py | 31 ++++++++----------- pyrevolve/evolution/selection.py | 8 ++--- .../genotype/plasticoding/plasticoding.py | 19 ++++++++++-- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/pyrevolve/evolution/individual.py b/pyrevolve/evolution/individual.py index a04d6d4c9b..89cc542d82 100644 --- a/pyrevolve/evolution/individual.py +++ b/pyrevolve/evolution/individual.py @@ -1,11 +1,12 @@ # (G,P) import pickle + class Individual: + def __init__(self, genotype, phenotype=None): """ Creates an Individual object with the given genotype and optionally the phenotype. - :param genotype: genotype of the individual :param phenotype (optional): phenotype of the individual """ @@ -17,13 +18,12 @@ def __init__(self, genotype, phenotype=None): self.parents = None self.failed_eval_attempt_count = 0 - def develop(self): + def develop(self, environment): """ Develops genotype into a intermediate phenotype - """ if self.phenotype is None: - self.phenotype = self.genotype.develop() + self.phenotype = self.genotype.develop(environment) @property def id(self): diff --git a/pyrevolve/evolution/population.py b/pyrevolve/evolution/population.py index 7fea232fad..8f869d919a 100644 --- a/pyrevolve/evolution/population.py +++ b/pyrevolve/evolution/population.py @@ -1,16 +1,12 @@ # [(G,P), (G,P), (G,P), (G,P), (G,P)] from pyrevolve.evolution.individual import Individual -from pyrevolve.SDF.math import Vector3 -from pyrevolve.tol.manage import measures from ..custom_logging.logger import logger -import time import asyncio import copy import os import pickle -import sys -from random import random + class PopulationConfig: def __init__(self, @@ -100,7 +96,7 @@ def _new_individual(self, genotype): for environment in self.conf.environments: individual[environment] = copy.deepcopy(individual_temp) - individual[environment].develop() + individual[environment].develop(environment) if len(individual) == 1: self.conf.experiment_management.export_genotype(individual[environment]) @@ -166,10 +162,11 @@ async def load_offspring(self, last_snapshot, population_size, offspring_size, n async def consolidate_fitness(self, individuals): + last_environment = list(self.conf.environments.keys())[-1] + if len(self.conf.environments) == 1: for individual in individuals: - fit = individual[list(self.conf.environments.keys())[-1]].fitness - individual[list(self.conf.environments.keys())[-1]].consolidated_fitness = fit + individual[last_environment].consolidated_fitness = individual[last_environment].fitness # if there are multiple seasons (environments) else: @@ -228,28 +225,27 @@ async def consolidate_fitness(self, individuals): masters += 1 if self.conf.front == 'slaves': - individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = slaves + individual_ref[last_environment].consolidated_fitness = slaves if self.conf.front == 'total_slaves': - individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = total_slaves + individual_ref[last_environment].consolidated_fitness = total_slaves if self.conf.front == 'total_masters': if total_masters == 0: - individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = 0 + individual_ref[last_environment].consolidated_fitness = 0 else: - individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = 1/total_masters + individual_ref[last_environment].consolidated_fitness = 1/total_masters if self.conf.front == 'masters': if masters == 0: - individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = 0 + individual_ref[last_environment].consolidated_fitness = 0 else: - individual_ref[list(self.conf.environments.keys())[-1]].consolidated_fitness = 1/masters + individual_ref[last_environment].consolidated_fitness = 1/masters for individual in individuals: - self.conf.experiment_management.export_consolidated_fitness(individual[list(self.conf.environments.keys())[-1]]) + self.conf.experiment_management.export_consolidated_fitness(individual[last_environment]) - self.conf.experiment_management.export_individual(individual[list(self.conf.environments.keys())[-1]], - list(self.conf.environments.keys())[-1]) + self.conf.experiment_management.export_individual(individual[last_environment], last_environment) async def init_pop(self, recovered_individuals=[]): """ @@ -383,7 +379,6 @@ async def evaluate(self, new_individuals, gen_num, environment, type_simulation # # return await self.simulator_queue[environment].test_robot(individual, self.conf) - async def evaluate_single_robot(self, individual, environment): """ :param individual: individual diff --git a/pyrevolve/evolution/selection.py b/pyrevolve/evolution/selection.py index 62b95d854e..631aad5fe0 100644 --- a/pyrevolve/evolution/selection.py +++ b/pyrevolve/evolution/selection.py @@ -4,9 +4,9 @@ def _compare_maj_fitness(indiv_1, indiv_2, environments): - - fit_1 = indiv_1[list(environments.keys())[-1]].consolidated_fitness - fit_2 = indiv_2[list(environments.keys())[-1]].consolidated_fitness + environment = list(environments.keys())[-1] + fit_1 = indiv_1[environment].consolidated_fitness + fit_2 = indiv_2[environment].consolidated_fitness fit_1 = _neg_inf if fit_1 is None else fit_1 fit_2 = _neg_inf if fit_2 is None else fit_2 @@ -43,4 +43,4 @@ def multiple_selection(population, selection_size, selection_function, environme if selected_individual not in selected_individuals: selected_individuals.append(selected_individual) new_individual = True - return selected_individuals \ No newline at end of file + return selected_individuals diff --git a/pyrevolve/genotype/plasticoding/plasticoding.py b/pyrevolve/genotype/plasticoding/plasticoding.py index 49d6761565..98ff6eeec2 100644 --- a/pyrevolve/genotype/plasticoding/plasticoding.py +++ b/pyrevolve/genotype/plasticoding/plasticoding.py @@ -171,17 +171,30 @@ def check_validity(self): if self.phenotype._morphological_measurements.measurement_to_dict()['hinge_count'] > 0: self.valid = True - def develop(self): - self.early_development() + def develop(self, environment): + self.early_development(environment) phenotype = self.late_development() return phenotype - def early_development(self): + def early_development(self, environment): if self.conf.plastic: grammar = {} for letter in self.grammar: + if environment == 'plane': + hill = False + hot = False + if environment == 'tilted5': + hill = True + hot = False + if environment == 'lava': + hill = False + hot = True + if environment == 'lavatilted5': + hill = True + hot = True + true_clauses = [] clause_is_true = None From 804b68b8847b6fae3df0915c700f45f007894e52 Mon Sep 17 00:00:00 2001 From: karinemiras Date: Thu, 12 Nov 2020 17:11:43 +0100 Subject: [PATCH 45/45] Update NeuralNetwork.cpp add connections of inpurs to oscillators --- cpprevolve/revolve/gazebo/brains/NeuralNetwork.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpprevolve/revolve/gazebo/brains/NeuralNetwork.cpp b/cpprevolve/revolve/gazebo/brains/NeuralNetwork.cpp index 94fd84f372..e809c06bf1 100644 --- a/cpprevolve/revolve/gazebo/brains/NeuralNetwork.cpp +++ b/cpprevolve/revolve/gazebo/brains/NeuralNetwork.cpp @@ -379,6 +379,9 @@ void NeuralNetwork::Step(const double _time) /* set output to be in [0.5 - gain/2, 0.5 + gain/2] */ nextState->at(i) = (0.5 - (gain / 2.0) + nextState->at(i) * gain); + + // add IN connections to oscillators + nextState->at(i) = nextState->at(i) + curNeuronActivation; } break; default: