(self,plotfig)
The basic loop
The basic loop
The basic loop
def runGA(self,plotfig):
		"""The basic loop"""
		pl.ion()
		#plotfig = pl.figure()
		bestfit = np.zeros(self.nEpochs)

		for i in range(self.nEpochs):
			# Compute fitness of the population
			fitness = eval(self.fitnessFunction)(self.population)

			# Pick parents -- can do in order since they are randomised
			newPopulation = self.fps(self.population,fitness)

			# Apply the genetic operators
			if self.crossover == 'sp':
				newPopulation = self.spCrossover(newPopulation)
			elif self.crossover == 'un':
				newPopulation = self.uniformCrossover(newPopulation)
			newPopulation = self.mutate(newPopulation)

			# Apply elitism and tournaments if using
			if self.nElite>0:
				newPopulation = self.elitism(self.population,newPopulation,fitness)
	
			if self.tournament:
				newPopulation = self.tournament(self.population,newPopulation,fitness,self.fitnessFunction)
	
			self.population = newPopulation
			bestfit[i] = fitness.max()

			if (np.mod(i,100)==0):
				print i, fitness.max()	
			#pl.plot([i],[fitness.max()],'r+')
		pl.plot(bestfit,'kx-')
def runGA ( self , plotfig ) : pl . ion ( ) #plotfig = pl.figure() bestfit = np . zeros ( self . nEpochs ) for i in range ( self . nEpochs ) : # Compute fitness of the population fitness = eval ( self . fitnessFunction ) ( self . population ) # Pick parents -- can do in order since they are randomised newPopulation = self . fps ( self . population , fitness ) # Apply the genetic operators if self . crossover == 'sp' : newPopulation = self . spCrossover ( newPopulation ) elif self . crossover == 'un' : newPopulation = self . uniformCrossover ( newPopulation ) newPopulation = self . mutate ( newPopulation ) # Apply elitism and tournaments if using if self . nElite > 0 : newPopulation = self . elitism ( self . population , newPopulation , fitness ) if self . tournament : newPopulation = self . tournament ( self . population , newPopulation , fitness , self . fitnessFunction ) self . population = newPopulation bestfit [ i ] = fitness . max ( ) if ( np . mod ( i , 100 ) == 0 ) : print i , fitness . max ( ) #pl.plot([i],[fitness.max()],'r+') pl . plot ( bestfit , 'kx-' )