Population

This module contains the class Population.

Created on Tue Sep 17 14:29:43 2019

@author: Jorge Mario Cruz-Duarte (jcrvz.github.io), e-mail: j.m.cruzduarte@ieee.org

The Population class represents a collection of search agents within a bounded domain. It manages agent positions, velocities, fitness values, and selection strategies.

Initialisation schemes: random, sobol, halton, lhs, vertex, among others.

Selection methods: greedy, all, metropolis, probabilistic.

Quick usage:

from customhys.population import Population

pop = Population(boundaries=([-5]*10, [5]*10), num_agents=30)
pop.initialise_positions("random")
class customhys.population.Population(boundaries, num_agents=30, is_constrained=True)[source]

Bases: object

This is the Population class, each object corresponds to a population of agents within a search space.

iteration = 0
metropolis_temperature = 1000.0
metropolis_rate = 0.01
metropolis_boltzmann = 1.0
probability_selection = 0.5
__init__(boundaries, num_agents=30, is_constrained=True)[source]

Return a population of size num_agents within a problem domain defined by boundaries.

Parameters:
  • boundaries (tuple) –

    A tuple with two lists of size D corresponding to the lower and upper limits of search space, such as:

    boundaries = (lower_boundaries, upper_boundaries)

    Note: Dimensions of search domain are read from these boundaries.

  • num_agents (int) – optional. Number of search agents or population size. The default is 30.

  • is_constrained (bool) – optional. Avoid agents abandon the search space. The default is True.

Returns:

population object.

property positions
get_state()[source]
Return a string containing the current state of the population, i.e.,

str = ‘x_best = ARRAY, f_best = VALUE’

Returns:

str

get_positions()[source]
Return the current population positions. Positions are represented in a matrix of size:

positions.shape() = (num_agents, num_dimensions)

NOTE: The position is rescaled from the normalised search space, i.e., [-1, 1]^num_dimensions.

Returns:

numpy.ndarray

set_positions(positions)[source]
Modify the current population positions. Positions are represented in a matrix of size:

positions.shape() = (num_agents, num_dimensions)

Note: The position is rescaled to the original search space.

Parameters:

positions (numpy.ndarray) – Population positions must have the size num_agents-by-num_dimensions array.

Returns:

numpy.ndarray

revert_positions()[source]

Revert the positions to the data in backup variables.

update_positions(level='population', selector='greedy')[source]

Update the population positions according to the level and selection scheme.

NOTE: When an operator is applied (from the operators’ module), it automatically replaces new positions, so the logic of selectors is contrary as they commonly do.

Parameters:
  • level (str) – optional Update level, it can be ‘population’ for the entire population, ‘particular’ for each agent_id (an historical performance), and ‘global’ for the current solution. The default is ‘population’.

  • selector (str) – optional Selection method. The selectors available are: ‘greedy’, ‘probabilistic’, ‘metropolis’, ‘all’, and ‘none’. The default is ‘all’.

Returns:

None.

evaluate_fitness(problem_function)[source]

Evaluate the population positions in the problem function.

Parameters:

problem_function (function) – A function that maps a 1-by-D array of real values to a real value.

Returns:

None.

initialise_positions(scheme='random')[source]

Initialise population by an initialisation scheme.

Parameters:

scheme (str) – optional Initialisation scheme. Available schemes are: - ‘random’: Random uniform distribution in [-1,1] (default) - ‘vertex’: Vertices of nested hyper-cubes - ‘lhs’: Latin Hypercube Sampling - ‘sobol’: Sobol quasi-random sequences - ‘halton’: Halton quasi-random sequences - ‘beta’: Beta distribution - ‘normal’: Normal (Gaussian) distribution - ‘lognormal’: Lognormal distribution - ‘exponential’: Exponential distribution - ‘rayleigh’: Rayleigh distribution

Returns:

None.

rescale_back(position)[source]

Rescale an agent position from [-1.0, 1.0] to the original search space boundaries per dimension.

Parameters:

position (numpy.ndarray) – A position given by an array of 1-by-D with elements between [-1, 1].

Returns:

ndarray