Ejemplo n.º 1
0
    def act(self):
        # Process the information if the agent has sense nearby agents
        if self.agents_found:

            # Combine the original individual and individuals found by interacting with nearby agents to form
            # a population
            individuals = self.individual + self.nearby_agents

            # Find out parents from the population
            parents = selection(individuals)

            # Crossover parents and add to the new population.
            cross_pop = crossover(parents)

            # Mutate the new population.
            new_pop = mutation(cross_pop)

            # Evaluate the fitness of the new population.
            new_pop = evaluate_fitness(new_pop)

            # Replace the old population with the new population.
            individuals = replacement(new_pop, individuals)

            # Generate statistics for run so far
            get_stats(individuals)

            # Sort the individuals list
            individuals.sort(reverse=True)

            # Get the highest performing individual from the sorted population
            self.new_individual = individuals[0]
Ejemplo n.º 2
0
 def children(self):
     """Return a list of children from this population."""
     children = []
     while len(children) < self.cut_off_count:
         children.extend(crossover_inds(*self._get_parents_for_crossover()))
     return evaluate_fitness(mutation(children),
                             current_generation=self.current_generation)
Ejemplo n.º 3
0
def step(individuals):
    """
    Runs a single generation of the evolutionary algorithm process:
        Selection
        Variation
        Evaluation
        Replacement
    
    :param individuals: The current generation, upon which a single
    evolutionary generation will be imposed.
    :return: The next generation of the population.
    """

    # Select parents from the original population.
    parents = selection(individuals)

    # Crossover parents and add to the new population.
    cross_pop = crossover(parents)

    # Mutate the new population.
    new_pop = mutation(cross_pop)

    # Evaluate the fitness of the new population.
    new_pop = evaluate_fitness(new_pop)

    # Replace the old population with the new population.
    individuals = replacement(new_pop, individuals)

    # Generate statistics for run so far
    params['STATISTICS'].get_stats(individuals)

    return individuals
Ejemplo n.º 4
0
    def act(self):
        # Process the information if the agent has sense nearby agents
        if self.agents_found:

            # Combine the original individual and individuals found by interacting with nearby agents to form 
            # a population
            individuals = self.individual + self.nearby_agents

            # Find out parents from the population
            parents = selection(individuals)

            # Crossover parents and add to the new population.
            cross_pop = crossover(parents)

            # Mutate the new population.
            new_pop = mutation(cross_pop)

            # Evaluate the fitness of the new population.
            new_pop = evaluate_fitness(new_pop)

            # Replace the old population with the new population.
            individuals = replacement(new_pop, individuals)

            # Generate statistics for run so far
            get_stats(individuals)
            
            # Sort the individuals list 
            individuals.sort(reverse=True)

            # Get the higest performing individual from the sorted population 
            self.new_individual = individuals[0]
Ejemplo n.º 5
0
def weips_step(individuals, weight_matrix):
    """
    Runs a single generation of the evolutionary algorithm process:
        Selection
        Variation
        Evaluation
        Replacement

    :param individuals: The current generation, upon which a single
    :param weight_matrix: The matrix of weights used by the selection method.
    :return: The next generation of the population.
    """

    # Size of the population
    pop_size = params['GENERATION_SIZE']

    # Select parents from the original population.
    parents = weips_selection(individuals, weight_matrix, pop_size)

    # Crossover parents and add to the new population.
    cross_pop = crossover(parents)

    # Mutate the new population.
    new_pop = mutation(cross_pop)

    # Evaluate the fitness of the new population (Q_t).
    new_pop = evaluate_fitness(new_pop)

    # Replace the old population with the new population.
    individuals = weips_replacement(new_pop, individuals, weight_matrix)

    # Generate statistics for run so far
    params['STATISTICS'].get_stats(individuals)

    return individuals
Ejemplo n.º 6
0
def step(individuals):
    """
    Runs a single generation of the evolutionary algorithm process:
        Selection
        Variation
        Evaluation
        Replacement
    
    :param individuals: The current generation, upon which a single
    evolutionary generation will be imposed.
    :return: The next generation of the population.
    """

    # Select parents from the original population.
    parents = selection(individuals)

    # Crossover parents and add to the new population.
    cross_pop = crossover(parents)

    # Mutate the new population.
    new_pop = mutation(cross_pop)

    # Evaluate the fitness of the new population.
    new_pop = evaluate_fitness(new_pop)

    # Replace the old population with the new population.
    individuals = replacement(new_pop, individuals)

    # Generate statistics for run so far
    get_stats(individuals)
    
    return individuals
