Beispiel #1
0
	def generator(self, constants):
		"""
		Carries out the standard evolutionary process of parent selection, evolution, and survivor selection.
		
		Parameters:
		
		-``constants``: Config settings for the EA from the config files specified at run time
		"""
		for individual in self.initialIndividuals(constants):
			yield individual

		while True:
			if constants["logAvgFitness"]:
				print self.getAvgFitness()
			parents = self.parentSelection(self.individuals, constants["offSize"] * constants["parentsPerChild"], constants)
			for i in range(0, len(parents), constants["parentsPerChild"]):
				family = parents[i:i + constants["parentsPerChild"]]
				child = Individual(id=id)
				child.parents = [parent.id for parent in family]
				self.id += 1
				self.crossover(child, family, constants)
				self.mutation(child, constants, family)
				self.geneType.fix(child.genes)
				yield child
				self.individuals.append(child)
			self.individuals = self.survivorSelection(self.individuals, constants["popSize"], constants)
Beispiel #2
0
	def generator(self, constants):
		"""
		Carries out the standard evolutionary process of parent selection, evolution, and survivor selection.
		
		Parameters:
		
		-``constants``: Config settings for the EA from the config files specified at run time
		"""
		for _ in self.initialIndividuals(constants):
			pass
		for individual in self.evalPop(constants):
			yield individual
		while True:
			parents = self.parentSelection(self.individuals, constants["offSize"] * constants["parentsPerChild"], constants)
			for i in range(0, len(parents), constants["parentsPerChild"]):
				family = parents[i:i + constants["parentsPerChild"]]
				child = Individual(id=id)
				child.parents = [parent.id for parent in family]
				self.id += 1
				child.crossover = self.crossover(family[0].crossover, family[1].crossover, constants)
				self.mutation(child, constants, family)
				self.individuals.append(child)
			for individual in self.evalPop(constants):
				yield individual
			self.individuals = self.survivorSelection(self.individuals, constants["popSize"], constants)
Beispiel #3
0
    def generator(self, constants):
        """
		Carries out the standard evolutionary process of parent selection, evolution, and survivor selection.
		
		Parameters:
		
		-``constants``: Config settings for the EA from the config files specified at run time
		"""
        for individual in self.initialIndividuals(constants):
            yield individual

        while True:
            if constants["logAvgFitness"]:
                print self.getAvgFitness()
            parents = self.parentSelection(
                self.individuals,
                constants["offSize"] * constants["parentsPerChild"], constants)
            for i in range(0, len(parents), constants["parentsPerChild"]):
                family = parents[i:i + constants["parentsPerChild"]]
                child = Individual(id=id)
                child.parents = [parent.id for parent in family]
                self.id += 1
                self.crossover(child, family, constants)
                self.mutation(child, constants, family)
                self.geneType.fix(child.genes)
                yield child
                self.individuals.append(child)
            self.individuals = self.survivorSelection(self.individuals,
                                                      constants["popSize"],
                                                      constants)
Beispiel #4
0
    def generator(self, constants):
        """
		Carries out the standard evolutionary process of parent selection, evolution, and survivor selection.
		
		Parameters:
		
		-``constants``: Config settings for the EA from the config files specified at run time
		"""
        for _ in self.initialIndividuals(constants):
            pass
        for individual in self.evalPop(constants):
            yield individual
        while True:
            parents = self.parentSelection(
                self.individuals,
                constants["offSize"] * constants["parentsPerChild"], constants)
            for i in range(0, len(parents), constants["parentsPerChild"]):
                family = parents[i:i + constants["parentsPerChild"]]
                child = Individual(id=id)
                child.parents = [parent.id for parent in family]
                self.id += 1
                child.crossover = self.crossover(family[0].crossover,
                                                 family[1].crossover,
                                                 constants)
                self.mutation(child, constants, family)
                self.individuals.append(child)
            for individual in self.evalPop(constants):
                yield individual
            self.individuals = self.survivorSelection(self.individuals,
                                                      constants["popSize"],
                                                      constants)
