def test_pickle_fitness(self): fitness = creator.FitnessMax() fitness.values = (1.0, ) fitness_s = pickle.dumps(fitness) fitness_l = pickle.loads(fitness_s) self.assertEqual(fitness, fitness_l, "Unpickled fitness != pickled fitness")
def __init__(self, model_class, initI, initR, initN, param_ranges, error_func, real_values, mut_range=0.1, p_mut=0.25, p_mut_ind=0.75, p_regen=0.2, p_cross=0.5, p_cross_ind=0.5, period=15, stop_cond=-1, tournament_size=10, max_gen=2000, start_fitness=-np.inf): self.model_class = model_class self.initI = initI self.initR = initR self.initN = initN self.param_ranges = param_ranges self.error_func = error_func self.real_values = real_values self.mut_range = mut_range self.p_mut = p_mut self.p_mut_ind = p_mut_ind self.p_regen = p_regen self.p_cross = p_cross self.p_cross_ind = p_cross_ind self.period = period self.stop_cond = stop_cond self.max_gen = max_gen self.start_fitness = start_fitness self.pop = list() self.fits = list() self.fitnesses = list() self.g = 0 self.best = None self.finished = False # creator.create("Individual", dict, fitness=creator.FitnessMax) self.toolbox = base.Toolbox() self.toolbox.register("individual", self.gen_individual, creator.FitnessMax()) self.toolbox.register("population", tools.initRepeat, list, self.toolbox.individual) self.toolbox.register("evaluate", self.fit_func) self.toolbox.register("mate", self.cross_func) self.toolbox.register("mutate", self.mut_func) # self.toolbox.register("select", tools.selTournament, tournsize=tournament_size) self.toolbox.register("select", tools.selBest)
def __init__(self, *args): list.__init__(self, *args) self.fitness = creator.FitnessMax() self.blackBox = BlackBox()
def test_enables_creation(self): self.assertIsInstance(creator.FitnessMax((1, )), base.Fitness)
def _init_individual(cond_tree, val_tree, fitness=creator.FitnessMax()): return DoubleTreeBasedIndividual(cond_tree, val_tree, fitness)