def setup_method(self): pop_size = 500 length = 10 init_population = get_onemax_samples(pop_size, length) optimizer = Optimizer(sample_data=init_population) model1 = get_onemax_model() optimizer.add_objective("ones", model1.predict, direction="maximize") model2 = get_linear_model(length) optimizer.add_objective("linear_min", model2.predict, direction="minimize") optimizer.add_discrete_constraint(fname="1", constraints=[0, 1, 2]) optimizer.add_onehot_groupconstraint(group=["3", "4", "5"], lower=1, upper=1) optimizer.add_sumtotal_groupconstraint(group=["7", "8", "9"], lower=2, upper=2) optimizer.compile() self.optimizer = optimizer self.strategy = self.optimizer.strategy self.init_population = self.optimizer.spawn_population(100).values
def setup_method(self): pop_size = 500 length = 10 init_population = get_onemax_samples(pop_size, length) optimizer = Optimizer(sample_data=init_population) model1 = get_onemax_model() optimizer.add_objective("ones", model1.predict, direction="maximize") model2 = get_linear_model(length) optimizer.add_objective("linear_min", model2.predict, direction="minimize") optimizer.add_discrete_constraint(fname="2", constraints=[0, 1, 2]) optimizer.add_discrete_constraint(fname="3", constraints=[0, 1, 2]) optimizer.add_onehot_groupconstraint(group=["4", "5"]) optimizer.add_sumtotal_groupconstraint(group=["6", "7", "8"], lower=5, upper=5) self.optimizer = optimizer
def test_evaluate(self): X = get_onemax_samples(500, 10) fitness = self.optimizer.evaluate_population(X) assert np.all(fitness.columns == ["ones", "linear_min"])
def setup_method(self): length = 20 init_popualtion = get_onemax_samples(500, length) optimizer = Optimizer(sample_data=init_popualtion) model1 = get_onemax_model() optimizer.add_objective("ones", model1.predict, direction="maximize") model2 = get_linear_model(length) optimizer.add_objective("linear_min", model2.predict, direction="minimize") model3 = get_linear_model(length) optimizer.add_objective("linear_max", model3.predict, direction="maximize") optimizer.add_discrete_constraint(fname="2", constraints=[0, 1, 2]) optimizer.add_discrete_constraint(fname="3", constraints=[0, 1, 2]) optimizer.add_valuerange_constraint(fname="2", lower=0, upper=2) optimizer.add_valuerange_constraint(fname="3", lower=0, upper=2) optimizer.add_onehot_groupconstraint(group=["4", "5"]) optimizer.add_onehot_groupconstraint(group=["6", "7"]) optimizer.add_sumtotal_groupconstraint(group=["8", "9", "10"], lower=1, upper=1) optimizer.add_sumtotal_groupconstraint(group=["11", "12"], lower=0, upper=1) def user_func(X): print("test func is called!!") print(X.columns) return X optimizer.add_user_constraint(user_func) self.optimizer = optimizer self.tempdir = os.path.join(os.path.expanduser("~"), "temp") if not os.path.exists(self.tempdir): os.makedirs(self.tempdir)
def setup_method(self): init_population = get_onemax_samples(500, 10) self.optimizer = Optimizer(sample_data=init_population) model1 = get_onemax_model() self.optimizer.add_objective("ones", model1.predict, direction="maximize") model2 = get_linear_model(10) self.optimizer.add_objective("linear_min", model2.predict, direction="minimize")
def setup_method(self): pop_size = 500 length = 20 init_population = get_onemax_samples(pop_size, length) optimizer = Optimizer(sample_data=init_population) model1 = get_onemax_model() optimizer.add_objective("ones", model1.predict, direction="maximize") model2 = get_linear_model(length) optimizer.add_objective("linear_min", model2.predict, direction="minimize") optimizer.add_discrete_constraint(fname="2", constraints=[0, 1, 2]) optimizer.add_discrete_constraint(fname="3", constraints=[0, 1, 2]) optimizer.add_onehot_groupconstraint(group=["4", "5", "6"], n=1) optimizer.add_sumtotal_groupconstraint(group=["7", "8", "9"], lower=2, upper=2) optimizer.add_onehot_groupconstraint(group=["10", "11", "12", "13"], n=3) optimizer.add_onehot_groupconstraint(group=["14", "15"], lower=3, upper=3) optimizer.compile() self.optimizer = optimizer population = self.optimizer.spawner.spawn(30) population = self.optimizer.strategy.constraint(population.values) self.population = pd.DataFrame( population, columns=self.optimizer.config.feature_names)
def setup_method(self): pop_size = 500 length = 10 init_population = get_onemax_samples(pop_size, length) optimizer = Optimizer(sample_data=init_population) model1 = get_onemax_model() optimizer.add_objective("ones", model1.predict, direction="maximize") model2 = get_linear_model(length) optimizer.add_objective("linear_min", model2.predict, direction="minimize") optimizer.add_discrete_constraint(fname="2", constraints=[0, 1, 2]) optimizer.add_discrete_constraint(fname="3", constraints=[0, 1, 2]) optimizer.add_onehot_groupconstraint(group=["4", "5", "6"]) optimizer.add_sumtotal_groupconstraint(group=["7", "8", "9"], lower=2, upper=2) optimizer.compile() self.optimizer = optimizer population = self.optimizer.spawner.spawn(30) population = self.optimizer.strategy.constraint(population.values) self.population = pd.DataFrame( population, columns=self.optimizer.config.feature_names) self.export_dir = os.path.join(os.path.expanduser("~"), "optga") if not os.path.exists(self.export_dir): os.makedirs(self.export_dir)
def setup_method(self): init_population = get_onemax_samples(500, 10) self.optimizer = Optimizer(sample_data=init_population)