Beispiel #5
0
	def generator(self, constants, supports=None):
		"""
		Carries out the standard evolutionary process of parent selection, evolution, and survivor selection.
		
		Parameters:
		
		-``constants``: Config settings for the EA from the config files specified at run time
		"""
		supportIndividual = None
		for individual in self.initialIndividuals(constants):
			if "MutationCoPopulation" not in constants["supportPopulations"]:
				# TODO Explain ranging 
				SAfix = GeneTypes.FLT(0.001, constants["mutationStepSize"])
				individual.stepSizes = SAfix.randomGenome(constants["dimensions"])
			yield individual, None

		while True:
			if constants["logAvgFitness"]:
				print self.getAvgFitness()
			#print "generation"
			parents = self.parentSelection(self.individuals, constants["offSize"] * constants["parentsPerChild"], constants)
			for i in range(0, len(parents), constants["parentsPerChild"]):
				family = parents[i:i + constants["parentsPerChild"]]

				child = Individual(id=id)
				child.parents = [parent for parent in family]
				self.id += 1
				#self.crossover(child, family, constants)
				supportIndividuals = list()
				if "MutationCoPopulation" in constants["supportPopulations"]:
					mutationSupportIndividual = supports[MutationCoPopulation]() #mutationSupport()
					rates = mutationSupportIndividual.genes
					supportIndividuals.append(mutationSupportIndividual)
					"""
					for r in rates:
						if r != constants["mutationStepSize"]:
							print "rates changed after creation"
					"""
					#print "mutation created"
				elif "MutationCoPopulation" not in constants["supportPopulations"]:
					bias = 1 / math.sqrt(2.0 * constants["dimensions"]) * random.gauss(0, 1)
					tau = 1 / math.sqrt(2.0 * math.sqrt(constants["dimensions"]))
					child.stepSizes = [(sum(psteps) / len(psteps)) * math.exp(bias + tau * random.gauss(0, 1)) for psteps in zip(*[f.stepSizes for f in family])]
					SAfix.fix(child.stepSizes)
					rates = child.stepSizes
				
				if "SCXCoPopulation" in constants["supportPopulations"]:
					crossoverSupportIndividual = supports[SCXCoPopulation]() #crossoverSupport()
					#print len(crossoverSupportIndividual.crossover.genes)
					Crossover.scxFromSupport(child, parents, crossoverSupportIndividual, constants)
					#print len(crossoverSupportIndividual.crossover.genes)
					supportIndividuals.append(crossoverSupportIndividual)
					#print "crossover created"
					
				elif "SCXCoPopulation" not in constants["supportPopulations"]:
					self.crossover(child, family, constants)
					#print len(child.crossover.genes)
				
				if constants["SuCoLevel"] == "Static":
					rates = constants["stepSizes"]
					
				"""
				for r in rates:
					if r != constants["mutationStepSize"]:
						print "rates changed"
				"""
						
				self.mutation(child, constants, rates)
				self.geneType.fix(child.genes)
				yield child, supportIndividuals
				self.individuals.append(child)

			self.individuals = self.survivorSelection(self.individuals, constants["popSize"], constants)
Beispiel #6
0
    def generator(self, constants, supports=None):
        """
		Carries out the standard evolutionary process of parent selection, evolution, and survivor selection.
		
		Parameters:
		
		-``constants``: Config settings for the EA from the config files specified at run time
		"""
        supportIndividual = None
        for individual in self.initialIndividuals(constants):
            if "MutationCoPopulation" not in constants["supportPopulations"]:
                # TODO Explain ranging
                SAfix = GeneTypes.FLT(0.001, constants["mutationStepSize"])
                individual.stepSizes = SAfix.randomGenome(
                    constants["dimensions"])
            yield individual, None

        while True:
            if constants["logAvgFitness"]:
                print self.getAvgFitness()
            #print "generation"
            parents = self.parentSelection(
                self.individuals,
                constants["offSize"] * constants["parentsPerChild"], constants)
            for i in range(0, len(parents), constants["parentsPerChild"]):
                family = parents[i:i + constants["parentsPerChild"]]

                child = Individual(id=id)
                child.parents = [parent for parent in family]
                self.id += 1
                #self.crossover(child, family, constants)
                supportIndividuals = list()
                if "MutationCoPopulation" in constants["supportPopulations"]:
                    mutationSupportIndividual = supports[MutationCoPopulation](
                    )  #mutationSupport()
                    rates = mutationSupportIndividual.genes
                    supportIndividuals.append(mutationSupportIndividual)
                    """
					for r in rates:
						if r != constants["mutationStepSize"]:
							print "rates changed after creation"
					"""
                    #print "mutation created"
                elif "MutationCoPopulation" not in constants[
                        "supportPopulations"]:
                    bias = 1 / math.sqrt(
                        2.0 * constants["dimensions"]) * random.gauss(0, 1)
                    tau = 1 / math.sqrt(
                        2.0 * math.sqrt(constants["dimensions"]))
                    child.stepSizes = [
                        (sum(psteps) / len(psteps)) *
                        math.exp(bias + tau * random.gauss(0, 1))
                        for psteps in zip(*[f.stepSizes for f in family])
                    ]
                    SAfix.fix(child.stepSizes)
                    rates = child.stepSizes

                if "SCXCoPopulation" in constants["supportPopulations"]:
                    crossoverSupportIndividual = supports[SCXCoPopulation](
                    )  #crossoverSupport()
                    #print len(crossoverSupportIndividual.crossover.genes)
                    Crossover.scxFromSupport(child, parents,
                                             crossoverSupportIndividual,
                                             constants)
                    #print len(crossoverSupportIndividual.crossover.genes)
                    supportIndividuals.append(crossoverSupportIndividual)
                    #print "crossover created"

                elif "SCXCoPopulation" not in constants["supportPopulations"]:
                    self.crossover(child, family, constants)
                    #print len(child.crossover.genes)

                if constants["SuCoLevel"] == "Static":
                    rates = constants["stepSizes"]
                """
				for r in rates:
					if r != constants["mutationStepSize"]:
						print "rates changed"
				"""

                self.mutation(child, constants, rates)
                self.geneType.fix(child.genes)
                yield child, supportIndividuals
                self.individuals.append(child)

            self.individuals = self.survivorSelection(self.individuals,
                                                      constants["popSize"],
                                                      constants)