Beispiel #1
0
    def run_simulation(self):
        if not self.pause:
            if self.current_timestep < self.max_timestep:
                for i in range(len(self.environments)):
                    self.environments[i].drop_object_one_level()
                    agent_sensor_output = self.environments[i].agent.get_sensor_array(self.environments[i])
                    ann_inputs = agent_sensor_output
                    prediction = self.ann.predict(inputs=ann_inputs)
                    self.environments[i].prediction_to_maneuver(prediction=prediction)
                self.draw_agents()
                self.draw_beer_objects()
                self.update_text()
                self.current_timestep += 1
            else:
                print "Simulation over"
                print self.ann.weights
                PhenotypeBeerTracker.environments_for_fitness = self.environments
                for l in range(len(self.environments)):
                    PhenotypeBeerTracker.environments_for_fitness[l].reset()
                    fitness = PhenotypeBeerTracker.fitness_evaluation(self.phenotype)
                    self.canvas.itemconfig(self.fitness_texts[l], text="Fitness:" + str(round(fitness[0], 3)) + " "+ str(fitness[1][l]))

                #self.plot_data(self.fitness_log_average, self.fitness_log_best, self.standard_deviation_log)
                return
        self.after(self.delay, lambda: self.run_simulation())
Beispiel #2
0
    def run_simulation(self):
        if not self.pause:
            if self.current_timestep < self.max_timestep:
                for i in range(len(self.environments)):
                    self.environments[i].drop_object_one_level()
                    agent_sensor_output = self.environments[
                        i].agent.get_sensor_array(self.environments[i])
                    ann_inputs = agent_sensor_output
                    prediction = self.ann.predict(inputs=ann_inputs)
                    self.environments[i].prediction_to_maneuver(
                        prediction=prediction)
                self.draw_agents()
                self.draw_beer_objects()
                self.update_text()
                self.current_timestep += 1
            else:
                print "Simulation over"
                print self.ann.weights
                PhenotypeBeerTracker.environments_for_fitness = self.environments
                for l in range(len(self.environments)):
                    PhenotypeBeerTracker.environments_for_fitness[l].reset()
                    fitness = PhenotypeBeerTracker.fitness_evaluation(
                        self.phenotype)
                    self.canvas.itemconfig(self.fitness_texts[l],
                                           text="Fitness:" +
                                           str(round(fitness[0], 3)) + " " +
                                           str(fitness[1][l]))

                #self.plot_data(self.fitness_log_average, self.fitness_log_best, self.standard_deviation_log)
                return
        self.after(self.delay, lambda: self.run_simulation())
    def do_fitness_testing(self, environments):
        PhenotypeBeerTracker.environments_for_fitness = environments
        res = []
        if MULTIPROCESSING:
            res = parmap(PhenotypeBeerTracker.fitness_evaluation, self.phenotype_children_pool)
        else:
            for phenotype in self.phenotype_children_pool:
                res.append(PhenotypeBeerTracker.fitness_evaluation(phenotype))
        for i in range(len(res)):
            self.phenotype_children_pool[i].fitness_value = res[i][0]
            self.phenotype_children_pool[i].fitness_components = res[i][1]

        # When using mixing in adult selection, the previous generation have to be reevaluated on the new scenarios
        if self.adult_selection_protocol == 3:
            res = parmap(PhenotypeBeerTracker.fitness_evaluation, self.phenotype_adult_pool)
            for i in range(len(res)):
                self.phenotype_adult_pool[i].fitness_value = res[i][0]
                self.phenotype_adult_pool[i].fitness_components = res[i][1]
 def init_phenotype_type(self, genotype):
     return PhenotypeBeerTracker(genotype,
                                 symbol_set_size=self.symbol_set_size,
                                 hidden_layers=self.hidden_layers,
                                 activation_functions=self.activation_functions)