Bardo.PopulationManager.PopulationManager (Bardo v0.1.0)

View Source

The population_manager is a process that spawns a population of neural network systems, monitors their performance, applies a selection algorithm to the NNs in the population, and generates the mutant offspring from the fit NNs, while removing the unfit. The population_manager module is the one responsible for mapping the genotypes to their phenotypes.

A population is a group of agents, in a neuroevolutionary system those agents are NN based systems. The genotypes of our NN's are represented as lists of structs. In our system, each NN genome is composed of a single cortex, one or more sensors, one or more actuators, and one or more neurons. Each element of the NN system knows what other elements it is connected to through element ids.

During one of our simulations we might want to start the experiment with many different species. Since the NN's depend on their morphologies, we can create a population with two different species, each with it own morphology. Then, when the NN's are created in those species, they would naturally start off with different sets available to them and belonging to the particular species they were seeded in.

The offspring are created through cloning and mutation. Not all fit agents are equal, some are more equal than others, some have a higher fitness level. Though all the fit agents will survive to the next generation, the number of offspring each agent creates will depend on that agent's fitness. The population_manager will decide how many offspring to allocate to each agent. The offspring will be created by first cloning the fit agent, and then by mutating the clone to produce a variation, a mutant, of it. The clone, with its own unique id, is assigned to the same specie that its parent belongs to. Once all the offspring are created, where "all" means the same number as was deleted during the selection process, the new generation of agents is then released back into the scape, or applied again to the problem. Then, the evolutionary cycle repeats.

Summary

Functions

The agent_terminated accepts the requests sent by the agents which terminate after finishing with their evaluations. The function specializes in the "competition" selection algorithm, which is a generational selection algorithm. As a generation selection algorithm, it waits until the entire population has finished being evaluated, and only then selects the fit from the unfit, and creates the updated population of the next generation. The OpTag can be set from the outside to shutdown the population_manager by setting it to done. Once an ending condition is reached, either through a generation limit, an evaluations limit, or fitness goal, the population_manager exits normally. If the ending condition is not reached, the population_manager spawns the new generation of agents and awaits again for all the agents in the population to complete their evaluations. If the OpTag is set to pause, it does not generate a new population, and instead goes into a waiting mode, and awaits to be restarted or terminated.

Calculate the average number of neurons per agent in a specie.

Calculate the diversity of agents in a specie based on their fingerprints.

Calculate the fitness statistics for a specie.

Gather statistics for all species in a population.

The set_evaluations function is called after the agent has completed its evaluation run. It calculates the total number of evaluations, gathers stats, etc.

The set_goal_reached function sets the goal_reached flag of the population_manager to true.

The population_manager process accepts a pause command, which if it receives, it then goes into pause mode after all the agents have completed with their evaluations. The process can only go into pause mode if it is currently in the continue mode (its op_tag is set to continue). The population_manager process can accept a continue command if its current op_tag is set to pause. When it receives a continue command, it summons all the agents in the population, and continues with its neuroevolution synchronization duties.

Spawns a PopulationManager process and calls init to initialize.

Starts a linked GenServer process for the PopulationManager. This function is used by supervision trees.

The validation_complete function is called after the validation test run has completed. It returns the fitness score of the validation test agent.

Functions

agent_terminated(agent_id)

@spec agent_terminated(binary() | Bardo.Models.agent_id()) :: :ok

The agent_terminated accepts the requests sent by the agents which terminate after finishing with their evaluations. The function specializes in the "competition" selection algorithm, which is a generational selection algorithm. As a generation selection algorithm, it waits until the entire population has finished being evaluated, and only then selects the fit from the unfit, and creates the updated population of the next generation. The OpTag can be set from the outside to shutdown the population_manager by setting it to done. Once an ending condition is reached, either through a generation limit, an evaluations limit, or fitness goal, the population_manager exits normally. If the ending condition is not reached, the population_manager spawns the new generation of agents and awaits again for all the agents in the population to complete their evaluations. If the OpTag is set to pause, it does not generate a new population, and instead goes into a waiting mode, and awaits to be restarted or terminated.

calculate_specie_avg_nodes(specie_id)

Calculate the average number of neurons per agent in a specie.

calculate_specie_diversity(specie_id)

Calculate the diversity of agents in a specie based on their fingerprints.

calculate_specie_fitness(specie_id)

Calculate the fitness statistics for a specie.

child_spec(args)

gather_stats(population_id, evaluations_acc, state)

Gather statistics for all species in a population.

set_evaluations(specie_id, aea, agent_cycle_acc, agent_time_acc)

@spec set_evaluations(Bardo.Models.specie_id(), integer(), integer(), integer()) ::
  :ok

The set_evaluations function is called after the agent has completed its evaluation run. It calculates the total number of evaluations, gathers stats, etc.

set_goal_reached()

@spec set_goal_reached() :: :ok

The set_goal_reached function sets the goal_reached flag of the population_manager to true.

set_op_tag(op_tag)

@spec set_op_tag(:pause | :continue) :: :ok

The population_manager process accepts a pause command, which if it receives, it then goes into pause mode after all the agents have completed with their evaluations. The process can only go into pause mode if it is currently in the continue mode (its op_tag is set to continue). The population_manager process can accept a continue command if its current op_tag is set to pause. When it receives a continue command, it summons all the agents in the population, and continues with its neuroevolution synchronization duties.

start(node)

@spec start(node()) :: pid()

Spawns a PopulationManager process and calls init to initialize.

start_link(args \\ [])

Starts a linked GenServer process for the PopulationManager. This function is used by supervision trees.

validation_complete(agent_id, fitness)

@spec validation_complete(Bardo.Models.agent_id(), float()) :: :ok

The validation_complete function is called after the validation test run has completed. It returns the fitness score of the validation test agent.