def objective_function(self, weights): """Constructs cellular automata, set weights of MLP as rule for cellular automata, run cellular automata until it stops and compare result with desired pattern. In this case desired pattern is two band. """ lattice = create_automaton(self.conf_file) lattice.rule.set_weights(weights) lattice.run(self.stop_criterion) self.lattice_age_list.append(lattice.age) objlog = logging.getLogger("OBJECTIVEFNC") objlog.info("iterations {}".format(lattice.age)) if lattice.chaotic: # if lattice doesn't have stable configuration objlog.info("unstable lattice") return 1.0 else: error = self.error_function(self.pattern, lattice) if error < self.min_error: objlog.info("updating minimal error to: {}".format(error)) self.min_error = error self.best_weights = weights self.lattice_age = lattice.age self.progress.append((error,weights)) if self.callback: self.callback() # hack objlog.debug("error: {}".format(error)) return error
def start_simulation(config_path): log = logging.getLogger("THREAD") replay_file_name = os.path.join(PROJECTS, self.name, "replays", time.strftime("%Y_%m_%d_%H_%M_%S.replay")) automaton = create_automaton(config_path) log.debug("automaton created") automaton.run_with_record(AgeStopCriterion(800), replay_file_name) log.info("Running finished! Replay saved in {}".format(replay_file_name))