def _apply_diversity(self, teams_population, teams_to_keep, diversity):
     if Config.USER['advanced_training_parameters']['novelty']['enabled']:
         archive = teams_population+list(Config.RESTRICTIONS['novelty_archive']['samples'])
         DiversityMaintenance.calculate_diversities(archive, self.environment.point_population_)
         self._update_novelty_archive(teams_population, diversity)
     else:
         DiversityMaintenance.calculate_diversities(teams_population, self.environment.point_population_)
     
     if (Config.USER['advanced_training_parameters']['novelty']['enabled'] 
         and not Config.USER['advanced_training_parameters']['novelty']['use_fitness']):
         sorted_solutions = sorted(teams_population, key=lambda solution: solution.diversity_[diversity], 
             reverse=True)
         keep_teams = sorted_solutions[0:teams_to_keep]
         remove_teams = sorted_solutions[teams_to_keep:]
         pareto_front = []
     else:
         keep_teams, remove_teams, pareto_front = ParetoDominanceForTeams.run(teams_population, diversity, 
             teams_to_keep)
     return keep_teams, remove_teams, pareto_front
Beispiel #2
0
    def _select_teams_to_keep_and_remove(self, teams_population, is_validation):
        teams_to_remove = int(Config.USER['training_parameters']['replacement_rate']['teams']*float(len(teams_population)))
        teams_to_keep = len(teams_population) - teams_to_remove

        diversities_to_apply = Config.USER['advanced_training_parameters']['diversity']['use_and_show']
        if len(diversities_to_apply) == 0:
            if len(Config.USER['advanced_training_parameters']['diversity']['only_show']) > 0:
                DiversityMaintenance.calculate_diversities(teams_population, self.environment.point_population())
            sorted_solutions = sorted(teams_population, key=lambda solution: solution.fitness_, reverse=True)
            keep_teams = sorted_solutions[0:teams_to_keep]
            remove_teams = sorted_solutions[teams_to_keep:]
            pareto_front = []
        else:
            options = list(Config.USER['advanced_training_parameters']['diversity']['use_and_show'])
            if len(diversities_to_apply) > 1 and self.previous_diversity_:
                options.remove(self.previous_diversity_)
            novelty = random.choice(options)
            DiversityMaintenance.calculate_diversities(teams_population, self.environment.point_population())
            keep_teams, remove_teams, pareto_front = ParetoDominanceForTeams.run(teams_population, novelty, teams_to_keep)
            self.previous_diversity_ = novelty
        return keep_teams, remove_teams, pareto_front