def objective_func(self, x): opts = self.vec_to_opts(x) print(opts) # run automata a = Automata(opts) a.run() stats = a.stats() fitness = np.float64(-stats["score_sum"]) print("Fitness: ", fitness) # if fitness < self.best_fitness: # self.best_fitness = fitness # self.best_automata = a return fitness
population_size = 30 optimization_steps = 5000 scaling_factor = 0.01 cross_over_rate = 0.5 problem_size = 4 # x = [-0.1, 0.1, -0.1, 1.0] # y = [1000.0, 1000.0, 1000.0, 1000.0] # x_c = x.ctypes.data_as(c.POINTER(c.c_double)) # y_c = x.ctypes.data_as(c.POINTER(c.c_double)) bounds = [(-0.5, 0.5), (-0.5, 0.5), (-0.5, 0.5), (-0.5, 0.5), (-0.5, 0.5), (0.7, 0.99)] result = de( opt.objective_func, bounds, updating="deferred", workers=2, maxiter=optimization_steps, ) x = result.x opts = opt.vec_to_opts(x) a = Automata(opts) a.run() print("BestAutomata", a) print(a.stats()) p = Plotter(a) p.plot(True) # animate