def set_mutation(self,mrate): if(mrate=='gene'): try: del self.mutation_rate #remove local mrates and use gene classes mrate except AttributeError: pass elif(mrate=='adapt'): self.mutation_rate = prng.uniform(self.mr_bounds[0],self.mr_bounds[1]) else: self.__class__.mutation_rate = mrate for child in self._children: child.set_mutation(mrate)
def set_mutation(self, mrate): """ Set the mutation rate of the gene. Arguments: mrate -- can be one of the following: * a number between 0 and 1 - sets the mutation rate of the gene to a specific value. * "gene" - use the mutation rate set in the class definition for this gene. * "adapt" - the mutation rate for the gene is chosen randomly from the range mr_bounds """ if(mrate=='gene'): try: del self.mutation_rate #remove local mrates and use gene classes mrate except AttributeError: pass elif(mrate=='adapt'): self.mutation_rate = prng.uniform(self.mr_bounds[0], self.mr_bounds[1]) else: self.__class__.mutation_rate = mrate
def evaluate(self,gene): bounds=gene.bounds new = prng.uniform(bounds[0], bounds[1]-bounds[0]) return new