Ejemplo n.º 7
0
def steady_state(individuals):
    """
    Runs a single generation of the evolutionary algorithm process,
    using steady state replacement:
        Selection
        Variation
        Evaluation
        Replacement
        
    Steady state replacement uses the Genitor model (Whitley, 1989) whereby
    new individuals directly replace the worst individuals in the population
    regardless of whether or not the new individuals are fitter than those
    they replace. Note that traditional GP crossover generates only 1 child,
    whereas linear GE crossover (and thus all crossover functions used in
    PonyGE) generates cython_backup children from cython_backup parents. Thus, we use a deletion
    strategy of cython_backup.

    :param individuals: The current generation, upon which a single
    evolutionary generation will be imposed.
    :return: The next generation of the population.
    """

    # Initialise counter for new individuals.
    ind_counter = 0

    while ind_counter < params['POPULATION_SIZE']:

        # Select parents from the original population.
        parents = selection(individuals)

        # Perform crossover on selected parents.
        cross_pop = crossover_inds(parents[0], parents[1])

        if cross_pop is None:
            # Crossover failed.
            pass

        else:
            # Mutate the new population.
            new_pop = mutation(cross_pop)

            # Evaluate the fitness of the new population.
            new_pop = evaluate_fitness(new_pop)

            # Sort the original population
            individuals.sort(reverse=True)

            # Combine both populations
            total_pop = individuals[:-len(new_pop)] + new_pop

            # Increment the ind counter
            ind_counter += params['GENERATION_SIZE']

    # Return the combined population.
    return total_pop
Ejemplo n.º 8
0
def steady_state(individuals):
    """
    Runs a single generation of the evolutionary algorithm process,
    using steady state replacement:
        Selection
        Variation
        Evaluation
        Replacement
        
    Steady state replacement uses the Genitor model (Whitley, 1989) whereby
    new individuals directly replace the worst individuals in the population
    regardless of whether or not the new individuals are fitter than those
    they replace. Note that traditional GP crossover generates only 1 child,
    whereas linear GE crossover (and thus all crossover functions used in
    PonyGE) generates 2 children from 2 parents. Thus, we use a deletion
    strategy of 2.

    :param individuals: The current generation, upon which a single
    evolutionary generation will be imposed.
    :return: The next generation of the population.
    """

    # Initialise counter for new individuals.
    ind_counter = 0

    while ind_counter < params['POPULATION_SIZE']:
        
        # Select parents from the original population.
        parents = selection(individuals)

        # Perform crossover on selected parents.
        cross_pop = crossover_inds(parents[0], parents[1])
        
        if cross_pop is None:
            # Crossover failed.
            pass

        else:
            # Mutate the new population.
            new_pop = mutation(cross_pop)
        
            # Evaluate the fitness of the new population.
            new_pop = evaluate_fitness(new_pop)
    
            # Sort the original population
            individuals.sort(reverse=True)
    
            # Combine both populations
            total_pop = individuals[:-len(new_pop)] + new_pop
        
            # Increment the ind counter
            ind_counter += params['GENERATION_SIZE']

    # Return the combined population.
    return total_pop
Ejemplo n.º 9
0
def step_reload(individuals,initial_population):
    individuals.sort(reverse=True)
    print(str(individuals[0].fitness) + " -v- " + str(params['RESET_FITNESS']))
    if individuals[0].fitness > params['RESET_FITNESS']:
        if params['DYNAMIC_ENVIRONMENT_RELOAD_PERCENTAGE']:
            print("RESETTING PERCENTAGE OF POP")
            new_inds = int(len(initial_population)*params['DYNAMIC_ENVIRONMENT_RELOAD_PERCENTAGE_VALUE'])
            #sample from initial pop randomly
            reload_pop_a = deepcopy(random.sample(initial_population, new_inds))
            reload_pop_b = deepcopy(individuals[:-new_inds])
            reload_pop = reload_pop_a + reload_pop_b
            reload_pop = evaluation(reload_pop)
            reload_pop.sort(reverse=True)
            params['RESET_FITNESS'] = reload_pop[0].fitness
            print("Reload Threshold now: " + str(params['RESET_FITNESS']))
            params['RELOAD_PERFORMED'] = 1
            rep_inds = deepcopy(reload_pop)
            # If we want to use replacement :D
            # individuals = replacement(initial_population, individuals)
        else:
            print("RESETTING POP")
            initial_population = evaluation(initial_population)
            initial_population.sort(reverse=True)
            params['RESET_FITNESS'] = initial_population[0].fitness
            print("Reload Threshold now: "+ str(params['RESET_FITNESS']))
            params['RELOAD_PERFORMED'] = 1
            rep_inds = deepcopy(initial_population)
            #If we want to use replacement :D
            #individuals = replacement(initial_population, individuals)
    else:
        # Select parents
        parents = selection(individuals)

        # Crossover parents and add to the new population
        cross_pop = crossover(parents)

        # Mutate the new population
        new_pop = mutation(cross_pop)

        # Evaluate the fitness of the new population
        new_pop = evaluation(new_pop)

        # Replace the sorted individuals with the new populations
        rep_inds = replacement(new_pop, individuals)

        params['RELOAD_PERFORMED'] = 0

    return rep_inds
Ejemplo n.º 10
0
def step(individuals):
    """Return individuals and best ever individual from a step of
    the EA iteration"""

    if params['BASELINE_STEPS']:
        individuals = evaluation(individuals)
    else:
        # Select parents
        parents = selection(individuals)

        # Crossover parents and add to the new population
        cross_pop = crossover(parents)

        # Mutate the new population
        new_pop = mutation(cross_pop)

        # Evaluate the fitness of the new population
        new_pop = evaluation(new_pop)

        # Replace the sorted individuals with the new populations
        individuals = replacement(new_pop, individuals)

    return individuals