Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review Multiobjective compatibility #91

Open
wants to merge 48 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3104ee9
plasticoding turtle changes
karinemiras Aug 6, 2019
04543ff
Merge remote-tracking branch 'origin/development' into multiobjective
karinemiras Aug 6, 2019
f26f044
small fixes
karinemiras Aug 7, 2019
25ed54e
eval time
karinemiras Aug 7, 2019
fcbecf6
small fixes
karinemiras Aug 9, 2019
32bf0e9
new fitness
karinemiras Aug 9, 2019
6897c47
small fixes
karinemiras Aug 9, 2019
37c9a7e
fix fitness
karinemiras Sep 13, 2019
c766609
small fitness change
karinemiras Sep 13, 2019
6228339
script best
karinemiras Sep 13, 2019
31b8a7d
fixes to script r
karinemiras Sep 16, 2019
34503b8
setting experiments and fix fitness hill
karinemiras Sep 18, 2019
ccff5cf
fix environments
karinemiras Sep 23, 2019
f265b46
new environment
karinemiras Sep 23, 2019
b29d17a
improves exportation of best robots pics
karinemiras Sep 30, 2019
b81954a
Merge pull request #76 from ci-group/examples_fix
portaloffreedom Oct 18, 2019
1e07fd1
Add Gitpod button to README.md
Nov 2, 2019
7bf8b3a
init plastic grammar + plastic early develop part 1
karinemiras Dec 5, 2019
b09de08
finished plasticity capacity in lsystem
karinemiras Dec 6, 2019
2bcbc5b
loads multiple environments
karinemiras Dec 6, 2019
0c995b7
adapts recovery (part 1)
karinemiras Dec 9, 2019
09d65e3
baseline manager
karinemiras Dec 11, 2019
5047e38
improvement in plasticity
karinemiras Dec 11, 2019
9eafb2d
recover of ini pop
karinemiras Dec 11, 2019
c370701
crossover and mutation for plasticity
karinemiras Dec 12, 2019
7fca738
tiny
karinemiras Dec 12, 2019
c363e0c
Merge remote-tracking branch 'origin/master' into multiobjective
karinemiras Dec 16, 2019
319f7d0
final adjusments for phenotypic plasticity in multiseason experiment
karinemiras Dec 17, 2019
c6949cc
fixed bug mutation
karinemiras Dec 17, 2019
ed685ea
adapts scripts od analysis
karinemiras Jan 10, 2020
05825c1
analysis
karinemiras Jan 10, 2020
3891141
fix bug recovery + new pareto fronts
karinemiras Jan 15, 2020
b13df9e
fix gub time + plots
karinemiras Jan 17, 2020
7830878
run exps
karinemiras Jan 22, 2020
3dbc182
fix exception pickle, and fix bug consolidation for non-seasonal
karinemiras Jan 23, 2020
70e7a00
untested lava changes + analysis scripts adaptation
karinemiras Jan 23, 2020
0cfff98
more scripts
karinemiras Jan 24, 2020
26e88fd
fix scripts and put lava back
karinemiras Jan 27, 2020
a0a6496
reproducible experiments
karinemiras Feb 4, 2020
764c485
plasticoding setup
karinemiras Feb 10, 2020
ffad29e
reproducible code
karinemiras Feb 12, 2020
ae99a09
reproducible code
karinemiras Feb 17, 2020
5320db0
Removed cost from fitness functions
DaanZ May 13, 2020
f02e1fb
Removed unused reference to environment in plasticoding.
DaanZ May 13, 2020
5f8571f
Revert Changes to world and put them in a separate folder
DaanZ May 13, 2020
dd47dce
Revert Changes to world and put them in a separate folder fixed small…
DaanZ May 13, 2020
6402c6a
revert changes
DaanZ May 25, 2020
804b68b
Update NeuralNetwork.cpp
karinemiras Nov 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Binary file not shown.
156 changes: 156 additions & 0 deletions experiments/Environmental_influences_on_evolvable_robots/baseline2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/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_plane(robot_manager, robot):
#contacts = measures.contacts(robot_manager, robot)
#assert(contacts != 0)
return fitness.displacement_velocity_hill(robot_manager, robot)


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...
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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()

Loading