def __init__(self,obj,robot=False): ''' Constructor. ''' Solution.__init__(self, len(obj)) #another list for objectives / #next to the one provided by the Superclass Solution? self.selected4 = obj self.grid_sz = -1 self.grid = 0 #4 personal history self.history = [] self.objs=[0.0]*len(obj_names) #here i save everything for analysis self.solver = False self.BEHAV_DIM = 0 self.behaviorSamples=np.zeros(1) self.IRARflag = False #true if IRAR has been evaluated self.parentRar = 0 self.newInArchive = True self.childrenInQ = 0 self.id = self._ids.next() self.parentIDs = [] if(not robot): self.robot=mazepy.mazenav() self.robot.init_rand() self.robot.mutate() else: self.robot=robot
def __init__(self, obj, robot=False): ''' Constructor. ''' Solution.__init__(self, len(obj)) #another list for objectives / #next to the one provided by the Superclass Solution? self.selected4 = obj self.grid_sz = -1 self.grid = 0 #4 personal history self.history = [] self.objs = [0.0] * len( obj_names) #here i save everything for analysis self.solver = False self.BEHAV_DIM = 0 self.behaviorSamples = np.zeros(1) self.IRARflag = False #true if IRAR has been evaluated self.parentRar = 0 self.newInArchive = True self.childrenInQ = 0 self.id = self._ids.next() self.parentIDs = [] if (not robot): self.robot = mazepy.mazenav() self.robot.init_rand() self.robot.mutate() else: self.robot = robot
def __init__(self, robot=False): ''' Constructor. ''' Solution.__init__(self, len(obj)) self.objs = [0.0] * 3 if (not robot): self.robot = mazepy.mazenav() self.robot.init_rand() self.robot.mutate() else: self.robot = robot
def __init__(self,robot=False): ''' Constructor. ''' Solution.__init__(self, len(obj)) self.objs=[0.0]*3 if(not robot): self.robot=mazepy.mazenav() self.robot.init_rand() self.robot.mutate() else: self.robot=robot
#function to calculate evolvability via PLoS paper metric #do many one-step mutants from initial individual, see how many #'unique' behaviors we get def calc_evolvability(robot, grid_sz, mutations): grids = set() for x in range(mutations): mutant = robot.copy() mutant.mutate() mutant.map() grids.add(map_into_grid(mutant, grid_sz)) return len(grids) if (__name__ == '__main__'): #initialize maze stuff with "medium maze" mazepy.mazenav.initmaze("hard_maze_list.txt") mazepy.mazenav.random_seed() #create initial genome robot = mazepy.mazenav() #initalize it randomly and mutate it once for good measure robot.init_rand() robot.mutate() #run genome in the maze simulator robot.map() #calculate evolvability print "evolvability:", calc_evolvability(robot, 30, 200)
import mazepy from entropy import * #simple fitness function -- how close do we get to the goal at the end of #a simulation? def fitness(robot): return mazepy.feature_detector.state_entropy(robot) #return -mazepy.feature_detector.end_goal(robot) #initialize maze stuff with "medium maze" mazepy.mazenav.initmaze("hard_maze_list.txt") mazepy.mazenav.random_seed() #create initial genome robot=mazepy.mazenav() #initalize it randomly and mutate it once for good measure robot.init_rand() robot.mutate() #run genome in the maze simulator robot.map() #current fitness set to how fit our first dude is cur_fitness=fitness(robot) iterations=0 #loop until we discover a solution to the maze #this is using simple hillclimbing algorithm (not neat) newrobot=robot while not newrobot.solution():
def optimize_evolvability(robot=None): evo_fnc = calc_evolvability_entropy #initialize maze stuff with "medium maze" population = defaultdict(list) whole_population = [] psize = 10 e_samp = 400 if (robot == None): for k in range(psize): robot = mazepy.mazenav() robot.init_rand() robot.mutate() robot.map() robot.fitness = evo_fnc(robot, e_samp) whole_population.append(robot) else: for k in range(psize): robot2 = robot.copy() robot2.map() robot2.fitness = evo_fnc(robot, e_samp) whole_population.append(robot2) solved = False evals = psize child = None while not solved: evals += 1 parent = random.choice(whole_population) parent.fitness = evo_fnc(parent, e_samp) child = parent.copy() child.mutate() child.map() child.fitness = evo_fnc(child, e_samp) if (child.solution()): #solved=True pass whole_population.append(child) whole_population.sort(key=lambda k: k.fitness, reverse=True) to_kill = whole_population[-1] #print to_kill.fitness whole_population.remove(to_kill) del to_kill if (evals % 1 == 0): print evals, calc_population_entropy( whole_population ), whole_population[0].fitness, whole_population[-1].fitness #run genome in the maze simulator #calculate evolvability print child.solution() print "evolvability:", evo_fnc(child, 1000) robot = mazepy.mazenav() robot.init_rand() robot.mutate() robot.map() print "evolvability:", evo_fnc(robot, 1000)
def optimize_evolvability(robot=None): evo_fnc = calc_evolvability_entropy #initialize maze stuff with "medium maze" population=defaultdict(list) whole_population=[] psize=10 e_samp=400 if(robot==None): for k in range(psize): robot=mazepy.mazenav() robot.init_rand() robot.mutate() robot.map() robot.fitness=evo_fnc(robot,e_samp) whole_population.append(robot) else: for k in range(psize): robot2=robot.copy() robot2.map() robot2.fitness=evo_fnc(robot,e_samp) whole_population.append(robot2) solved=False evals=psize child=None while not solved: evals+=1 parent=random.choice(whole_population) parent.fitness=evo_fnc(parent,e_samp) child=parent.copy() child.mutate() child.map() child.fitness=evo_fnc(child,e_samp) if(child.solution()): #solved=True pass whole_population.append(child) whole_population.sort(key=lambda k:k.fitness,reverse=True) to_kill=whole_population[-1] #print to_kill.fitness whole_population.remove(to_kill) del to_kill if(evals%1==0): print evals,calc_population_entropy(whole_population),whole_population[0].fitness,whole_population[-1].fitness #run genome in the maze simulator #calculate evolvability print child.solution() print "evolvability:", evo_fnc(child,1000) robot=mazepy.mazenav() robot.init_rand() robot.mutate() robot.map() print "evolvability:", evo_fnc(robot,1000)