from numpy.random import seed, rand, randn, randint from numpy import array, arange, asfarray, exp, pi, cos, zeros, where, linspace import matplotlib as mpl import matplotlib.pyplot as plt from peabox_individual import Individual from peabox_population import Population from peabox_testfuncs import CEC05_test_function_producer as tfp from peabox_helpers import parentselect_exp as pse from peabox_helpers import simple_searchspace #------------------------------------------------------------------------------- #--- part 1: Ingredients ------------------------------------------------------- #------------------------------------------------------------------------------- dim = 10 f11 = tfp(11, dim) # Weierstrass function in 10 dimensions searchspace = simple_searchspace(10, -3., 1.) ps = 40 # population size G = 80 # number of generations to go through parents = Population(Individual, ps, f11, searchspace) offspring = Population(Individual, ps, f11, searchspace) #------------------------------------------------------------------------------- #--- part 2: initialisation ---------------------------------------------------- #------------------------------------------------------------------------------- seed( 1 ) # seeding numpy's random number generator so we get reproducibly the same random numbers
self.traj=[] self.trajqual=[] def memorize(self): self.traj.append(self.get_copy_of_DNA()) self.trajqual.append(self.score) def do_step(self): PSO_Individ.do_step(self) self.memorize() def get_trajectory_components(self,dims): output=[] for d in dims: output.append([self.traj[i][d] for i in range(len(self.traj))]) return output dim=2 f1=tfp(1,dim) # Weierstrass function in 2 dimensions f11=tfp(11,dim) # Weierstrass function in 2 dimensions searchspace=simple_searchspace(dim,-3.,1.) p=Pswarm(Memorizing_PSO_Individ,12,f1,searchspace,[3,4],1) p.random_ini() #p.alpha=0.95 if True: dude=p[0] #dude.random_influence='1D' dude.add_attractor(ones(dim),1.) dude.speed[:]=1,0 for i in range(20): dude.do_step()
self.sa_beststeps=[] self.ga_beststeps=[] #------------------------------------------------------------------------------- #--- intermezzo: the colormap used in peabox_plotting.ancestryplot ------------- #------------------------------------------------------------------------------- show_these_colormaps([ancestcolors],'colormap_used_for_ancestry_coloring.png') #------------------------------------------------------------------------------- #--- part 1: Ingredients ------------------------------------------------------- #------------------------------------------------------------------------------- dim=10 f11=tfp(11,dim) # Weierstrass function in 10 dimensions searchspace=simple_searchspace(10,-3.,1.) ps=80 # population size G=120 # number of generations to go through parents=SAGA_Population(Individual,ps,f11,searchspace); parents.objname='CEC05 f11' offspring=SAGA_Population(Individual,ps,f11,searchspace); offspring.objname='CEC05 f11' parents.ncase=1 # let this be case 1, plots and pickles will contain the number offspring.ncase=1 rec=Recorder(parents) # creating this Recorder instance to collect survey data on parent population rec.snames.append('sa_improverate') # appending a scalar property's name to the survey list rec.snames.append('sa_toleraterate') rec.snames.append('ga_improverate')
self.traj.append(self.get_copy_of_DNA()) self.trajqual.append(self.score) def do_step(self): PSO_Individ.do_step(self) self.memorize() def get_trajectory_components(self, dims): output = [] for d in dims: output.append([self.traj[i][d] for i in range(len(self.traj))]) return output dim = 2 f1 = tfp(1, dim) # Weierstrass function in 2 dimensions f11 = tfp(11, dim) # Weierstrass function in 2 dimensions searchspace = simple_searchspace(dim, -3., 1.) p = Pswarm(Memorizing_PSO_Individ, 12, f1, searchspace, [3, 4], 1) p.random_ini() #p.alpha=0.95 if True: dude = p[0] #dude.random_influence='1D' dude.add_attractor(ones(dim), 1.) dude.speed[:] = 1, 0 for i in range(20): dude.do_step()