NiaPy.algorithms

Module with implementations of basic and hybrid algorithms.

class NiaPy.algorithms.Algorithm(**kwargs)[source]

Bases: object

Class for implementing algorithms.

Date:

2018

Author

Klemen Berkovič

License:

MIT

Variables
  • Name (List[str]) – List of names for algorithm.

  • Rand (mtrand.RandomState) – Random generator.

  • NP (int) – Number of inidividuals in populatin.

  • InitPopFunc (Callable[[int, Task, mtrand.RandomState, Dict[str, Any]], Tuple[numpy.ndarray, numpy.ndarray[float]]]) – Idividual initialization function.

  • itype (Individual) – Type of individuals used in population, default value is None for Numpy arrays.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

InitPopFunc(NP, rnd=<module 'numpy.random' from '/home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/numpy/random/__init__.py'>, **kwargs)

Initialize starting population that is represented with numpy.ndarray with shape {NP, task.D}.

Parameters
  • task (Task) – Optimization task.

  • NP (int) – Number of individuals in population.

  • rnd (Optional[mtrand.RandomState]) – Random number generator.

  • kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. New population with shape {NP, task.D}.

  2. New population function/fitness values.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float]]

NP = 50
Name = ['Algorithm', 'AAA']
Rand = RandomState(MT19937) at 0x7F0B64D00678
__init__(**kwargs)[source]

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

static algorithmInfo()[source]

Get algorithm information.

Returns

Bit item.

Return type

str

bad_run()[source]

Check if some exeptions where thrown when the algorithm was running.

Returns

True if some error where detected at runtime of the algorithm, otherwise False

Return type

bool

getBest(X, X_f, xb=None, xb_f=inf)[source]

Get the best individual for population.

Parameters
  • X (numpy.ndarray) – Current population.

  • X_f (numpy.ndarray) – Current populations fitness/function values of aligned individuals.

  • xb (numpy.ndarray) – Best individual.

  • xb_f (float) – Fitness value of best individual.

Returns

  1. Coordinates of best solution.

  2. beset fitness/function value.

Return type

Tuple[numpy.ndarray, float]

getParameters()[source]

Get parameters of the algorithm.

Returns

  • Parameter name (str): Represents a parameter name

  • Value of parameter (Any): Represents the value of the parameter

Return type

Dict[str, Any]

initPopulation(task)[source]

Initialize starting population of optimization algorithm.

Parameters

task (Task) – Optimization task.

Returns

  1. New population.

  2. New population fitness values.

  3. Additional arguments.

Return type

Tuple[numpy.ndarray, numpy.ndarray, Dict[str, Any]]

itype = None
normal(loc, scale, D=None)[source]

Get normal random distribution of shape D with mean “loc” and standard deviation “scale”.

Parameters
  • loc (float) – Mean of the normal random distribution.

  • scale (float) – Standard deviation of the normal random distribution.

  • D (Union[int, Iterable[int]]) – Shape of returned normal random distribution.

Returns

Array of numbers.

Return type

Union[numpy.ndarray[float], float]

rand(D=1)[source]

Get random distribution of shape D in range from 0 to 1.

Parameters

D (numpy.ndarray[int]) – Shape of returned random distribution.

Returns

Random number or numbers \(\in [0, 1]\).

Return type

Union[numpy.ndarray[float], float]

randint(Nmax, D=1, Nmin=0, skip=None)[source]

Get discrete uniform (integer) random distribution of D shape in range from “Nmin” to “Nmax”.

Parameters
  • Nmin (int) – Lower integer bound.

  • Nmax (int) – One above upper integer bound.

  • D (Union[int, Iterable[int]]) – shape of returned discrete uniform random distribution.

  • skip (Union[int, Iterable[int], numpy.ndarray[int]]) – numbers to skip.

Returns

Random generated integer number.

Return type

Union[int, numpy.ndarrayj[int]]

randn(D=None)[source]

Get standard normal distribution of shape D.

Parameters

D (Union[int, Iterable[int]]) – Shape of returned standard normal distribution.

Returns

Random generated numbers or one random generated number \(\in [0, 1]\).

Return type

Union[numpy.ndarray[float], float]

run(task)[source]

Start the optimization.

Parameters

task (Task) – Optimization task.

Returns

  1. Best individuals components found in optimization process.

  2. Best fitness value found in optimization process.

Return type

Tuple[numpy.ndarray, float]

runIteration(task, pop, fpop, xb, fxb, **dparams)[source]

Core functionality of algorithm.

This function is called on every algorithm iteration.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population coordinates.

  • fpop (numpy.ndarray) – Current population fitness value.

  • xb (numpy.ndarray) – Current generation best individuals coordinates.

  • xb_f (float) – current generation best individuals fitness value.

  • **dparams (Dict[str, Any]) – Additional arguments for algorithms.

Returns

  1. New populations coordinates.

  2. New populations fitness values.

  3. New global best position/solution

  4. New global best fitness/objective value

  5. Additional arguments of the algorithm.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

runTask(task)[source]

Start the optimization.

Parameters

task (Task) – Task with bounds and objective function for optimization.

Returns

  1. Best individuals components found in optimization process.

  2. Best fitness value found in optimization process.

Return type

Tuple[numpy.ndarray, float]

runYield(task)[source]

Run the algorithm for a single iteration and return the best solution.

Parameters

task (Task) – Task with bounds and objective function for optimization.

Returns

Generator getting new/old optimal global values.

Return type

Generator[Tuple[numpy.ndarray, float], None, None]

Yields

Tuple[numpy.ndarray, float] – 1. New population best individuals coordinates. 2. Fitness value of the best solution.

setParameters(NP=50, InitPopFunc=<function defaultNumPyInit>, itype=None, **kwargs)[source]

Set the parameters/arguments of the algorithm.

Parameters
  • NP (Optional[int]) – Number of individuals in population \(\in [1, \infty]\).

  • InitPopFunc (Optional[Callable[[int, Task, mtrand.RandomState, Dict[str, Any]], Tuple[numpy.ndarray, numpy.ndarray[float]]]]) – Type of individuals used by algorithm.

  • itype (Optional[Any]) – Individual type used in population, default is Numpy array.

  • **kwargs (Dict[str, Any]) – Additional arguments.

static typeParameters()[source]

Return functions for checking values of parameters.

Returns

  • NP (Callable[[int], bool]): Check if number of individuals is \(\in [0, \infty]\).

Return type

Dict[str, Callable]

uniform(Lower, Upper, D=None)[source]

Get uniform random distribution of shape D in range from “Lower” to “Upper”.

Parameters
  • Lower (Iterable[float]) – Lower bound.

  • Upper (Iterable[float]) – Upper bound.

  • D (Union[int, Iterable[int]]) – Shape of returned uniform random distribution.

Returns

Array of numbers \(\in [\mathit{Lower}, \mathit{Upper}]\).

Return type

Union[numpy.ndarray[float], float]

class NiaPy.algorithms.AlgorithmUtility[source]

Bases: object

Base class with string mappings to algorithms.

Variables

classes (Dict[str, Algorithm]) – Mapping from stings to algorithms.

Initialize the algorithms.

__init__()[source]

Initialize the algorithms.

get_algorithm(algorithm)[source]

Get the algorithm.

Parameters

algorithm (Union[str, Algorithm]) – String or class that represents the algorithm.

Returns

Instance of an Algorithm.

Return type

Algorithm

class NiaPy.algorithms.BasicStatistics(array)[source]

Bases: object

Name = ['BasicStatistics']
generate_standard_report()[source]
max_value()[source]
mean()[source]
median()[source]
min_value()[source]
standard_deviation()[source]
class NiaPy.algorithms.Individual(x=None, task=None, e=True, rnd=<module 'numpy.random' from '/home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/numpy/random/__init__.py'>, **kwargs)[source]

Bases: object

Class that represents one solution in population of solutions.

Date:

2018

Author:

Klemen Berkovič

License:

MIT

Variables
  • x (numpy.ndarray) – Coordinates of individual.

  • f (float) – Function/fitness value of individual.

Initialize new individual.

Parameters
  • task (Optional[Task]) – Optimization task.

  • rand (Optional[mtrand.RandomState]) – Random generator.

  • x (Optional[numpy.ndarray]) – Individuals components.

  • e (Optional[bool]) – True to evaluate the individual on initialization. Default value is True.

  • **kwargs (Dict[str, Any]) – Additional arguments.

__eq__(other)[source]

Compare the individuals for equalities.

Parameters

other (Union[Any, numpy.ndarray]) – Object that we want to compare this object to.

Returns

True if equal or False if no equal.

Return type

bool

__getitem__(i)[source]

Get the value of i-th component of the solution.

Parameters

i (int) – Position of the solution component.

Returns

Value of ith component.

Return type

Any

__init__(x=None, task=None, e=True, rnd=<module 'numpy.random' from '/home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/numpy/random/__init__.py'>, **kwargs)[source]

Initialize new individual.

Parameters
  • task (Optional[Task]) – Optimization task.

  • rand (Optional[mtrand.RandomState]) – Random generator.

  • x (Optional[numpy.ndarray]) – Individuals components.

  • e (Optional[bool]) – True to evaluate the individual on initialization. Default value is True.

  • **kwargs (Dict[str, Any]) – Additional arguments.

__len__()[source]

Get the length of the solution or the number of components.

Returns

Number of components.

Return type

int

__setitem__(i, v)[source]

Set the value of i-th component of the solution to v value.

Parameters
  • i (int) – Position of the solution component.

  • v (Any) – Value to set to i-th component.

__str__()[source]

Print the individual with the solution and objective value.

Returns

String representation of self.

Return type

str

copy()[source]

Return a copy of self.

Method returns copy of this object so it is safe for editing.

Returns

Copy of self.

Return type

Individual

evaluate(task, rnd=<module 'numpy.random' from '/home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/numpy/random/__init__.py'>)[source]

Evaluate the solution.

Evaluate solution this.x with the help of task. Task is used for reparing the solution and then evaluating it.

Parameters
  • task (Task) – Objective function object.

  • rnd (Optional[mtrand.RandomState]) – Random generator.

See also

  • NiaPy.util.Task.repair()

f = inf
generateSolution(task, rnd=<module 'numpy.random' from '/home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/numpy/random/__init__.py'>)[source]

Generate new solution.

Generate new solution for this individual and set it to self.x. This method uses rnd for getting random numbers. For generating random components rnd and task is used.

Parameters
  • task (Task) – Optimization task.

  • rnd (Optional[mtrand.RandomState]) – Random numbers generator object.

x = None
NiaPy.algorithms.defaultIndividualInit(task, NP, rnd=<module 'numpy.random' from '/home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/numpy/random/__init__.py'>, itype=None, **kwargs)[source]

Initialize NP individuals of type itype.

Parameters
  • task (Task) – Optimization task.

  • NP (int) – Number of individuals in population.

  • rnd (Optional[mtrand.RandomState]) – Random number generator.

  • itype (Optional[Individual]) – Class of individual in population.

  • kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. Initialized individuals.

  2. Initialized individuals function/fitness values.

Return type

Tuple[numpy.ndarray[Individual], numpy.ndarray[float]

NiaPy.algorithms.defaultNumPyInit(task, NP, rnd=<module 'numpy.random' from '/home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/numpy/random/__init__.py'>, **kwargs)[source]

Initialize starting population that is represented with numpy.ndarray with shape {NP, task.D}.

Parameters
  • task (Task) – Optimization task.

  • NP (int) – Number of individuals in population.

  • rnd (Optional[mtrand.RandomState]) – Random number generator.

  • kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. New population with shape {NP, task.D}.

  2. New population function/fitness values.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float]]

NiaPy.algorithms.basic

Implementation of basic nature-inspired algorithms.

class NiaPy.algorithms.basic.AgingNpDifferentialEvolution(**kwargs)[source]

Bases: NiaPy.algorithms.basic.de.DifferentialEvolution

Implementation of Differential evolution algorithm with aging individuals.

Algorithm:

Differential evolution algorithm with dynamic population size that is defined by the quality of population

Date:

2018

Author:

Klemen Berkovič

License:

MIT

Variables
  • Name (List[str]) – list of strings representing algorithm names.

  • Lt_min (int) – Minimal age of individual.

  • Lt_max (int) – Maximal age of individual.

  • delta_np (float) – Proportion of how many individuals shall die.

  • omega (float) – Acceptance rate for individuals to die.

  • mu (int) – Mean of individual max and min age.

  • age (Callable[[int, int, float, float, float, float, float], int]) – Function for calculation of age for individual.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['AgingNpDifferentialEvolution', 'ANpDE']
aging(task, pop)[source]

Apply aging to individuals.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray[Individual]) – Current population.

Returns

New population.

Return type

numpy.ndarray[Individual]

static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

deltaPopC(t)[source]

Calculate how many individuals are going to be created.

Parameters

t (int) – Number of generations made by the algorithm.

Returns

Number of individuals to be born.

Return type

int

deltaPopE(t)[source]

Calculate how many individuals are going to dye.

Parameters

t (int) – Number of generations made by the algorithm.

Returns

Number of individuals to dye.

Return type

int

popDecrement(pop, task)[source]

Decrement population.

Parameters
  • pop (numpy.ndarray) – Current population.

  • task (Task) – Optimization task.

Returns

Decreased population.

Return type

numpy.ndarray[Individual]

popIncrement(pop, task)[source]

Increment population.

Parameters
  • pop (numpy.ndarray[Individual]) – Current population.

  • task (Task) – Optimization task.

Returns

Increased population.

Return type

numpy.ndarray[Individual]

postSelection(pop, task, xb, fxb, **kwargs)[source]

Post selection operator.

Parameters
  • pop (numpy.ndarray) – Current population.

  • task (Task) – Optimization task.

  • xb (Individual) – Global best individual.

  • **kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New global best solution

  3. New global best solutions fitness/objective value

Return type

Tuple[numpy.ndarray, numpy.ndarray, float]

selection(pop, npop, xb, fxb, task, **kwargs)[source]

Select operator for individuals with aging.

Parameters
  • pop (numpy.ndarray) – Current population.

  • npop (numpy.ndarray) – New population.

  • xb (numpy.ndarray) – Current global best solution.

  • fxb (float) – Current global best solutions fitness/objective value.

  • task (Task) – Optimization task.

  • **kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. New population of individuals.

  2. New global best solution.

  3. New global best solutions fitness/objective value.

Return type

Tuple[numpy.ndarray, numpy.ndarray, float]

setParameters(Lt_min=0, Lt_max=12, delta_np=0.3, omega=0.3, age=<function proportional>, CrossMutt=<function CrossBest1>, **ukwargs)[source]

Set the algorithm parameters.

Parameters
  • Lt_min (Optional[int]) – Minimum life time.

  • Lt_max (Optional[int]) – Maximum life time.

  • age (Optional[Callable[[int, int, float, float, float, float, float], int]]) – Function for calculation of age for individual.

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • Lt_min (Callable[[int], bool])

  • Lt_max (Callable[[int], bool])

  • delta_np (Callable[[float], bool])

  • omega (Callable[[float], bool])

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.AgingNpMultiMutationDifferentialEvolution(**kwargs)[source]

Bases: NiaPy.algorithms.basic.de.AgingNpDifferentialEvolution, NiaPy.algorithms.basic.de.MultiStrategyDifferentialEvolution

Implementation of Differential evolution algorithm with aging individuals.

Algorithm:

Differential evolution algorithm with dynamic population size that is defined by the quality of population

Date:

2018

Author:

Klemen Berkovič

License:

MIT

Variables

Name (List[str]) – List of strings representing algorithm names

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['AgingNpMultiMutationDifferentialEvolution', 'ANpMSDE']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

evolve(pop, xb, task, **kwargs)[source]

Evolve current population.

Parameters
  • pop (numpy.ndarray) – Current population.

  • xb (numpy.ndarray) – Global best individual.

  • task (Task) – Optimization task.

  • **kwargs (Dict[str, Any]) – Additional arguments.

Returns

New population of individuals.

Return type

numpy.ndarray

setParameters(**ukwargs)[source]

Set core parameter arguments.

Parameters

**ukwargs (Dict[str, Any]) – Additional arguments.

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

Mappings form parameter names to test functions.

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.ArtificialBeeColonyAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Artificial Bee Colony algorithm.

Algorithm:

Artificial Bee Colony algorithm

Date:

2018

Author:

Uros Mlakar and Klemen Berkovič

License:

MIT

Reference paper:

Karaboga, D., and Bahriye B. “A powerful and efficient algorithm for numerical function optimization: artificial bee colony (ABC) algorithm.” Journal of global optimization 39.3 (2007): 459-471.

Arguments

Name (List[str]): List containing strings that represent algorithm names Limit (Union[float, numpy.ndarray[float]]): Limt

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

CalculateProbs(Foods, Probs)[source]

Calculate the probes.

Parameters
  • Foods (numpy.ndarray) – TODO

  • Probs (numpy.ndarray) – TODO

Returns

TODO

Return type

numpy.ndarray

Name = ['ArtificialBeeColonyAlgorithm', 'ABC']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

initPopulation(task)[source]

Initialize the starting population.

Parameters

task (Task) – Optimization task

Returns

  1. New population

  2. New population fitness/function values

  3. Additional arguments:
    • Probes (numpy.ndarray): TODO

    • Trial (numpy.ndarray): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

runIteration(task, Foods, fpop, xb, fxb, Probs, Trial, **dparams)[source]

Core funciton of the algorithm.

Parameters
  • task (Task) – Optimization task

  • Foods (numpy.ndarray) – Current population

  • fpop (numpy.ndarray[float]) – Function/fitness values of current population

  • xb (numpy.ndarray) – Current best individual

  • fxb (float) – Current best individual fitness/function value

  • Probs (numpy.ndarray) – TODO

  • Trial (numpy.ndarray) – TODO

  • dparams (Dict[str, Any]) – Additional parameters

Returns

  1. New population

  2. New population fitness/function values

  3. New global best solution

  4. New global best fitness/objecive value

  5. Additional arguments:
    • Probes (numpy.ndarray): TODO

    • Trial (numpy.ndarray): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=10, Limit=100, **ukwargs)[source]

Set the parameters of Artificial Bee Colony Algorithm.

Parameters
  • Limit (Optional[Union[float, numpy.ndarray[float]]]) – Limt

  • **ukwargs (Dict[str, Any]) – Additional arguments

static typeParameters()[source]

Return functions for checking values of parameters.

Returns

  • Limit (Callable[Union[float, numpy.ndarray[float]]]): TODO

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.BacterialForagingOptimizationAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of the Bacterial foraging optimization algorithm.

Date:

2021

Author:

Žiga Stupan

License:

MIT

Reference paper:
    1. Passino, “Biomimicry of bacterial foraging for distributed optimization and control,” in IEEE Control Systems Magazine, vol. 22, no. 3, pp. 52-67, June 2002, doi: 10.1109/MCS.2002.1004010.

Variables

Name (List[str]) – list of strings representing algorithm names.

Initialize algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['BacterialForagingOptimizationAlgorithm', 'BFOA', 'BFO']
__init__(**kwargs)[source]

Initialize algorithm.

Parameters

seed (int) – Starting seed for random generator.

static algorithmInfo()[source]

Get algorithm information.

Returns

Bit item.

Return type

str

getParameters()[source]

Get parameters of the algorithm.

Returns

  • Parameter name (str): Represents a parameter name

  • Value of parameter (Any): Represents the value of the parameter

Return type

Dict[str, Any]

initPopulation(task)[source]

Initialize starting population of optimization algorithm.

Parameters

task (Task) – Optimization task.

Returns

  1. New population.

  2. New population fitness values.

  3. Additional arguments.

Return type

Tuple[numpy.ndarray, numpy.ndarray, Dict[str, Any]]

interaction(cell, population)[source]

Compute cell to cell interaction J_cc.

Parameters
  • cell (Cell) – Cell to compute interaction for.

  • population (numpy.ndarray[Cell]) – Population

Returns

Cell to cell interaction J_cc

Return type

float

random_direction(dimension)[source]

Generate a random direction vector.

Parameters

dimension (int) – Problem dimension

Returns

Normalised random direction vector

Return type

numpy.ndarray

runIteration(task, pop, fpop, xb, fxb, **dparams)[source]

Core function of Bacterial Foraging Optimization algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population.

  • fpop (numpy.ndarray) – Current populations fitness/function values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individuals function/fitness value.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New populations function/fitness values.

  3. New global best solution,

  4. New global best solutions fitness/objective value.

  5. Additional arguments.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=50, n_chemotactic=100, n_swim=4, n_reproduction=4, n_elimination=2, prob_elimination=0.25, step_size=0.1, d_attract=0.1, w_attract=0.2, h_repel=0.1, w_repel=10.0, **kwargs)[source]

Set the parameters/arguments of the algorithm.

Parameters
  • NP (Optional[int]) – Number of individuals in population \(\in [1, \infty]\).

  • n_chemotactic (Optional[int]) – Number of chemotactic steps.

  • n_swim (Optional[int]) – Number of swim steps.

  • n_reproduction (Optional[int]) – Number of reproduction steps.

  • n_elimination (Optional[int]) – Number of elimination and dispersal steps.

  • prob_elimination (Optional[float]) – Probability of a bacterium being eliminated and a new one being created at a random location in the search space.

  • step_size (Optional[float]) – Size of a chemotactic step.

  • d_attract (Optional[float]) – Depth of the attractant released by the cell (a quantification of how much attractant is released).

  • w_attract (Optional[float]) – Width of the attractant signal (a quantification of the diffusion rate of the chemical).

  • h_repel (Optional[float]) – Height of the repellant effect (magnitude of its effect).

  • w_repel (Optional[float]) – Width of the repellant.

  • **kwargs (Dict[str, Any]) – Additional arguments.

static typeParameters()[source]

Return functions for checking values of parameters.

Returns

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.BareBonesFireworksAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Bare Bones Fireworks Algorithm.

Algorithm:

Bare Bones Fireworks Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.sciencedirect.com/science/article/pii/S1568494617306609

Reference paper:

Junzhi Li, Ying Tan, The bare bones fireworks algorithm: A minimalist global optimizer, Applied Soft Computing, Volume 62, 2018, Pages 454-462, ISSN 1568-4946, https://doi.org/10.1016/j.asoc.2017.10.046.

Variables
  • Name (lsit of str) – List of strings representing algorithm names

  • n (int) – Number of spraks

  • C_a (float) – amplification coefficient

  • C_r (float) – reduction coefficient

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['BareBonesFireworksAlgorithm', 'BBFWA']
static algorithmInfo()[source]

Get default information of algorithm.

Returns

Basic information.

Return type

str

initPopulation(task)[source]

Initialize starting population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initial solution.

  2. Initial solution function/fitness value.

  3. Additional arguments:
    • A (numpy.ndarray): Starting aplitude or search range.

Return type

Tuple[numpy.ndarray, float, Dict[str, Any]]

runIteration(task, x, x_fit, xb, fxb, A, **dparams)[source]

Core function of Bare Bones Fireworks Algorithm.

Parameters
  • task (Task) – Optimization task.

  • x (numpy.ndarray) – Current solution.

  • x_fit (float) – Current solution fitness/function value.

  • xb (numpy.ndarray) – Current best solution.

  • fxb (float) – Current best solution fitness/function value.

  • A (numpy.ndarray) – Serach range.

  • dparams (Dict[str, Any]) – Additional parameters.

Returns

  1. New solution.

  2. New solution fitness/function value.

  3. New global best solution.

  4. New global best solutions fitness/objective value.

  5. Additional arguments:
    • A (numpy.ndarray): Serach range.

Return type

Tuple[numpy.ndarray, float, numpy.ndarray, float, Dict[str, Any]]

setParameters(n=10, C_a=1.5, C_r=0.5, **ukwargs)[source]

Set the arguments of an algorithm.

Parameters
  • n (int) – Number of sparks \(\in [1, \infty)\).

  • C_a (float) – Amplification coefficient \(\in [1, \infty)\).

  • C_r (float) – Reduction coefficient \(\in (0, 1)\).

static typeParameters()[source]

Return functions for checking values of parameters.

Returns

  • NP (Callable[[int], bool]): Check if number of individuals is \(\in [0, \infty]\).

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.BatAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Bat algorithm.

Algorithm:

Bat algorithm

Date:

2015

Authors:

Iztok Fister Jr., Marko Burjek and Klemen Berkovič

License:

MIT

Reference paper:

Yang, Xin-She. “A new metaheuristic bat-inspired algorithm.” Nature inspired cooperative strategies for optimization (NICSO 2010). Springer, Berlin, Heidelberg, 2010. 65-74.

Variables
  • Name (List[str]) – List of strings representing algorithm name.

  • A (float) – Loudness.

  • r (float) – Pulse rate.

  • Qmin (float) – Minimum frequency.

  • Qmax (float) – Maximum frequency.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['BatAlgorithm', 'BA']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

getParameters()[source]

Get parameters of the algorithm.

Returns

Dict[str, Any]

initPopulation(task)[source]

Initialize the starting population.

Parameters

task (Task) – Optimization task

Returns

  1. New population.

  2. New population fitness/function values.

  3. Additional arguments:
    • S (numpy.ndarray): Solutions

    • Q (numpy.ndarray[float]): Frequencies

    • v (numpy.ndarray[float]): Velocities

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

localSearch(best, task, **kwargs)[source]

Improve the best solution according to the Yang (2010).

Parameters
  • best (numpy.ndarray) – Global best individual.

  • task (Task) – Optimization task.

  • **kwargs (Dict[str, Any]) – Additional arguments.

Returns

New solution based on global best individual.

Return type

numpy.ndarray

runIteration(task, Sol, Fitness, xb, fxb, S, Q, v, **dparams)[source]

Core function of Bat Algorithm.

Parameters
  • task (Task) – Optimization task.

  • Sol (numpy.ndarray) – Current population

  • Fitness (numpy.ndarray[float]) – Current population fitness/funciton values

  • best (numpy.ndarray) – Current best individual

  • f_min (float) – Current best individual function/fitness value

  • S (numpy.ndarray) – Solutions

  • Q (numpy.ndarray) – Frequencies

  • v (numpy.ndarray) – Velocities

  • best – Global best used by the algorithm

  • f_min – Global best fitness value used by the algorithm

  • dparams (Dict[str, Any]) – Additional algorithm arguments

Returns

  1. New population

  2. New population fitness/function vlues

  3. New global best solution

  4. New global best fitness/objective value

  5. Additional arguments:
    • S (numpy.ndarray): Solutions

    • Q (numpy.ndarray): Frequencies

    • v (numpy.ndarray): Velocities

    • best (numpy.ndarray): Global best

    • f_min (float): Global best fitness

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=40, A=0.5, r=0.5, Qmin=0.0, Qmax=2.0, **ukwargs)[source]

Set the parameters of the algorithm.

Parameters
  • A (Optional[float]) – Loudness.

  • r (Optional[float]) – Pulse rate.

  • Qmin (Optional[float]) – Minimum frequency.

  • Qmax (Optional[float]) – Maximum frequency.

static typeParameters()[source]

Return dict with where key of dict represents parameter name and values represent checking functions for selected parameter.

Returns

  • A (Callable[[Union[float, int]], bool]): Loudness.

  • r (Callable[[Union[float, int]], bool]): Pulse rate.

  • Qmin (Callable[[Union[float, int]], bool]): Minimum frequency.

  • Qmax (Callable[[Union[float, int]], bool]): Maximum frequency.

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.BeesAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Bees algorithm.

Algorithm:

The Bees algorithm

Date:

2019

Authors:

Rok Potočnik

License:

MIT

Reference paper:

DT Pham, A Ghanbarzadeh, E Koc, S Otri, S Rahim, and M Zaidi. The bees algorithm-a novel tool for complex optimisation problems. In Proceedings of the 2nd Virtual International Conference on Intelligent Production Machines and Systems (IPROMS 2006), pages 454–459, 2006

Variables
  • NP (Optional[int]) – Number of scout bees parameter.

  • m (Optional[int]) – Number of sites selected out of n visited sites parameter.

  • e (Optional[int]) – Number of best sites out of m selected sitest parameter.

  • nep (Optional[int]) – Number of bees recruited for best e sites parameter.

  • nsp (Optional[int]) – Number of bees recruited for the other selected sites parameter.

  • ngh (Optional[float]) – Initial size of patches parameter.

  • ukwargs (Dict[str, Any]) – Additional arguments.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['BeesAlgorithm', 'BEA']
static algorithmInfo()[source]

Get information about algorithm.

Returns

Algorithm information

Return type

str

beeDance(x, task, ngh)[source]

Bees Dance. Search for new positions.

Parameters
  • x (numpy.ndarray) – One instance from the population.

  • task (Task) – Optimization task.

  • ngh (float) – A small value for patch search.

Returns

  1. New population.

  2. New population fitness/function values.

Return type

Tuple[numpy.ndarray, float]

getParameters()[source]

Get parameters of the algorithm.

Returns

Return type

Dict[str, Any]

initPopulation(task)[source]

Initialize the starting population.

Parameters

task (Task) – Optimization task

Returns

  1. New population.

  2. New population fitness/function values.

Return type

Tuple[numpy.ndarray, numpy.ndarray, Dict[str, Any]]

repair(x, lower, upper)[source]

Truncate exceeded dimensions to the limits.

Parameters
  • x (numpy.ndarray) – Individual to repair.

  • lower (numpy.ndarray) – Lower limits for dimensions.

  • upper (numpy.ndarray) – Upper limits for dimensions.

Returns

Repaired individual.

Return type

numpy.ndarray

runIteration(task, BeesPosition, BeesCost, xb, fxb, ngh, **dparams)[source]

Core function of Forest Optimization Algorithm.

Parameters
  • task (Task) – Optimization task.

  • BeesPosition (numpy.ndarray[float]) – Current population.

  • BeesCost (numpy.ndarray[float]) – Current population function/fitness values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individual fitness/function value.

  • ngh (float) – A small value used for patches.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New population fitness/function values.

  3. New global best solution.

  4. New global best fitness/objective value.

  5. Additional arguments:
    • ngh (float): A small value used for patches.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=40, m=5, e=4, ngh=1, nep=4, nsp=2, **ukwargs)[source]

Set the parameters of the algorithm.

Parameters
  • NP (Optional[int]) – Number of scout bees parameter.

  • m (Optional[int]) – Number of sites selected out of n visited sites parameter.

  • e (Optional[int]) – Number of best sites out of m selected sitest parameter.

  • nep (Optional[int]) – Number of bees recruited for best e sites parameter.

  • nsp (Optional[int]) – Number of bees recruited for the other selected sites parameter.

  • ngh (Optional[float]) – Initial size of patches parameter.

  • ukwargs (Dict[str, Any]) – Additional arguments.

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • NP (Callable[[int], bool]): Checks if number of bees parameter has a proper value.

  • m (Callable[[int], bool]): Checks if number of selected sites parameter has a proper value.

  • e (Callable[[int], bool]): Checks if number of elite selected sites parameter has a proper value.

  • nep (Callable[[int], bool]): Checks if number of elite bees parameter has a proper value.

  • nsp (Callable[[int], bool]): Checks if number of other bees parameter has a proper value.

  • ngh (Callable[[float], bool]): Checks if size of patches parameter has a proper value.

Return type

Dict[str, Callable]

See also

  • NiaPy.algorithms.algorithm.Algorithm.typeParameters()

class NiaPy.algorithms.basic.CamelAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Camel traveling behavior.

Algorithm:

Camel algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.iasj.net/iasj?func=fulltext&aId=118375

Reference paper:

Ali, Ramzy. (2016). Novel Optimization Algorithm Inspired by Camel Traveling Behavior. Iraq J. Electrical and Electronic Engineering. 12. 167-177.

Variables
  • Name (List[str]) – List of strings representing name of the algorithm.

  • T_min (float) – Minimal temperature of environment.

  • T_max (float) – Maximal temperature of environment.

  • E_init (float) – Starting value of energy.

  • S_init (float) – Starting value of supplys.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['CamelAlgorithm', 'CA']
static algorithmInfo()[source]

Get information about algorithm.

Returns

Algorithm information

Return type

str

getParameters()[source]

Get parameters of the algorithm.

Returns

Return type

Dict[str, Any]

initPop(task, NP, rnd, itype, **kwargs)[source]

Initialize starting population.

Parameters
  • task (Task) – Optimization task.

  • NP (int) – Number of camels in population.

  • rnd (mtrand.RandomState) – Random number generator.

  • itype (Individual) – Individual type.

  • **kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. Initialize population of camels.

  2. Initialized populations function/fitness values.

Return type

Tuple[numpy.ndarray[Camel], numpy.ndarray[float]]

initPopulation(task)[source]

Initialize population.

Parameters

task (Task) – Optimization taks.

Returns

  1. New population of Camels.

  2. New population fitness/function values.

  3. Additional arguments.

Return type

Tuple[numpy.ndarray[Camel], numpy.ndarray[float], dict]

lifeCycle(c, mu, task)[source]

Apply life cycle to Camel.

Parameters
  • c (Camel) – Camel to apply life cycle.

  • mu (float) – Vision range of camel.

  • task (Task) – Optimization task.

Returns

Camel with life cycle applyed to it.

Return type

Camel

oasis(c, rn, alpha)[source]

Apply oasis function to camel.

Parameters
  • c (Camel) – Camel to apply oasis on.

  • rn (float) – Random number.

  • alpha (float) – View range of Camel.

Returns

Camel with appliyed oasis on.

Return type

Camel

runIteration(task, caravan, fcaravan, cb, fcb, **dparams)[source]

Core function of Camel Algorithm.

Parameters
  • task (Task) – Optimization task.

  • caravan (numpy.ndarray[Camel]) – Current population of Camels.

  • fcaravan (numpy.ndarray[float]) – Current population fitness/function values.

  • cb (Camel) – Current best Camel.

  • fcb (float) – Current best Camel fitness/function value.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population

  2. New population function/fitness value

  3. New global best solution

  4. New global best fitness/objective value

  5. Additional arguments

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, folat, dict]

setParameters(NP=50, omega=0.25, mu=0.5, alpha=0.5, S_init=10, E_init=10, T_min=- 10, T_max=10, **ukwargs)[source]

Set the arguments of an algorithm.

Parameters
  • NP (Optional[int]) – Population size \(\in [1, \infty)\).

  • T_min (Optional[float]) – Minimum temperature, must be true \($T_{min} < T_{max}\).

  • T_max (Optional[float]) – Maximum temperature, must be true \(T_{min} < T_{max}\).

  • omega (Optional[float]) – Burden factor \(\in [0, 1]\).

  • mu (Optional[float]) – Dying rate \(\in [0, 1]\).

  • S_init (Optional[float]) – Initial supply \(\in (0, \infty)\).

  • E_init (Optional[float]) – Initial endurance \(\in (0, \infty)\).

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • omega (Callable[[Union[int, float]], bool])

  • mu (Callable[[float], bool])

  • alpha (Callable[[float], bool])

  • S_init (Callable[[Union[float, int]], bool])

  • E_init (Callable[[Union[float, int]], bool])

  • T_min (Callable[[Union[float, int], bool])

  • T_max (Callable[[Union[float, int], bool])

Return type

Dict[str, Callable]

walk(c, cb, task)[source]

Move the camel in search space.

Parameters
  • c (Camel) – Camel that we want to move.

  • cb (Camel) – Best know camel.

  • task (Task) – Optimization task.

Returns

Camel that moved in the search space.

Return type

Camel

class NiaPy.algorithms.basic.CatSwarmOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Cat swarm optimiization algorithm.

Algorithm: Cat swarm optimization

Date: 2019

Author: Mihael Baketarić

License: MIT

Reference paper: Chu, S. C., Tsai, P. W., & Pan, J. S. (2006). Cat swarm optimization. In Pacific Rim international conference on artificial intelligence (pp. 854-858). Springer, Berlin, Heidelberg..

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['CatSwarmOptimization', 'CSO']
static algorithmInfo()[source]

Get algorithm information.

Returns

Algorithm information.

Return type

str

initPopulation(task)[source]

Initialize population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized population.

  2. Initialized populations fitness/function values.

  3. Additional arguments:
    • Dictionary of modes (seek or trace) and velocities for each cat

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

randomSeekTrace()[source]

Set cats into seeking/tracing mode.

Returns

One or zero. One means tracing mode. Zero means seeking mode. Length of list is equal to NP.

Return type

numpy.ndarray

repair(x, l, u)[source]

Repair array to range.

Parameters
  • x (numpy.ndarray) – Array to repair.

  • l (numpy.ndarray) – Lower limit of allowed range.

  • u (numpy.ndarray) – Upper limit of allowed range.

Returns

Repaired array.

Return type

numpy.ndarray

runIteration(task, pop, fpop, xb, fxb, velocities, modes, **dparams)[source]

Core function of Cat Swarm Optimization algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population.

  • fpop (numpy.ndarray) – Current population fitness/function values.

  • xb (numpy.ndarray) – Current best individual.

  • fxb (float) – Current best cat fitness/function value.

  • velocities (numpy.ndarray) – Velocities of individuals.

  • modes (numpy.ndarray) – Flag of each individual.

  • **dparams (Dict[str, Any]) – Additional function arguments.

Returns

  1. New population.

  2. New population fitness/function values.

  3. New global best solution.

  4. New global best solutions fitness/objective value.

  5. Additional arguments:
    • Dictionary of modes (seek or trace) and velocities for each cat.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

seekingMode(task, cat, fcat, pop, fpop, fxb)[source]

Seeking mode.

Parameters
  • task (Task) – Optimization task.

  • cat (numpy.ndarray) – Individual from population.

  • fcat (float) – Current individual’s fitness/function value.

  • pop (numpy.ndarray) – Current population.

  • fpop (numpy.ndarray) – Current population fitness/function values.

  • fxb (float) – Current best cat fitness/function value.

Returns

  1. Updated individual’s position

  2. Updated individual’s fitness/function value

  3. Updated global best position

  4. Updated global best fitness/function value

Return type

Tuple[numpy.ndarray, float, numpy.ndarray, float]

setParameters(NP=30, MR=0.1, C1=2.05, SMP=3, SPC=True, CDC=0.85, SRD=0.2, vMax=1.9, **ukwargs)[source]

Set the algorithm parameters.

Parameters
  • NP (int) – Number of individuals in population.

  • MR (float) – Mixture ratio.

  • C1 (float) – Constant in tracing mode.

  • SMP (int) – Seeking memory pool.

  • SPC (bool) – Self-position considering.

  • CDC (float) – Decides how many dimensions will be varied.

  • SRD (float) – Seeking range of the selected dimension.

  • vMax (float) – Maximal velocity.

  • Also (See) –

tracingMode(task, cat, velocity, xb)[source]

Tracing mode.

Parameters
  • task (Task) – Optimization task.

  • cat (numpy.ndarray) – Individual from population.

  • velocity (numpy.ndarray) – Velocity of individual.

  • xb (numpy.ndarray) – Current best individual.

Returns

  1. Updated individual’s position

  2. Updated individual’s fitness/function value

  3. Updated individual’s velocity vector

Return type

Tuple[numpy.ndarray, float, numpy.ndarray]

static typeParameters()[source]

Return functions for checking values of parameters.

Returns

  • NP (Callable[[int], bool]): Check if number of individuals is \(\in [0, \infty]\).

Return type

Dict[str, Callable]

weightedSelection(weights)[source]

Random selection considering the weights.

Parameters

weights (numpy.ndarray) – weight for each potential position.

Returns

index of selected next position.

Return type

int

class NiaPy.algorithms.basic.CenterParticleSwarmOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.basic.pso.ParticleSwarmAlgorithm

Implementation of Center Particle Swarm Optimization.

Algorithm:

Center Particle Swarm Optimization

Date:

2019

Authors:

Klemen Berkovič

License:

MIT

Reference paper:

H.-C. Tsai, Predicting strengths of concrete-type specimens using hybrid multilayer perceptrons with center-Unified particle swarm optimization, Adv. Eng. Softw. 37 (2010) 1104–1112.

See also

  • NiaPy.algorithms.basic.WeightedVelocityClampingParticleSwarmAlgorithm

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['CenterParticleSwarmOptimization', 'CPSO']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

getParameters()[source]

Get value of parametrs for this instance of algorithm.

Returns

Dictionary which has parameters maped to values.

Return type

Dict[str, Union[int, float, np.ndarray]]

runIteration(task, pop, fpop, xb, fxb, **dparams)[source]

Core function of algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population of particles.

  • fpop (numpy.ndarray) – Current particles function/fitness values.

  • xb (numpy.ndarray) – Current global best particle.

  • fxb (numpy.ndarray) – Current global best particles function/fitness value.

  • **dparams – Additional arguments.

Returns

  1. New population of particles.

  2. New populations function/fitness values.

  3. New global best particle.

  4. New global best particle function/fitness value.

  5. Additional arguments.

Return type

Tuple[np.ndarray, np.ndarray, np.ndarray, float, dict]

See also

  • NiaPy.algorithm.basic.WeightedVelocityClampingParticleSwarmAlgorithm.runIteration()

setParameters(**kwargs)[source]

Set core algorithm parameters.

Parameters

**kwargs – Additional arguments.

See also

NiaPy.algorithm.basic.WeightedVelocityClampingParticleSwarmAlgorithm.setParameters()

class NiaPy.algorithms.basic.ComprehensiveLearningParticleSwarmOptimizer(**kwargs)[source]

Bases: NiaPy.algorithms.basic.pso.ParticleSwarmAlgorithm

Implementation of Mutated Particle Swarm Optimization.

Algorithm:

Comprehensive Learning Particle Swarm Optimizer

Date:

2019

Authors:

Klemen Berkovič

License:

MIT

Reference paper:
    1. Liang, A. K. Qin, P. N. Suganthan and S. Baskar, “Comprehensive learning particle swarm optimizer for global optimization of multimodal functions,” in IEEE Transactions on Evolutionary Computation, vol. 10, no. 3, pp. 281-295, June 2006. doi: 10.1109/TEVC.2005.857610

Reference URL:

http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=1637688&isnumber=34326

Variables
  • w0 (float) – Inertia weight.

  • w1 (float) – Inertia weight.

  • C (float) – Velocity constant.

  • m (int) – Refresh rate.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['ComprehensiveLearningParticleSwarmOptimizer', 'CLPSO']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

generatePbestCL(i, Pc, pbs, fpbs)[source]

Generate new personal best position for learning.

Parameters
  • i (int) – Current particle.

  • Pc (float) – Learning probability.

  • pbs (numpy.ndarray) – Personal best positions for population.

  • fpbs (numpy.ndarray) – Personal best positions function/fitness values for persolan best position.

Returns

Personal best for learning.

Return type

numpy.ndarray

getParameters()[source]

Get value of parametrs for this instance of algorithm.

Returns

Dictionary which has parameters maped to values.

Return type

Dict[str, Union[int, float, np.ndarray]]

init(task)[source]

Initialize dynamic arguments of Particle Swarm Optimization algorithm.

Parameters

task (Task) – Optimization task.

Returns

  • vMin: Mininal velocity.

  • vMax: Maximal velocity.

  • V: Initial velocity of particle.

  • flag: Refresh gap counter.

Return type

Dict[str, np.ndarray]

runIteration(task, pop, fpop, xb, fxb, popb, fpopb, vMin, vMax, V, flag, Pc, **dparams)[source]

Core function of algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current populations.

  • fpop (numpy.ndarray) – Current population fitness/function values.

  • xb (numpy.ndarray) – Current best particle.

  • fxb (float) – Current best particle fitness/function value.

  • popb (numpy.ndarray) – Particles best position.

  • fpopb (numpy.ndarray) – Particles best positions fitness/function values.

  • vMin (numpy.ndarray) – Minimal velocity.

  • vMax (numpy.ndarray) – Maximal velocity.

  • V (numpy.ndarray) – Velocity of particles.

  • flag (numpy.ndarray) – Refresh rate counter.

  • Pc (numpy.ndarray) – Learning rate.

  • **dparams (Dict[str, Any]) – Additional function arguments.

Returns

  1. New population.

  2. New population fitness/function values.

  3. New global best position.

  4. New global best positions function/fitness value.

  5. Additional arguments:
    • popb: Particles best population.

    • fpopb: Particles best positions function/fitness value.

    • vMin: Minimal velocity.

    • vMax: Maximal velocity.

    • V: Initial velocity of particle.

    • flag: Refresh gap counter.

    • Pc: Learning rate.

Return type

Tuple[np.ndarray, np.ndarray, np.ndarray, dict]

setParameters(m=10, w0=0.9, w1=0.4, C=1.49445, **ukwargs)[source]

Set Particle Swarm Algorithm main parameters.

Parameters
  • w0 (int) – Inertia weight.

  • w1 (float) – Inertia weight.

  • C (float) – Velocity constant.

  • m (float) – Refresh rate.

  • **ukwargs – Additional arguments

updateVelocityCL(V, p, pb, w, vMin, vMax, task, **kwargs)[source]

Update particle velocity.

Parameters
  • V (numpy.ndarray) – Current velocity of particle.

  • p (numpy.ndarray) – Current position of particle.

  • pb (numpy.ndarray) – Personal best position of particle.

  • w (numpy.ndarray) – Weights for velocity adjustment.

  • vMin (numpy.ndarray) – Minimal velocity allowed.

  • vMax (numpy.ndarray) – Maxmimal velocity allowed.

  • task (Task) – Optimization task.

  • kwargs – Additional arguments.

Returns

Updated velocity of particle.

Return type

numpy.ndarray

class NiaPy.algorithms.basic.CoralReefsOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Coral Reefs Optimization Algorithm.

Algorithm:

Coral Reefs Optimization Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference Paper:
  1. Salcedo-Sanz, J. Del Ser, I. Landa-Torres, S. Gil-López, and J. A. Portilla-Figueras, “The Coral Reefs Optimization Algorithm: A Novel Metaheuristic for Efficiently Solving Optimization Problems,” The Scientific World Journal, vol. 2014, Article ID 739768, 15 pages, 2014.

Reference URL:

https://doi.org/10.1155/2014/739768.

Variables
  • Name (List[str]) – List of strings representing algorithm name.

  • phi (float) – Range of neighborhood.

  • Fa (int) – Number of corals used in asexsual reproduction.

  • Fb (int) – Number of corals used in brooding.

  • Fd (int) – Number of corals used in depredation.

  • k (int) – Nomber of trys for larva setting.

  • P_F (float) – Mutation variable \(\in [0, \infty]\).

  • P_Cr (float) – Crossover rate in [0, 1].

  • Distance (Callable[[numpy.ndarray, numpy.ndarray], float]) – Funciton for calculating distance between corals.

  • SexualCrossover (Callable[[numpy.ndarray, float, Task, mtrand.RandomState, Dict[str, Any]], Tuple[numpy.ndarray, numpy.ndarray[float]]]) – Crossover function.

  • Brooding (Callable[[numpy.ndarray, float, Task, mtrand.RandomState, Dict[str, Any]], Tuple[numpy.ndarray, numpy.ndarray]]) – Brooding function.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['CoralReefsOptimization', 'CRO']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

asexualReprodution(Reef, Reef_f, xb, fxb, task)[source]

Asexual reproduction of corals.

Parameters
  • Reef (numpy.ndarray) – Current population of reefs.

  • Reef_f (numpy.ndarray) – Current populations function/fitness values.

  • task (Task) – Optimization task.

Returns

  1. New population.

  2. New population fitness/funciton values.

Return type

Tuple[numpy.ndarray, numpy.ndarray]

See also

depredation(Reef, Reef_f)[source]

Depredation operator for reefs.

Parameters
  • Reef (numpy.ndarray) – Current reefs.

  • Reef_f (numpy.ndarray) – Current reefs function/fitness values.

Returns

  1. Best individual

  2. Best individual fitness/function value

Return type

Tuple[numpy.ndarray, numpy.ndarray]

getParameters()[source]

Get parameters values of the algorithm.

Returns

TODO.

Return type

Dict[str, Any]

runIteration(task, Reef, Reef_f, xb, fxb, **dparams)[source]

Core function of Coral Reefs Optimization algorithm.

Parameters
  • task (Task) – Optimization task.

  • Reef (numpy.ndarray) – Current population.

  • Reef_f (numpy.ndarray) – Current population fitness/function value.

  • xb (numpy.ndarray) – Global best solution.

  • fxb (float) – Global best solution fitness/function value.

  • **dparams – Additional arguments

Returns

  1. New population.

  2. New population fitness/function values.

  3. New global bset solution

  4. New global best solutions fitness/objective value

  5. Additional arguments:

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

See also

  • NiaPy.algorithms.basic.CoralReefsOptimization.SexualCrossover()

  • NiaPy.algorithms.basic.CoralReefsOptimization.Brooding()

setParameters(N=25, phi=0.4, Fa=0.5, Fb=0.5, Fd=0.3, k=25, P_Cr=0.5, P_F=0.36, SexualCrossover=<function SexualCrossoverSimple>, Brooding=<function BroodingSimple>, Distance=<function euclidean>, **ukwargs)[source]

Set the parameters of the algorithm.

Parameters
  • N (int) – population size for population initialization.

  • phi (int) – TODO.

  • Fa (float) – Value $in [0, 1]$ for Asexual reproduction size.

  • Fb (float) – Value $in [0, 1]$ for Brooding size.

  • Fd (float) – Value $in [0, 1]$ for Depredation size.

  • k (int) – Trys for larvae setting.

  • SexualCrossover (Callable[[numpy.ndarray, float, Task, mtrand.RandomState, Dict[str, Any]], Tuple[numpy.ndarray, numpy.ndarray]]) – Crossover function.

  • P_Cr (float) – Crossover rate $in [0, 1]$.

  • Brooding (Callable[[numpy.ndarray, float, Task, mtrand.RandomState, Dict[str, Any]], Tuple[numpy.ndarray, numpy.ndarray]]) – Brooding function.

  • P_F (float) – Crossover rate $in [0, 1]$.

  • Distance (Callable[[numpy.ndarray, numpy.ndarray], float]) – Funciton for calculating distance between corals.

setting(X, X_f, Xn, Xn_f, xb, fxb, task)[source]

Operator for setting reefs.

New reefs try to seatle to selected position in search space. New reefs are successful if theyr fitness values is better or if they have no reef ocupying same search space.

Parameters
  • X (numpy.ndarray) – Current population of reefs.

  • X_f (numpy.ndarray) – Current populations function/fitness values.

  • Xn (numpy.ndarray) – New population of reefs.

  • Xn_f (array of float) – New populations function/fitness values.

  • xb (numpy.ndarray) – Global best solution.

  • fxb (float) – Global best solutions fitness/objective value.

  • task (Task) – Optimization task.

Returns

  1. New seatled population.

  2. New seatled population fitness/function values.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float]

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • N (func): TODO

  • phi (func): TODO

  • Fa (func): TODO

  • Fb (func): TODO

  • Fd (func): TODO

  • k (func): TODO

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.CovarianceMatrixAdaptionEvolutionStrategy(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of (mu, lambda) evolution strategy algorithm. Algorithm is good for dynamic environments. Mu individual create lambda chields. Only best mu chields go to new generation. Mu parents are discarded.

Algorithm:

(\(\mu + \lambda\)) Evolution Strategy Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://arxiv.org/abs/1604.00772

Reference paper:

Hansen, Nikolaus. “The CMA evolution strategy: A tutorial.” arXiv preprint arXiv:1604.00772 (2016).

Variables

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['CovarianceMatrixAdaptionEvolutionStrategy', 'CMA-ES', 'CMAES']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

epsilon = 1e-20
runTask(task)[source]

TODO.

Parameters

task (Task) – Optimization task.

Returns

TODO.

setParameters(epsilon=1e-20, **ukwargs)[source]

Set core parameters of CovarianceMatrixAdaptionEvolutionStrategy algorithm.

Parameters
  • epsilon (float) – Small number.

  • **ukwargs (Dict[str, Any]) – Additional arguments.

static typeParameters()[source]

Return functions for checking values of parameters.

Returns

  • NP (Callable[[int], bool]): Check if number of individuals is \(\in [0, \infty]\).

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.CrowdingDifferentialEvolution(**kwargs)[source]

Bases: NiaPy.algorithms.basic.de.DifferentialEvolution

Implementation of Differential evolution algorithm with multiple mutation strateys.

Algorithm:

Implementation of Differential evolution algorithm with multiple mutation strateys

Date:

2018

Author:

Klemen Berkovič

License:

MIT

Variables
  • Name (List[str]) – List of strings representing algorithm name.

  • CrowPop (float) – Proportion of range for cowding.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['CrowdingDifferentialEvolution', 'CDE']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

selection(pop, npop, xb, fxb, task, **kwargs)[source]

Operator for selection of individuals.

Parameters
  • pop (numpy.ndarray) – Current population.

  • npop (numpy.ndarray) – New population.

  • xb (numpy.ndarray) – Current global best solution.

  • fxb (float) – Current global best solutions fitness/objective value.

  • task (Task) – Optimization task.

  • kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New global best solution.

  3. New global best solutions fitness/objective value.

Return type

Tuple[numpy.ndarray, numpy.ndarray, float]

setParameters(CrowPop=0.1, **ukwargs)[source]

Set core parameters of algorithm.

Parameters
  • CrowPop (Optional[float]) – Crowding distance.

  • **ukwargs – Additional arguments.

class NiaPy.algorithms.basic.CuckooSearch(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Cuckoo behaviour and levy flights.

Algorithm:

Cuckoo Search

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference:

Yang, Xin-She, and Suash Deb. “Cuckoo search via Lévy flights.” Nature & Biologically Inspired Computing, 2009. NaBIC 2009. World Congress on. IEEE, 2009.

Variables
  • Name (List[str]) – list of strings representing algorithm names.

  • N (int) – Population size.

  • pa (float) – Proportion of worst nests.

  • alpha (float) – Scale factor for levy flight.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['CuckooSearch', 'CS']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

emptyNests(pop, fpop, pa_v, task)[source]

Empty ensts.

Parameters
  • pop (numpy.ndarray) – Current population

  • fpop (numpy.ndarray[float]) – Current population fitness/funcion values

  • () (pa_v) – TODO.

  • task (Task) – Optimization task

Returns

  1. New population

  2. New population fitness/function values

Return type

Tuple[numpy.ndarray, numpy.ndarray[float]]

getParameters()[source]

Get parameters of the algorithm.

Returns

  • Parameter name (str): Represents a parameter name

  • Value of parameter (Any): Represents the value of the parameter

Return type

Dict[str, Any]

initPopulation(task)[source]

Initialize starting population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized population.

  2. Initialized populations fitness/function values.

  3. Additional arguments:
    • pa_v (float): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

runIteration(task, pop, fpop, xb, fxb, pa_v, **dparams)[source]

Core function of CuckooSearch algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population.

  • fpop (numpy.ndarray) – Current populations fitness/function values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individual function/fitness values.

  • pa_v (float) – TODO

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. Initialized population.

  2. Initialized populations fitness/function values.

  3. New global best solution

  4. New global best solutions fitness/objective value

  5. Additional arguments:
    • pa_v (float): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(N=50, pa=0.2, alpha=0.5, **ukwargs)[source]

Set the arguments of an algorithm.

Parameters
  • N (int) – Population size \(\in [1, \infty)\)

  • pa (float) – factor \(\in [0, 1]\)

  • alpah (float) – TODO

  • **ukwargs (Dict[str, Any]) – Additional arguments

static typeParameters()[source]

TODO.

Returns

  • N (Callable[[int], bool]): TODO

  • pa (Callable[[float], bool]): TODO

  • alpha (Callable[[Union[int, float]], bool]): TODO

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.DifferentialEvolution(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Differential evolution algorithm.

Algorithm:

Differential evolution algorithm

Date:

2018

Author:

Uros Mlakar and Klemen Berkovič

License:

MIT

Reference paper:

Storn, Rainer, and Kenneth Price. “Differential evolution - a simple and efficient heuristic for global optimization over continuous spaces.” Journal of global optimization 11.4 (1997): 341-359.

Variables
  • Name (List[str]) – List of string of names for algorithm.

  • F (float) – Scale factor.

  • CR (float) – Crossover probability.

  • CrossMutt (Callable[numpy.ndarray, int, numpy.ndarray, float, float, mtrand.RandomState, Dict[str, Any]]) – crossover and mutation strategy.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['DifferentialEvolution', 'DE']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

evolve(pop, xb, task, **kwargs)[source]

Evolve population.

Parameters
  • pop (numpy.ndarray) – Current population.

  • xb (Individual) – Current best individual.

  • task (Task) – Optimization task.

  • **kwargs (Dict[str, Any]) – Additional arguments.

Returns

New evolved populations.

Return type

numpy.ndarray

getParameters()[source]

Get parameters values of the algorithm.

Returns

TODO

Return type

Dict[str, Any]

postSelection(pop, task, xb, fxb, **kwargs)[source]

Apply additional operation after selection.

Parameters
  • pop (numpy.ndarray) – Current population.

  • task (Task) – Optimization task.

  • xb (numpy.ndarray) – Global best solution.

  • **kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New global best solution.

  3. New global best solutions fitness/objective value.

Return type

Tuple[numpy.ndarray, numpy.ndarray, float]

runIteration(task, pop, fpop, xb, fxb, **dparams)[source]

Core function of Differential Evolution algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population.

  • fpop (numpy.ndarray) – Current populations fitness/function values.

  • xb (numpy.ndarray) – Current best individual.

  • fxb (float) – Current best individual function/fitness value.

  • **dparams (dict) – Additional arguments.

Returns

  1. New population.

  2. New population fitness/function values.

  3. New global best solution.

  4. New global best solutions fitness/objective value.

  5. Additional arguments.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

selection(pop, npop, xb, fxb, task, **kwargs)[source]

Operator for selection.

Parameters
  • pop (numpy.ndarray) – Current population.

  • npop (numpy.ndarray) – New Population.

  • xb (numpy.ndarray) – Current global best solution.

  • fxb (float) – Current global best solutions fitness/objective value.

  • task (Task) – Optimization task.

  • **kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. New selected individuals.

  2. New global best solution.

  3. New global best solutions fitness/objective value.

Return type

Tuple[numpy.ndarray, numpy.ndarray, float]

setParameters(NP=50, F=1, CR=0.8, CrossMutt=<function CrossRand1>, **ukwargs)[source]

Set the algorithm parameters.

Parameters
  • NP (Optional[int]) – Population size.

  • F (Optional[float]) – Scaling factor.

  • CR (Optional[float]) – Crossover rate.

  • CrossMutt (Optional[Callable[[numpy.ndarray, int, numpy.ndarray, float, float, mtrand.RandomState, list], numpy.ndarray]]) – Crossover and mutation strategy.

  • ukwargs (Dict[str, Any]) – Additional arguments.

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • F (Callable[[Union[float, int]], bool]): Check for correct value of parameter.

  • CR (Callable[[float], bool]): Check for correct value of parameter.

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.DynNpDifferentialEvolution(**kwargs)[source]

Bases: NiaPy.algorithms.basic.de.DifferentialEvolution

Implementation of Dynamic poulation size Differential evolution algorithm.

Algorithm:

Dynamic poulation size Differential evolution algorithm

Date:

2018

Author:

Klemen Berkovič

License:

MIT

Variables
  • Name (List[str]) – List of strings representing algorithm names.

  • pmax (int) – Number of population reductions.

  • rp (int) – Small non-negative number which is added to value of generations.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['DynNpDifferentialEvolution', 'dynNpDE']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

postSelection(pop, task, xb, fxb, **kwargs)[source]

Post selection operator.

In this algorithm the post selection operator decrements the population at specific iterations/generations.

Parameters
  • pop (numpy.ndarray) – Current population.

  • task (Task) – Optimization task.

  • kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. Changed current population.

  2. New global best solution.

  3. New global best solutions fitness/objective value.

Return type

Tuple[numpy.ndarray, numpy.ndarray, float]

setParameters(pmax=50, rp=3, **ukwargs)[source]

Set the algorithm parameters.

Parameters
  • pmax (Optional[int]) – umber of population reductions.

  • rp (Optional[int]) – Small non-negative number which is added to value of generations.

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • rp (Callable[[Union[float, int]], bool])

  • pmax (Callable[[int], bool])

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.DynNpMultiStrategyDifferentialEvolution(**kwargs)[source]

Bases: NiaPy.algorithms.basic.de.MultiStrategyDifferentialEvolution, NiaPy.algorithms.basic.de.DynNpDifferentialEvolution

Implementation of Dynamic population size Differential evolution algorithm with dynamic population size that is defined by the quality of population.

Algorithm:

Dynamic population size Differential evolution algorithm with dynamic population size that is defined by the quality of population

Date:

2018

Author:

Klemen Berkovič

License:

MIT

Variables

Name (List[str]) – List of strings representing algorithm name.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['DynNpMultiStrategyDifferentialEvolution', 'dynNpMsDE']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

evolve(pop, xb, task, **kwargs)[source]

Evolve the current population.

Parameters
  • pop (numpy.ndarray) – Current population.

  • xb (numpy.ndarray) – Global best solution.

  • task (Task) – Optimization task.

  • **kwargs (dict) – Additional arguments.

Returns

Evolved new population.

Return type

numpy.ndarray

postSelection(pop, task, xb, fxb, **kwargs)[source]

Post selection operator.

Parameters
  • pop (numpy.ndarray) – Current population.

  • task (Task) – Optimization task.

  • **kwargs (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New global best solution.

  3. New global best solutions fitness/objective value.

Return type

Tuple[numpy.ndarray, numpy.ndarray, float]

setParameters(**ukwargs)[source]

Set the arguments of the algorithm.

Parameters

ukwargs (Dict[str, Any]) – Additional arguments.

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • rp (Callable[[Union[float, int]], bool]): TODO

  • pmax (Callable[[int], bool]): TODO

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.DynamicFireworksAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.basic.fwa.DynamicFireworksAlgorithmGauss

Implementation of dynamic fireworks algorithm.

Algorithm:

Dynamic Fireworks Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6900485&isnumber=6900223

Reference paper:
  1. Zheng, A. Janecek, J. Li and Y. Tan, “Dynamic search in fireworks algorithm,” 2014 IEEE Congress on Evolutionary Computation (CEC), Beijing, 2014, pp. 3222-3229. doi: 10.1109/CEC.2014.6900485

Variables

Name (List[str]) – List of strings representing algorithm name.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['DynamicFireworksAlgorithm', 'dynFWA']
static algorithmInfo()[source]

Get default information of algorithm.

Returns

Basic information.

Return type

str

runIteration(task, FW, FW_f, xb, fxb, Ah, Ab, **dparams)[source]

Core function of Dynamic Fireworks Algorithm.

Parameters
  • task (Task) – Optimization task

  • FW (numpy.ndarray) – Current population

  • FW_f (numpy.ndarray[float]) – Current population fitness/function values

  • xb (numpy.ndarray) – Current best solution

  • fxb (float) – Current best solution’s fitness/function value

  • () (Ab) – TODO

  • () – TODO

  • **dparams

Returns

  1. New population.

  2. New population function/fitness values.

  3. Additional arguments:
    • Ah (): TODO

    • Ab (): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

class NiaPy.algorithms.basic.DynamicFireworksAlgorithmGauss(**kwargs)[source]

Bases: NiaPy.algorithms.basic.fwa.EnhancedFireworksAlgorithm

Implementation of dynamic fireworks algorithm.

Algorithm:

Dynamic Fireworks Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6900485&isnumber=6900223

Reference paper:
  1. Zheng, A. Janecek, J. Li and Y. Tan, “Dynamic search in fireworks algorithm,” 2014 IEEE Congress on Evolutionary Computation (CEC), Beijing, 2014, pp. 3222-3229. doi: 10.1109/CEC.2014.6900485

Variables
  • Name (List[str]) – List of strings representing algorithm names.

  • A_cf (Union[float, int]) – TODO

  • C_a (Union[float, int]) – Amplification factor.

  • C_r (Union[float, int]) – Reduction factor.

  • epsilon (Union[float, int]) – Small value.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

ExplosionAmplitude(x_f, xb_f, Ah, As, A_min=None)[source]

Calculate explosion amplitude.

Parameters
  • x_f (float) – Individuals function/fitness value.

  • xb_f (float) – Best individual function/fitness value.

  • Ah (numpy.ndarray) –

  • () (As) – TODO.

  • A_min (Optional[numpy.ndarray]) – Minimal amplitude values.

  • task (Task) – Optimization task.

Returns

New amplitude.

Return type

numpy.ndarray

Mapping(x, task)[source]

Fix out of bound solution/individual.

Parameters
  • x (numpy.ndarray) – Individual.

  • task (Task) – Optimization task.

Returns

Fixed individual.

Return type

numpy.ndarray

Name = ['DynamicFireworksAlgorithmGauss', 'dynFWAG']
NextGeneration(FW, FW_f, FWn, task)[source]

TODO.

Parameters
  • FW (numpy.ndarray) – Current population.

  • FW_f (numpy.ndarray[float]) – Current populations function/fitness values.

  • FWn (numpy.ndarray) – New population.

  • task (Task) – Optimization task.

Returns

  1. New population.

  2. New populations function/fitness values.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float]]

static algorithmInfo()[source]

Get default information of algorithm.

Returns

Basic information.

Return type

str

initAmplitude(task)[source]

Initialize amplitude.

Parameters

task (Task) – Optimization task.

Returns

  1. Initial amplitudes.

  2. Amplitude for best spark.

Return type

Tuple[numpy.ndarray, numpy.ndarray]

initPopulation(task)[source]

Initialize population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized population.

  2. Initialized population function/fitness values.

  3. Additional arguments:
    • Ah (): TODO

    • Ab (): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

repair(x, d, epsilon)[source]

Repair solution.

Parameters
  • x (numpy.ndarray) – Individual.

  • d (numpy.ndarray) – Default value.

  • epsilon (float) – Limiting value.

Returns

Fixed solution.

Return type

numpy.ndarray

runIteration(task, FW, FW_f, xb, fxb, Ah, Ab, **dparams)[source]

Core function of DynamicFireworksAlgorithmGauss algorithm.

Parameters
  • task (Task) – Optimization task.

  • FW (numpy.ndarray) – Current population.

  • FW_f (numpy.ndarray) – Current populations function/fitness values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best fitness/function value.

  • Ah (Union[numpy.ndarray, float]) – TODO

  • Ab (Union[numpy.ndarray, float]) – TODO

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New populations fitness/function values.

  3. New global best solution.

  4. New global best solutions fitness/objective value.

  5. Additional arguments:
    • Ah (Union[numpy.ndarray, float]): TODO

    • Ab (Union[numpy.ndarray, float]): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(A_cf=20, C_a=1.2, C_r=0.9, epsilon=1e-08, **ukwargs)[source]

Set core arguments of DynamicFireworksAlgorithmGauss.

Parameters
static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • A_cr (Callable[[Union[float, int], bool]): TODo

Return type

Dict[str, Callable]

uCF(xnb, xcb, xcb_f, xb, xb_f, Acf, task)[source]

TODO.

Parameters
  • xnb

  • xcb

  • xcb_f

  • xb

  • xb_f

  • Acf

  • task (Task) – Optimization task.

Returns

  1. TODO

Return type

Tuple[numpy.ndarray, float, numpy.ndarray]

class NiaPy.algorithms.basic.EnhancedFireworksAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.basic.fwa.FireworksAlgorithm

Implementation of enganced fireworks algorithm.

Algorithm:

Enhanced Fireworks Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://ieeexplore.ieee.org/document/6557813/

Reference paper:
  1. Zheng, A. Janecek and Y. Tan, “Enhanced Fireworks Algorithm,” 2013 IEEE Congress on Evolutionary Computation, Cancun, 2013, pp. 2069-2077. doi: 10.1109/CEC.2013.6557813

Variables
  • Name (List[str]) – List of strings representing algorithm names.

  • Ainit (float) – Initial amplitude of sparks.

  • Afinal (float) – Maximal amplitude of sparks.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

ExplosionAmplitude(x_f, xb_f, Ah, As, A_min=None)[source]

Calculate explosion amplitude.

Parameters
  • x_f (float) – Individuals function/fitness value.

  • xb_f (float) – Best individual function/fitness value.

  • Ah (numpy.ndarray) –

  • () (As) – TODO.

  • A_min (Optional[numpy.ndarray]) – Minimal amplitude values.

  • task (Task) – Optimization task.

Returns

New amplitude.

Return type

numpy.ndarray

GaussianSpark(x, xb, task)[source]

Create new individual.

Parameters
  • x (numpy.ndarray) –

  • xb (numpy.ndarray) –

  • task (Task) – Optimization task.

Returns

New individual generated by gaussian noise.

Return type

numpy.ndarray

Name = ['EnhancedFireworksAlgorithm', 'EFWA']
NextGeneration(FW, FW_f, FWn, task)[source]

Generate new population.

Parameters
  • FW (numpy.ndarray) – Current population.

  • FW_f (numpy.ndarray[float]) – Current populations fitness/function values.

  • FWn (numpy.ndarray) – New population.

  • task (Task) – Optimization task.

Returns

  1. New population.

  2. New populations fitness/function values.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float]]

static algorithmInfo()[source]

Get default information of algorithm.

Returns

Basic information.

Return type

str

initPopulation(task)[source]

Initialize population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initial population.

  2. Initial populations fitness/function values.

  3. Additional arguments:
    • Ainit (numpy.ndarray): Initial amplitude values.

    • Afinal (numpy.ndarray): Final amplitude values.

    • A_min (numpy.ndarray): Minimal amplitude values.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

initRanges(task)[source]

Initialize ranges.

Parameters

task (Task) – Optimization task.

Returns

  1. Initial amplitude values over dimensions.

  2. Final amplitude values over dimensions.

  3. uAmin.

Return type

Tuple[numpy.ndarray[float], numpy.ndarray[float], numpy.ndarray[float]]

runIteration(task, FW, FW_f, xb, fxb, Ah, Ainit, Afinal, A_min, **dparams)[source]

Core function of EnhancedFireworksAlgorithm algorithm.

Parameters
  • task (Task) – Optimization task.

  • FW (numpy.ndarray) – Current population.

  • FW_f (numpy.ndarray[float]) – Current populations fitness/function values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individuals function/fitness value.

  • Ah (numpy.ndarray[float]) – Current amplitude.

  • Ainit (numpy.ndarray[float]) – Initial amplitude.

  • Afinal (numpy.ndarray[float]) – Final amplitude values.

  • A_min (numpy.ndarray[float]) – Minial amplitude values.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. Initial population.

  2. Initial populations fitness/function values.

  3. New global best solution.

  4. New global best solutions fitness/objective value.

  5. Additional arguments:
    • Ainit (numpy.ndarray): Initial amplitude values.

    • Afinal (numpy.ndarray): Final amplitude values.

    • A_min (numpy.ndarray): Minimal amplitude values.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(Ainit=20, Afinal=5, **ukwargs)[source]

Set EnhancedFireworksAlgorithm algorithms core parameters.

Parameters
  • Ainit (float) – TODO

  • Afinal (float) – TODO

  • **ukwargs (Dict[str, Any]) – Additional arguments.

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • Ainit (Callable[[Union[int, float]], bool]): TODO

  • Afinal (Callable[[Union[int, float]], bool]): TODO

Return type

Dict[str, Callable]

uAmin(Ainit, Afinal, task)[source]

Calculate the value of uAmin.

Parameters
  • Ainit (numpy.ndarray[float]) – Initial amplitude values over dimensions.

  • Afinal (numpy.ndarray[float]) – Final amplitude values over dimensions.

  • task (Task) – Optimization task.

Returns

uAmin.

Return type

numpy.ndarray[float]

class NiaPy.algorithms.basic.EvolutionStrategy1p1(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of (1 + 1) evolution strategy algorithm. Uses just one individual.

Algorithm:

(1 + 1) Evolution Strategy Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

Reference paper:

Variables
  • Name (List[str]) – List of strings representing algorithm names.

  • mu (int) – Number of parents.

  • k (int) – Number of iterations before checking and fixing rho.

  • c_a (float) – Search range amplification factor.

  • c_r (float) – Search range reduction factor.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['EvolutionStrategy1p1', 'EvolutionStrategy(1+1)', 'ES(1+1)']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

initPopulation(task)[source]

Initialize starting individual.

Parameters

task (Task) – Optimization task.

Returns

1, Initialized individual. 2, Initialized individual fitness/function value. 3. Additional arguments:

  • ki (int): Number of successful rho update.

Return type

Tuple[Individual, float, Dict[str, Any]]

mutate(x, rho)[source]

Mutate individual.

Parameters
  • x (Individual) – Current individual.

  • rho (float) – Current standard deviation.

Returns

Mutated individual.

Return type

Individual

runIteration(task, c, fpop, xb, fxb, ki, **dparams)[source]

Core function of EvolutionStrategy(1+1) algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (Individual) – Current position.

  • fpop (float) – Current position function/fitness value.

  • xb (Individual) – Global best position.

  • fxb (float) – Global best function/fitness value.

  • ki (int) – Number of successful updates before rho update.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

1, Initialized individual. 2, Initialized individual fitness/function value. 3. New global best solution. 4. New global best soluitons fitness/objective value. 5. Additional arguments:

  • ki (int): Number of successful rho update.

Return type

Tuple[Individual, float, Individual, float, Dict[str, Any]]

setParameters(mu=1, k=10, c_a=1.1, c_r=0.5, epsilon=1e-20, **ukwargs)[source]

Set the arguments of an algorithm.

Parameters
  • mu (Optional[int]) – Number of parents

  • k (Optional[int]) – Number of iterations before checking and fixing rho

  • c_a (Optional[float]) – Search range amplification factor

  • c_r (Optional[float]) – Search range reduction factor

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • mu (Callable[[int], bool])

  • k (Callable[[int], bool])

  • c_a (Callable[[Union[float, int]], bool])

  • c_r (Callable[[Union[float, int]], bool])

  • epsilon (Callable[[float], bool])

Return type

Dict[str, Callable]

updateRho(rho, k)[source]

Update standard deviation.

Parameters
  • rho (float) – Current standard deviation.

  • k (int) – Number of succesfull mutations.

Returns

New standard deviation.

Return type

float

class NiaPy.algorithms.basic.EvolutionStrategyML(**kwargs)[source]

Bases: NiaPy.algorithms.basic.es.EvolutionStrategyMpL

Implementation of (mu, lambda) evolution strategy algorithm. Algorithm is good for dynamic environments. Mu individual create lambda chields. Only best mu chields go to new generation. Mu parents are discarded.

Algorithm:

(\(\mu + \lambda\)) Evolution Strategy Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

Reference paper:

Variables

Name (List[str]) – List of strings representing algorithm names

See also

  • NiaPy.algorithm.basic.es.EvolutionStrategyMpL

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['EvolutionStrategyML', 'EvolutionStrategy(mu,lambda)', 'ES(m,l)']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

initPopulation(task)[source]

Initialize starting population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized population.

2. Initialized populations fitness/function values. 2. Additional arguments.

Return type

Tuple[numpy.ndarray[Individual], numpy.ndarray[float], Dict[str, Any]]

See also

  • NiaPy.algorithm.basic.es.EvolutionStrategyMpL.initPopulation()

newPop(pop)[source]

Return new population.

Parameters

pop (numpy.ndarray) – Current population.

Returns

New population.

Return type

numpy.ndarray

runIteration(task, c, fpop, xb, fxb, **dparams)[source]

Core function of EvolutionStrategyML algorithm.

Parameters
  • task (Task) – Optimization task.

  • c (numpy.ndarray) – Current population.

  • fpop (numpy.ndarray) – Current population fitness/function values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individuals fitness/function value.

  • Dict[str (**dparams) – Additional arguments.

  • Any] – Additional arguments.

Returns

  1. New population.

  2. New populations fitness/function values.

  3. New global best solution.

  4. New global best solutions fitness/objective value.

  5. Additional arguments.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

class NiaPy.algorithms.basic.EvolutionStrategyMp1(**kwargs)[source]

Bases: NiaPy.algorithms.basic.es.EvolutionStrategy1p1

Implementation of (mu + 1) evolution strategy algorithm. Algorithm creates mu mutants but into new generation goes only one individual.

Algorithm:

(\(\mu + 1\)) Evolution Strategy Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

Reference paper:

Variables

Name (List[str]) – List of strings representing algorithm names.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['EvolutionStrategyMp1', 'EvolutionStrategy(mu+1)', 'ES(m+1)']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

setParameters(**kwargs)[source]

Set core parameters of EvolutionStrategy(mu+1) algorithm.

Parameters

**kwargs (Dict[str, Any]) –

class NiaPy.algorithms.basic.EvolutionStrategyMpL(**kwargs)[source]

Bases: NiaPy.algorithms.basic.es.EvolutionStrategy1p1

Implementation of (mu + lambda) evolution strategy algorithm. Mulation creates lambda individual. Lambda individual compete with mu individuals for survival, so only mu individual go to new generation.

Algorithm:

(\(\mu + \lambda\)) Evolution Strategy Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

Reference paper:

Variables
  • Name (List[str]) – List of strings representing algorithm names

  • lam (int) – TODO

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['EvolutionStrategyMpL', 'EvolutionStrategy(mu+lambda)', 'ES(m+l)']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

changeCount(c, cn)[source]

Update number of successful mutations for population.

Parameters
  • c (numpy.ndarray[Individual]) – Current population.

  • cn (numpy.ndarray[Individual]) – New population.

Returns

Number of successful mutations.

Return type

int

initPopulation(task)[source]

Initialize starting population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized populaiton.

  2. Initialized populations function/fitness values.

  3. Additional arguments:
    • ki (int): Number of successful mutations.

Return type

Tuple[numpy.ndarray[Individual], numpy.ndarray[float], Dict[str, Any]]

See also

  • NiaPy.algorithms.algorithm.Algorithm.initPopulation()

mutateRand(pop, task)[source]

Mutate random individual form population.

Parameters
  • pop (numpy.ndarray[Individual]) – Current population.

  • task (Task) – Optimization task.

Returns

Random individual from population that was mutated.

Return type

numpy.ndarray

runIteration(task, c, fpop, xb, fxb, ki, **dparams)[source]

Core function of EvolutionStrategyMpL algorithm.

Parameters
  • task (Task) – Optimization task.

  • c (numpy.ndarray) – Current population.

  • fpop (numpy.ndarray) – Current populations fitness/function values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individuals fitness/function value.

  • ki (int) – Number of successful mutations.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New populations function/fitness values.

  3. New global best solution.

  4. New global best solutions fitness/objective value.

  5. Additional arguments:
    • ki (int): Number of successful mutations.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(lam=45, **ukwargs)[source]

Set the arguments of an algorithm.

Parameters

lam (int) – Number of new individual generated by mutation.

See also

  • NiaPy.algorithms.basic.es.EvolutionStrategy1p1.setParameters()

static typeParameters()[source]

TODO.

Returns

  • lam (Callable[[int], bool]): TODO.

Return type

Dict[str, Any]

updateRho(pop, k)[source]

Update standard deviation for population.

Parameters
  • pop (numpy.ndarray[Individual]) – Current population.

  • k (int) – Number of successful mutations.

class NiaPy.algorithms.basic.FireflyAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Firefly algorithm.

Algorithm:

Firefly algorithm

Date:

2016

Authors:

Iztok Fister Jr, Iztok Fister and Klemen Berkovič

License:

MIT

Reference paper:

Fister, I., Fister Jr, I., Yang, X. S., & Brest, J. (2013). A comprehensive review of firefly algorithms. Swarm and Evolutionary Computation, 13, 34-46.

Variables
  • Name (List[str]) – List of strings representing algorithm name.

  • alpha (float) – Alpha parameter.

  • betamin (float) – Betamin parameter.

  • gamma (flaot) – Gamma parameter.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['FireflyAlgorithm', 'FA']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

alpha_new(a, alpha)[source]

Optionally recalculate the new alpha value.

Parameters
Returns

New value of parameter alpha.

Return type

float

initPopulation(task)[source]

Initialize the starting population.

Parameters

task (Task) – Optimization task

Returns

  1. New population.

  2. New population fitness/function values.

  3. Additional arguments:
    • alpha (float): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

move_ffa(i, Fireflies, Intensity, oFireflies, alpha, task)[source]

Move fireflies.

Parameters
  • i (int) – Index of current individual.

  • Fireflies (numpy.ndarray) –

  • Intensity (numpy.ndarray) –

  • oFireflies (numpy.ndarray) –

  • alpha (float) –

  • task (Task) – Optimization task.

Returns

  1. New individual

  2. True if individual was moved, False if individual was not moved

Return type

Tuple[numpy.ndarray, bool]

runIteration(task, Fireflies, Intensity, xb, fxb, alpha, **dparams)[source]

Core function of Firefly Algorithm.

Parameters
  • task (Task) – Optimization task.

  • Fireflies (numpy.ndarray) – Current population.

  • Intensity (numpy.ndarray) – Current population function/fitness values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individual fitness/function value.

  • alpha (float) – TODO.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New population fitness/function values.

  3. New global best solution

  4. New global best solutions fitness/objective value

  5. Additional arguments:
    • alpha (float): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=20, alpha=1, betamin=1, gamma=2, **ukwargs)[source]

Set the parameters of the algorithm.

Parameters
  • NP (Optional[int]) – Population size.

  • alpha (Optional[float]) – Alpha parameter.

  • betamin (Optional[float]) – Betamin parameter.

  • gamma (Optional[flaot]) – Gamma parameter.

  • ukwargs (Dict[str, Any]) – Additional arguments.

static typeParameters()[source]

TODO.

Returns

  • alpha (Callable[[Union[float, int]], bool]): TODO.

  • betamin (Callable[[Union[float, int]], bool]): TODO.

  • gamma (Callable[[Union[float, int]], bool]): TODO.

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.FireworksAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of fireworks algorithm.

Algorithm:

Fireworks Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.springer.com/gp/book/9783662463529

Reference paper:

Tan, Ying. “Fireworks algorithm.” Heidelberg, Germany: Springer 10 (2015): 978-3

Variables

Name (List[str]) – List of stirngs representing algorithm names.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

ExplodeSpark(x, A, task)[source]

Explode a spark.

Parameters
  • x (numpy.ndarray) – Individuals creating spark.

  • A (numpy.ndarray) – Amplitude of spark.

  • task (Task) – Optimization task.

Returns

Sparks exploded in with specified amplitude.

Return type

numpy.ndarray

ExplosionAmplitude(x_f, xb_f, A, As)[source]

Calculate explosion amplitude.

Parameters
  • x_f (float) – Individuals function/fitness value.

  • xb_f (float) – Best individuals function/fitness value.

  • A (numpy.ndarray) – Amplitudes.

  • () (As) –

Returns

TODO.

Return type

numpy.ndarray

GaussianSpark(x, task)[source]

Create gaussian spark.

Parameters
  • x (numpy.ndarray) – Individual creating a spark.

  • task (Task) – Optimization task.

Returns

Spark exploded based on gaussian amplitude.

Return type

numpy.ndarray

Mapping(x, task)[source]

Fix value to bounds..

Parameters
  • x (numpy.ndarray) – Individual to fix.

  • task (Task) – Optimization task.

Returns

Individual in search range.

Return type

numpy.ndarray

Name = ['FireworksAlgorithm', 'FWA']
NextGeneration(FW, FW_f, FWn, task)[source]

Generate new generation of individuals.

Parameters
  • FW (numpy.ndarray) – Current population.

  • FW_f (numpy.ndarray[float]) – Currents population fitness/function values.

  • FWn (numpy.ndarray) – New population.

  • task (Task) – Optimization task.

Returns

  1. New population.

  2. New populations fitness/function values.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float]]

R(x, FW)[source]

Calculate ranges.

Parameters
  • x (numpy.ndarray) – Individual in population.

  • FW (numpy.ndarray) – Current population.

Returns

Ranges values.

Return type

numpy,ndarray[float]

SparsksNo(x_f, xw_f, Ss)[source]

Calculate number of sparks based on function value of individual.

Parameters
  • x_f (float) – Individuals function/fitness value.

  • xw_f (float) – Worst individual function/fitness value.

  • () (Ss) – TODO

Returns

Number of sparks that individual will create.

Return type

int

static algorithmInfo()[source]

Get default information of algorithm.

Returns

Basic information.

Return type

str

initAmplitude(task)[source]

Initialize amplitudes for dimensions.

Parameters

task (Task) – Optimization task.

Returns

Starting amplitudes.

Return type

numpy.ndarray[float]

initPopulation(task)[source]

Initialize starting population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized population.

  2. Initialized populations function/fitness values.

  3. Additional arguments:
    • Ah (numpy.ndarray): Initialized amplitudes.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

See also

  • NiaPy.algorithms.algorithm.Algorithm.initPopulation()

p(r, Rs)[source]

Calculate p.

Parameters
  • r (float) – Range of individual.

  • Rs (float) – Sum of ranges.

Returns

p value.

Return type

float

runIteration(task, FW, FW_f, xb, fxb, Ah, **dparams)[source]

Core function of Fireworks algorithm.

Parameters
  • task (Task) – Optimization task.

  • FW (numpy.ndarray) – Current population.

  • FW_f (numpy.ndarray[float]) – Current populations function/fitness values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individuals fitness/function value.

  • Ah (numpy.ndarray) – Current amplitudes.

  • **dparams (Dict[str, Any) – Additional arguments

Returns

  1. Initialized population.

  2. Initialized populations function/fitness values.

  3. New global best solution.

  4. New global best solutions fitness/objective value.

  5. Additional arguments:
    • Ah (numpy.ndarray): Initialized amplitudes.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(N=40, m=40, a=1, b=2, A=40, epsilon=1e-31, **ukwargs)[source]

Set the arguments of an algorithm.

Parameters
  • N (int) – Number of Fireworks

  • m (int) – Number of sparks

  • a (int) – Limitation of sparks

  • b (int) – Limitation of sparks

  • A (float) –

  • epsilon (float) – Small number for non 0 devision

static typeParameters()[source]

Return functions for checking values of parameters.

Returns

  • NP (Callable[[int], bool]): Check if number of individuals is \(\in [0, \infty]\).

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.FishSchoolSearch(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Fish School Search algorithm.

Algorithm:

Fish School Search algorithm

Date:

2019

Authors:

Clodomir Santana Jr, Elliackin Figueredo, Mariana Maceds, Pedro Santos. Ported to NiaPy with small changes by Kristian Järvenpää (2018). Ported to the NiaPy 2.0 by Klemen Berkovič (2019).

License:

MIT

Reference paper:

Bastos Filho, Lima Neto, Lins, D. O. Nascimento and P. Lima, “A novel search algorithm based on fish school behavior,” in 2008 IEEE International Conference on Systems, Man and Cybernetics, Oct 2008, pp. 2646–2651.

Variables
  • Name (List[str]) – List of strings representing algorithm name.

  • SI_init (int) – Length of initial individual step.

  • SI_final (int) – Length of final individual step.

  • SV_init (int) – Length of initial volatile step.

  • SV_final (int) – Length of final volatile step.

  • min_w (float) – Minimum weight of a fish.

  • w_scale (float) – Maximum weight of a fish.

See also

  • NiaPy.algorithms.algorithm.Algorithm

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['FSS', 'FishSchoolSearch']
static algorithmInfo()[source]

Get default information of algorithm.

Returns

Basic information.

Return type

str

calculate_barycenter(school, task)[source]

Calculate barycenter of fish school.

Parameters
  • school (numpy.ndarray) – Current school fish.

  • task (Task) – Optimization task.

Returns

TODO.

Return type

numpy.ndarray

collective_instinctive_movement(school, task)[source]

Perform collective instinctive movement.

Parameters
  • school (numpy.ndarray) – Current population.

  • task (Task) – Optmization task.

Returns

New populaiton

Return type

numpy.ndarray

collective_volitive_movement(school, curr_step_volitive, prev_weight_school, curr_weight_school, xb, fxb, task)[source]

Perform collective volitive movement.

Parameters
  • school (numpy.ndarray) –

  • curr_step_volitive

  • prev_weight_school

  • curr_weight_school

  • xb (numpy.ndarray) – Global best solution.

  • fxb (float) – Global best solutions fitness/objective value.

  • task (Task) – Optimization task.

Returns

New population.

Return type

Tuple[numpy.ndarray, numpy.ndarray, float]

feeding(school)[source]

Feed all fishes.

Parameters

school (numpy.ndarray) – Current school fish population.

Returns

New school fish population.

Return type

numpy.ndarray

gen_weight()[source]

Get initial weight for fish.

Returns

Weight for fish.

Return type

float

generate_uniform_coordinates(task)[source]

Return Numpy array with uniform distribution.

Parameters

task (Task) – Optimization task.

Returns

Array with uniform distribution.

Return type

numpy.ndarray

getParameters()[source]

Get algorithm parameters.

Returns

TODO.

Return type

Dict[str, Any]

individual_movement(school, curr_step_individual, xb, fxb, task)[source]

Perform individual movement for each fish.

Parameters
  • school (numpy.ndarray) – School fish population.

  • curr_step_individual (numpy.ndarray) – TODO

  • xb (numpy.ndarray) – Global best solution.

  • fxb (float) – Global best solutions fitness/objecive value.

  • task (Task) – Optimization task.

Returns

  1. New school of fishes.

Return type

Tuple[numpy.ndarray, numpy.ndarray, float]

initPopulation(task)[source]

Initialize the school.

Parameters

task (Task) – Optimization task.

Returns

TODO.

Return type

Tuple[numpy.ndarray, numpy.ndarray, dict]

init_fish(pos, task)[source]

Create a new fish to a given position.

Parameters
  • pos

  • task (Task) –

Returns:

init_school(task)[source]

Initialize fish school with uniform distribution.

max_delta_cost(school)[source]

Find maximum delta cost - return 0 if none of the fishes moved.

Parameters

school (numpy.ndarray) –

Returns:

runIteration(task, school, fschool, xb, fxb, curr_step_individual, curr_step_volitive, curr_weight_school, prev_weight_school, **dparams)[source]

Core function of algorithm.

Parameters
  • task (Task) –

  • school (numpy.ndarray) –

  • fschool (numpy.ndarray) –

  • best_fish (numpy.ndarray) –

  • fxb (float) –

  • curr_step_individual

  • curr_step_volitive

  • curr_weight_school

  • prev_weight_school

  • **dparams

Returns

TODO.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, dict]

setParameters(NP=25, SI_init=3, SI_final=10, SV_init=3, SV_final=13, min_w=0.3, w_scale=0.7, **ukwargs)[source]

Set core arguments of FishSchoolSearch algorithm.

Parameters
  • NP (Optional[int]) – Number of fishes in school.

  • SI_init (Optional[int]) – Length of initial individual step.

  • SI_final (Optional[int]) – Length of final individual step.

  • SV_init (Optional[int]) – Length of initial volatile step.

  • SV_final (Optional[int]) – Length of final volatile step.

  • min_w (Optional[float]) – Minimum weight of a fish.

  • w_scale (Optional[float]) – Maximum weight of a fish.

total_school_weight(school, prev_weight_school, curr_weight_school)[source]

Calculate and update current weight of fish school.

Parameters
  • school (numpy.ndarray) –

  • prev_weight_school (numpy.ndarray) –

  • curr_weight_school (numpy.ndarray) –

Returns

TODO.

Return type

Tuple[numpy.ndarray, numpy.ndarray]

static typeParameters()[source]

Return functions for checking values of parameters.

Returns

  • NP (Callable[[int], bool]): Check if number of individuals is \(\in [0, \infty]\).

Return type

Dict[str, Callable]

update_steps(task)[source]

Update step length for individual and volatile steps.

Parameters

task (Task) – Optimization task

Returns

TODO.

Return type

Tuple[numpy.ndarray, numpy.ndarray]

class NiaPy.algorithms.basic.FlowerPollinationAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Flower Pollination algorithm.

Algorithm:

Flower Pollination algorithm

Date:

2018

Authors:

Dusan Fister, Iztok Fister Jr. and Klemen Berkovič

License:

MIT

Reference paper:

Yang, Xin-She. “Flower pollination algorithm for global optimization. International conference on unconventional computing and natural computation. Springer, Berlin, Heidelberg, 2012.

References URL:

Implementation is based on the following MATLAB code: https://www.mathworks.com/matlabcentral/fileexchange/45112-flower-pollination-algorithm?requestedDomain=true

Variables
  • Name (List[str]) – List of strings representing algorithm names.

  • p (float) – probability switch.

  • beta (float) – Shape of the gamma distribution (should be greater than zero).

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['FlowerPollinationAlgorithm', 'FPA']
static algorithmInfo()[source]

Get default information of algorithm.

Returns

Basic information.

Return type

str

initPopulation(task)[source]

Initialize starting population of optimization algorithm.

Parameters

task (Task) – Optimization task.

Returns

  1. New population.

  2. New population fitness values.

  3. Additional arguments.

Return type

Tuple[numpy.ndarray, numpy.ndarray, Dict[str, Any]]

levy(D)[source]

Levy function.

Returns

Next Levy number.

Return type

float

repair(x, task)[source]

Repair solution to search space.

Parameters
  • x (numpy.ndarray) – Solution to fix.

  • task (Task) – Optimization task.

Returns

fixed solution.

Return type

numpy.ndarray

runIteration(task, Sol, Sol_f, xb, fxb, S, **dparams)[source]

Core function of FlowerPollinationAlgorithm algorithm.

Parameters
  • task (Task) – Optimization task.

  • Sol (numpy.ndarray) – Current population.

  • Sol_f (numpy.ndarray) – Current population fitness/function values.

  • xb (numpy.ndarray) – Global best solution.

  • fxb (float) – Global best solution function/fitness value.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New populations fitness/function values.

  3. New global best solution.

  4. New global best solution fitness/objective value.

  5. Additional arguments.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=25, p=0.35, beta=1.5, **ukwargs)[source]

Set core parameters of FlowerPollinationAlgorithm algorithm.

Parameters
  • NP (int) – Population size.

  • p (float) – Probability switch.

  • beta (float) – Shape of the gamma distribution (should be greater than zero).

static typeParameters()[source]

TODO.

Returns

  • p (function): TODO

  • beta (function): TODO

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.ForestOptimizationAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Forest Optimization Algorithm.

Algorithm:

Forest Optimization Algorithm

Date:

2019

Authors:

Luka Pečnik

License:

MIT

Reference paper:

Manizheh Ghaemi, Mohammad-Reza Feizi-Derakhshi, Forest Optimization Algorithm, Expert Systems with Applications, Volume 41, Issue 15, 2014, Pages 6676-6687, ISSN 0957-4174, https://doi.org/10.1016/j.eswa.2014.05.009.

References URL:

Implementation is based on the following MATLAB code: https://github.com/cominsys/FOA

Variables
  • Name (List[str]) – List of strings representing algorithm name.

  • lt (int) – Life time of trees parameter.

  • al (int) – Area limit parameter.

  • lsc (int) – Local seeding changes parameter.

  • gsc (int) – Global seeding changes parameter.

  • tr (float) – Transfer rate parameter.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['ForestOptimizationAlgorithm', 'FOA']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

getParameters()[source]

Get parameters values of the algorithm.

Returns

TODO.

Return type

Dict[str, Any]

globalSeeding(task, candidates, size)[source]

Global optimum search stage that should prevent getting stuck in a local optimum.

Parameters
  • task (Task) – Optimization task.

  • candidates (numpy.ndarray) – Candidate population for global seeding.

  • size (int) – Number of trees to produce.

Returns

Resulting trees.

Return type

numpy.ndarray

initPopulation(task)[source]

Initialize the starting population.

Parameters

task (Task) – Optimization task

Returns

  1. New population.

  2. New population fitness/function values.

  3. Additional arguments:
    • age (numpy.ndarray[int32]): Age of trees.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

localSeeding(task, trees)[source]

Local optimum search stage.

Parameters
  • task (Task) – Optimization task.

  • trees (numpy.ndarray) – Zero age trees for local seeding.

Returns

Resulting zero age trees.

Return type

numpy.ndarray

removeLifeTimeExceeded(trees, candidates, age)[source]

Remove dead trees.

Parameters
  • trees (numpy.ndarray) – Population to test.

  • candidates (numpy.ndarray) – Candidate population array to be updated.

  • age (numpy.ndarray[int32]) – Age of trees.

Returns

  1. Alive trees.

  2. New candidate population.

  3. Age of trees.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray[int32]]

runIteration(task, Trees, Evaluations, xb, fxb, age, **dparams)[source]

Core function of Forest Optimization Algorithm.

Parameters
  • task (Task) – Optimization task.

  • Trees (numpy.ndarray) – Current population.

  • Evaluations (numpy.ndarray[float]) – Current population function/fitness values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individual fitness/function value.

  • age (numpy.ndarray[int32]) – Age of trees.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New population fitness/function values.

  3. Additional arguments:
    • age (numpy.ndarray[int32]): Age of trees.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

setParameters(NP=10, lt=3, al=10, lsc=1, gsc=1, tr=0.3, **ukwargs)[source]

Set the parameters of the algorithm.

Parameters
  • NP (Optional[int]) – Population size.

  • lt (Optional[int]) – Life time parameter.

  • al (Optional[int]) – Area limit parameter.

  • lsc (Optional[int]) – Local seeding changes parameter.

  • gsc (Optional[int]) – Global seeding changes parameter.

  • tr (Optional[float]) – Transfer rate parameter.

  • ukwargs (Dict[str, Any]) – Additional arguments.

survivalOfTheFittest(task, trees, candidates, age)[source]

Evaluate and filter current population.

Parameters
  • task (Task) – Optimization task.

  • trees (numpy.ndarray) – Population to evaluate.

  • candidates (numpy.ndarray) – Candidate population array to be updated.

  • age (numpy.ndarray[int32]) – Age of trees.

Returns

  1. Trees sorted by fitness value.

  2. Updated candidate population.

  3. Population fitness values.

  4. Age of trees

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray[float], numpy.ndarray[int32]]

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • lt (Callable[[int], bool]): Checks if life time parameter has a proper value.

  • al (Callable[[int], bool]): Checks if area limit parameter has a proper value.

  • lsc (Callable[[int], bool]): Checks if local seeding changes parameter has a proper value.

  • gsc (Callable[[int], bool]): Checks if global seeding changes parameter has a proper value.

  • tr (Callable[[float], bool]): Checks if transfer rate parameter has a proper value.

Return type

Dict[str, Callable]

See also

  • NiaPy.algorithms.algorithm.Algorithm.typeParameters()

class NiaPy.algorithms.basic.GeneticAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Genetic Algorithm.

Algorithm:

Genetic algorithm

Date:

2018

Author:

Klemen Berkovič

Reference paper:

Goldberg, David (1989). Genetic Algorithms in Search, Optimization and Machine Learning. Reading, MA: Addison-Wesley Professional.

License:

MIT

Variables

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['GeneticAlgorithm', 'GA']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

runIteration(task, pop, fpop, xb, fxb, **dparams)[source]

Core function of GeneticAlgorithm algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population.

  • fpop (numpy.ndarray) – Current populations fitness/function values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individuals function/fitness value.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New populations function/fitness values.

  3. New global best solution

  4. New global best solutions fitness/objective value

  5. Additional arguments.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=25, Ts=5, Mr=0.25, Cr=0.25, Selection=<function TournamentSelection>, Crossover=<function UniformCrossover>, Mutation=<function UniformMutation>, **ukwargs)[source]

Set the parameters of the algorithm.

Parameters
  • NP (Optional[int]) – Population size.

  • Ts (Optional[int]) – Tournament selection.

  • Mr (Optional[int]) – Mutation rate.

  • Cr (Optional[float]) – Crossover rate.

  • Selection (Optional[Callable[[numpy.ndarray[Individual], int, int, Individual, mtrand.RandomState], Individual]]) – Selection operator.

  • Crossover (Optional[Callable[[numpy.ndarray[Individual], int, float, mtrand.RandomState], Individual]]) – Crossover operator.

  • Mutation (Optional[Callable[[numpy.ndarray[Individual], int, float, Task, mtrand.RandomState], Individual]]) – Mutation operator.

See also

  • NiaPy.algorithms.Algorithm.setParameters()

  • Selection:
    • NiaPy.algorithms.basic.TournamentSelection()

    • NiaPy.algorithms.basic.RouletteSelection()

  • Crossover:
    • NiaPy.algorithms.basic.UniformCrossover()

    • NiaPy.algorithms.basic.TwoPointCrossover()

    • NiaPy.algorithms.basic.MultiPointCrossover()

    • NiaPy.algorithms.basic.CrossoverUros()

  • Mutations:
    • NiaPy.algorithms.basic.UniformMutation()

    • NiaPy.algorithms.basic.CreepMutation()

    • NiaPy.algorithms.basic.MutationUros()

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • Ts (Callable[[int], bool]): Tournament size.

  • Mr (Callable[[float], bool]): Probability of mutation.

  • Cr (Callable[[float], bool]): Probability of crossover.

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.GlowwormSwarmOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of glowworm swarm optimization.

Algorithm:

Glowworm Swarm Optimization Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.springer.com/gp/book/9783319515946

Reference paper:

Kaipa, Krishnanand N., and Debasish Ghose. Glowworm swarm optimization: theory, algorithms, and applications. Vol. 698. Springer, 2017.

Variables
  • Name (List[str]) – List of strings represeinting algorithm name.

  • l0 (float) – Initial luciferin quantity for each glowworm.

  • nt (float) –

  • rs (float) – Maximum sensing range.

  • rho (float) – Luciferin decay constant.

  • gamma (float) – Luciferin enhancement constant.

  • beta (float) –

  • s (float) –

  • Distance (Callable[[numpy.ndarray, numpy.ndarray], float]]) – Measure distance between two individuals.

See also

  • NiaPy.algorithms.algorithm.Algorithm

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['GlowwormSwarmOptimization', 'GSO']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information.

Return type

str

calcLuciferin(L, GS_f)[source]

TODO.

Parameters
  • L

  • GS_f

Returns:

getNeighbors(i, r, GS, L)[source]

Get neighbours of glowworm.

Parameters
  • i (int) – Index of glowworm.

  • r (float) – Neighborhood distance.

  • GS (numpy.ndarray) –

  • L (numpy.ndarray[float]) – Luciferin value of glowworm.

Returns

Indexes of neighborhood glowworms.

Return type

numpy.ndarray[int]

getParameters()[source]

Get algorithms parameters values.

Returns

TODO.

Return type

Dict[str, Any]

initPopulation(task)[source]

Initialize population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized population of glowwarms.

  2. Initialized populations function/fitness values.

  3. Additional arguments:
    • L (numpy.ndarray): TODO.

    • R (numpy.ndarray): TODO.

    • rs (numpy.ndarray): TODO.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

moveSelect(pb, i)[source]

TODO.

Parameters
  • pb

  • i

Returns:

probabilityes(i, N, L)[source]

Calculate probabilities for glowworm to movement.

Parameters
  • i (int) – Index of glowworm to search for probable movement.

  • N (numpy.ndarray[float]) –

  • L (numpy.ndarray[float]) –

Returns

Probabilities for each glowworm in swarm.

Return type

numpy.ndarray[float]

rangeUpdate(R, N, rs)[source]

TODO.

Parameters
  • R

  • N

  • rs

Returns:

runIteration(task, GS, GS_f, xb, fxb, L, R, rs, **dparams)[source]

Core function of GlowwormSwarmOptimization algorithm.

Parameters
  • task (Task) – Optimization taks.

  • GS (numpy.ndarray) – Current population.

  • GS_f (numpy.ndarray) – Current populations fitness/function values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individuals function/fitness value.

  • L (numpy.ndarray) –

  • R (numpy.ndarray) –

  • rs (numpy.ndarray) –

  • Dict[str (**dparams) – Additional arguments.

  • Any] – Additional arguments.

Returns

  1. Initialized population of glowwarms.

  2. Initialized populations function/fitness values.

  3. New global best solution

  4. New global best sloutions fitness/objective value.

  5. Additional arguments:
    • L (numpy.ndarray): TODO.

    • R (numpy.ndarray): TODO.

    • rs (numpy.ndarray): TODO.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(n=25, l0=5, nt=5, rho=0.4, gamma=0.6, beta=0.08, s=0.03, Distance=<function euclidean>, **ukwargs)[source]

Set the arguments of an algorithm.

Parameters
  • n (Optional[int]) – Number of glowworms in population.

  • l0 (Optional[float]) – Initial luciferin quantity for each glowworm.

  • nt (Optional[float]) –

  • rs (Optional]float]) – Maximum sensing range.

  • rho (Optional[float]) – Luciferin decay constant.

  • gamma (Optional[float]) – Luciferin enhancement constant.

  • beta (Optional[float]) –

  • s (Optional[float]) –

  • Distance (Optional[Callable[[numpy.ndarray, numpy.ndarray], float]]]) – Measure distance between two individuals.

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • n (Callable[[int], bool])

  • l0 (Callable[[Union[float, int]], bool])

  • nt (Callable[[Union[float, int]], bool])

  • rho (Callable[[Union[float, int]], bool])

  • gamma (Callable[[float], bool])

  • beta (Callable[[float], bool])

  • s (Callable[[float], bool])

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.GlowwormSwarmOptimizationV1(**kwargs)[source]

Bases: NiaPy.algorithms.basic.gso.GlowwormSwarmOptimization

Implementation of glowwarm swarm optimization.

Algorithm:

Glowwarm Swarm Optimization Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.springer.com/gp/book/9783319515946

Reference paper:

Kaipa, Krishnanand N., and Debasish Ghose. Glowworm swarm optimization: theory, algorithms, and applications. Vol. 698. Springer, 2017.

Variables
  • Name (List[str]) – List of strings representing algorithm names.

  • alpha (float) –

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['GlowwormSwarmOptimizationV1', 'GSOv1']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information.

Return type

str

calcLuciferin(L, GS_f)[source]

TODO.

Parameters
  • L

  • GS_f

Returns:

rangeUpdate(R, N, rs)[source]

TODO.

Parameters
  • R

  • N

  • rs

Returns:

setParameters(**kwargs)[source]

Set default parameters of the algorithm.

Parameters

**kwargs (dict) – Additional arguments.

class NiaPy.algorithms.basic.GlowwormSwarmOptimizationV2(**kwargs)[source]

Bases: NiaPy.algorithms.basic.gso.GlowwormSwarmOptimization

Implementation of glowwarm swarm optimization.

Algorithm:

Glowwarm Swarm Optimization Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.springer.com/gp/book/9783319515946

Reference paper:

Kaipa, Krishnanand N., and Debasish Ghose. Glowworm swarm optimization: theory, algorithms, and applications. Vol. 698. Springer, 2017.

Variables
  • Name (List[str]) – List of strings representing algorithm names.

  • alpha (float) –

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['GlowwormSwarmOptimizationV2', 'GSOv2']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information.

Return type

str

rangeUpdate(P, N, rs)[source]

TODO.

Parameters
  • P

  • N

  • rs

Returns

TODO

Return type

float

setParameters(alpha=0.2, **kwargs)[source]

Set core parameters for GlowwormSwarmOptimizationV2 algorithm.

Parameters
  • alpha (Optional[float]) –

  • **kwargs (Dict[str, Any]) – Additional arguments.

class NiaPy.algorithms.basic.GlowwormSwarmOptimizationV3(**kwargs)[source]

Bases: NiaPy.algorithms.basic.gso.GlowwormSwarmOptimization

Implementation of glowwarm swarm optimization.

Algorithm:

Glowwarm Swarm Optimization Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.springer.com/gp/book/9783319515946

Reference paper:

Kaipa, Krishnanand N., and Debasish Ghose. Glowworm swarm optimization: theory, algorithms, and applications. Vol. 698. Springer, 2017.

Variables
  • Name (List[str]) – List of strings representing algorithm names.

  • beta1 (float) –

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['GlowwormSwarmOptimizationV3', 'GSOv3']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information.

Return type

str

rangeUpdate(R, N, rs)[source]

TODO.

Parameters
  • R

  • N

  • rs

Returns:

setParameters(beta1=0.2, **kwargs)[source]

Set core parameters for GlowwormSwarmOptimizationV3 algorithm.

Parameters
  • beta1 (Optional[float]) –

  • **kwargs (Dict[str, Any]) – Additional arguments.

class NiaPy.algorithms.basic.GravitationalSearchAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Gravitational Search Algorithm.

Algorithm:

Gravitational Search Algorithm

Date:

2018

Author:

Klemen Berkoivč

License:

MIT

Reference URL:

https://doi.org/10.1016/j.ins.2009.03.004

Reference paper:

Esmat Rashedi, Hossein Nezamabadi-pour, Saeid Saryazdi, GSA: A Gravitational Search Algorithm, Information Sciences, Volume 179, Issue 13, 2009, Pages 2232-2248, ISSN 0020-0255

Variables

Name (List[str]) – List of strings representing algorithm name.

See also

  • NiaPy.algorithms.algorithm.Algorithm

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

G(t)[source]

TODO.

Parameters

t (int) – TODO

Returns

TODO

Return type

float

Name = ['GravitationalSearchAlgorithm', 'GSA']
static algorithmInfo()[source]

Get algorithm information.

Returns

Algorithm information.

Return type

str

d(x, y, ln=2)[source]

TODO.

Parameters
  • x

  • y

  • ln

Returns

TODO

getParameters()[source]

Get algorithm parameters values.

Returns

TODO.

Return type

Dict[str, Any]

See also

  • NiaPy.algorithms.algorithm.Algorithm.getParameters()

initPopulation(task)[source]

Initialize staring population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized population.

  2. Initialized populations fitness/function values.

  3. Additional arguments:
    • v (numpy.ndarray[float]): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

See also

  • NiaPy.algorithms.algorithm.Algorithm.initPopulation()

runIteration(task, X, X_f, xb, fxb, v, **dparams)[source]

Core function of GravitationalSearchAlgorithm algorithm.

Parameters
  • task (Task) – Optimization task.

  • X (numpy.ndarray) – Current population.

  • X_f (numpy.ndarray) – Current populations fitness/function values.

  • xb (numpy.ndarray) – Global best solution.

  • fxb (float) – Global best fitness/function value.

  • v (numpy.ndarray) – TODO

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New populations fitness/function values.

  3. New global best solution

  4. New global best solutions fitness/objective value

  5. Additional arguments:
    • v (numpy.ndarray): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=40, G_0=2.467, epsilon=1e-17, **ukwargs)[source]

Set the algorithm parameters.

Parameters
  • G_0 (float) – Starting gravitational constant.

  • epsilon (float) – TODO.

See also

  • NiaPy.algorithms.algorithm.Algorithm.setParameters()

static typeParameters()[source]

TODO.

Returns

  • G_0 (Callable[[Union[int, float]], bool]): TODO

  • epsilon (Callable[[float], bool]): TODO

Return type

Dict[str, Callable]

See also

  • NiaPy.algorithms.algorithm.Algorithm.typeParameters()

class NiaPy.algorithms.basic.GreyWolfOptimizer(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Grey wolf optimizer.

Algorithm:

Grey wolf optimizer

Date:

2018

Author:

Iztok Fister Jr. and Klemen Berkovič

License:

MIT

Reference paper:
  • Mirjalili, Seyedali, Seyed Mohammad Mirjalili, and Andrew Lewis. “Grey wolf optimizer.” Advances in engineering software 69 (2014): 46-61.

  • Grey Wolf Optimizer (GWO) source code version 1.0 (MATLAB) from MathWorks

Variables

Name (List[str]) – List of strings representing algorithm names.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['GreyWolfOptimizer', 'GWO']
static algorithmInfo()[source]

Get algorithm information.

Returns

Algorithm information.

Return type

str

initPopulation(task)[source]

Initialize population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized population.

  2. Initialized populations fitness/function values.

  3. Additional arguments:
    • A (): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray, Dict[str, Any]]

runIteration(task, pop, fpop, xb, fxb, A, A_f, B, B_f, D, D_f, **dparams)[source]

Core funciton of GreyWolfOptimizer algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population.

  • fpop (numpy.ndarray) – Current populations function/fitness values.

  • xb (numpy.ndarray) –

  • fxb (float) –

  • A (numpy.ndarray) –

  • A_f (float) –

  • B (numpy.ndarray) –

  • B_f (float) –

  • D (numpy.ndarray) –

  • D_f (float) –

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population

  2. New population fitness/function values

  3. Additional arguments:
    • A (): TODO

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=25, **ukwargs)[source]

Set the algorithm parameters.

Parameters

NP (int) – Number of individuals in population

static typeParameters()[source]

Return functions for checking values of parameters.

Returns

  • NP (Callable[[int], bool]): Check if number of individuals is \(\in [0, \infty]\).

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.HarmonySearch(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of harmony search algorithm.

Algorithm:

Harmony Search Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://link.springer.com/chapter/10.1007/978-3-642-00185-7_1

Reference paper:

Geem, Z. W., Kim, J. H., & Loganathan, G. V. (2001). A new heuristic optimization algorithm: harmony search. Simulation, 76(2), 60-68.

Variables
  • Name (List[str]) – List of strings representing algorithm names

  • r_accept (float) – Probability of accepting new bandwidth into harmony.

  • r_pa (float) – Probability of accepting random bandwidth into harmony.

  • b_range (float) – Range of bandwidth.

See also

  • NiaPy.algorithms.algorithm.Algorithm

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['HarmonySearch', 'HS']
adjustment(x, task)[source]

Adjust value based on bandwidth.

Parameters
  • x (Union[int, float]) – Current position.

  • task (Task) – Optimization task.

Returns

New position.

Return type

float

static algorithmInfo()[source]

Get basic information about the algorithm.

Returns

Basic information.

Return type

str

bw(task)[source]

Get bandwidth.

Parameters

task (Task) – Optimization task.

Returns

Bandwidth.

Return type

float

getParameters()[source]

Get parameters of the algorithm.

Returns

  • Parameter name (str): Represents a parameter name

  • Value of parameter (Any): Represents the value of the parameter

Return type

Dict[str, Any]

improvize(HM, task)[source]

Create new individual.

Parameters
  • HM (numpy.ndarray) – Current population.

  • task (Task) – Optimization task.

Returns

New individual.

Return type

numpy.ndarray

initPopulation(task)[source]

Initialize first population.

Parameters

task (Task) – Optimization task.

Returns

  1. New harmony/population.

  2. New population fitness/function values.

  3. Additional parameters.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

See also

  • NiaPy.algorithms.algorithm.Algorithm.initPopulation()

runIteration(task, HM, HM_f, xb, fxb, **dparams)[source]

Core function of HarmonySearch algorithm.

Parameters
  • task (Task) – Optimization task.

  • HM (numpy.ndarray) – Current population.

  • HM_f (numpy.ndarray) – Current populations function/fitness values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best fitness/function value.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New harmony/population.

  2. New populations function/fitness values.

  3. New global best solution

  4. New global best solution fitness/objective value

  5. Additional arguments.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(HMS=30, r_accept=0.7, r_pa=0.35, b_range=1.42, **ukwargs)[source]

Set the arguments of the algorithm.

Parameters
  • HMS (Optional[int]) – Number of harmony in the memory.

  • r_accept (Optional[float]) – Probability of accepting new bandwidth to harmony.

  • r_pa (Optional[float]) – Probability of accepting random bandwidth into harmony.

  • b_range (Optional[float]) – Bandwidth range.

See also

  • NiaPy.algorithms.algorithm.Algorithm.setParameters()

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • HMS (Callable[[int], bool])

  • r_accept (Callable[[float], bool])

  • r_pa (Callable[[float], bool])

  • b_range (Callable[[float], bool])

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.HarmonySearchV1(**kwargs)[source]

Bases: NiaPy.algorithms.basic.hs.HarmonySearch

Implementation of harmony search algorithm.

Algorithm:

Harmony Search Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://link.springer.com/chapter/10.1007/978-3-642-00185-7_1

Reference paper:

Yang, Xin-She. “Harmony search as a metaheuristic algorithm.” Music-inspired harmony search algorithm. Springer, Berlin, Heidelberg, 2009. 1-14.

Variables
  • Name (List[str]) – List of strings representing algorithm name.

  • bw_min (float) – Minimal bandwidth.

  • bw_max (float) – Maximal bandwidth.

See also

  • NiaPy.algorithms.basic.hs.HarmonySearch

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['HarmonySearchV1', 'HSv1']
static algorithmInfo()[source]

Get basic information about algorihtm.

Returns

Basic information.

Return type

str

bw(task)[source]

Get new bandwidth.

Parameters

task (Task) – Optimization task.

Returns

New bandwidth.

Return type

float

getParameters()[source]

Get parameters of the algorithm.

Returns

  • Parameter name (str): Represents a parameter name

  • Value of parameter (Any): Represents the value of the parameter

Return type

Dict[str, Any]

setParameters(bw_min=1, bw_max=2, **kwargs)[source]

Set the parameters of the algorithm.

Parameters
  • bw_min (Optional[float]) – Minimal bandwidth

  • bw_max (Optional[float]) – Maximal bandwidth

  • kwargs (Dict[str, Any]) – Additional arguments.

See also

  • NiaPy.algorithms.basic.hs.HarmonySearch.setParameters()

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

Function for testing correctness of parameters.

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.HarrisHawksOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Harris Hawks Optimization algorithm.

Algorithm:

Harris Hawks Optimization

Date:

2020

Authors:

Francisco Jose Solis-Munoz

License:

MIT

Reference paper:

Heidari et al. “Harris hawks optimization: Algorithm and applications”. Future Generation Computer Systems. 2019. Vol. 97. 849-872.

Variables
  • Name (List[str]) – List of strings representing algorithm name.

  • levy (float) – Levy factor.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['HarrisHawksOptimization', 'HHO']
static algorithmInfo()[source]

Get algorithms information.

Returns

Algorithm information.

Return type

str

getParameters()[source]

Get parameters of the algorithm.

Returns

Dict[str, Any]

initPopulation(task, rnd=<module 'numpy.random' from '/home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/numpy/random/__init__.py'>)[source]

Initialize the starting population.

Parameters

task (Task) – Optimization task

Returns

  1. New population.

  2. New population fitness/function values.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

levy_function(dims, step=0.01, rnd=<module 'numpy.random' from '/home/docs/.pyenv/versions/3.6.12/lib/python3.6/site-packages/numpy/random/__init__.py'>)[source]

Calculate levy function.

Parameters
  • dim (int) – Number of dimensions

  • step (float) – Step of the Levy function

Returns

The Levy function evaluation

Return type

float

runIteration(task, Sol, Fitness, xb, fxb, **dparams)[source]

Core function of Harris Hawks Optimization.

Parameters
  • task (Task) – Optimization task.

  • Sol (numpy.ndarray) – Current population

  • Fitness (numpy.ndarray[float]) – Current population fitness/funciton values

  • xb (numpy.ndarray) – Current best individual

  • fxb (float) – Current best individual function/fitness value

  • dparams (Dict[str, Any]) – Additional algorithm arguments

Returns

  1. New population

  2. New population fitness/function vlues

  3. New global best solution

  4. New global best fitness/objective value

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=40, levy=0.01, **ukwargs)[source]

Set the parameters of the algorithm.

Parameters

levy (Optional[float]) – Levy factor.

static typeParameters()[source]

Return dict with where key of dict represents parameter name and values represent checking functions for selected parameter.

Returns

  • levy (Callable[[Union[float, int]], bool]): Levy factor.

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.KrillHerdV1(**kwargs)[source]

Bases: NiaPy.algorithms.basic.kh.KrillHerd

Implementation of krill herd algorithm.

Algorithm:

Krill Herd Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

http://www.sciencedirect.com/science/article/pii/S1007570412002171

Reference paper:

Amir Hossein Gandomi, Amir Hossein Alavi, Krill herd: A new bio-inspired optimization algorithm, Communications in Nonlinear Science and Numerical Simulation, Volume 17, Issue 12, 2012, Pages 4831-4845, ISSN 1007-5704, https://doi.org/10.1016/j.cnsns.2012.05.010.

Variables

Name (List[str]) – List of strings representing algorithm name.

See also

  • :func:NiaPy.algorithms.basic.kh.KrillHerd.KrillHerd`

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['KrillHerdV1', 'KHv1']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

crossover(x, xo, Cr)[source]

Preform a crossover operation on individual.

Parameters
  • x (numpy.ndarray) – Current individual.

  • xo (numpy.ndarray) – New individual.

  • Cr (float) – Crossover probability.

Returns

Crossover individual.

Return type

numpy.ndarray

mutate(x, x_b, Mu)[source]

Mutate individual.

Parameters
  • x (numpy.ndarray) – Current individual.

  • x_b (numpy.ndarray) – Global best individual.

  • Mu (float) – Mutation probability.

Returns

Mutated krill.

Return type

numpy.ndarray

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

Dictionary with testing functions for parameters.

Return type

Dict[str, Callable]

See also

  • :func:NiaPy.algorithms.basic.kh.KrillHerd.typeParameters`

class NiaPy.algorithms.basic.KrillHerdV11(**kwargs)[source]

Bases: NiaPy.algorithms.basic.kh.KrillHerd

Implementation of krill herd algorithm.

Algorithm:

Krill Herd Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

Reference paper:

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Cr(KH_f, KHb_f, KHw_f)[source]

Calculate crossover probability.

Parameters
  • KH_f (float) – Krill/individuals function/fitness value.

  • KHb_f (float) – Best krill/individual function/fitness value.

  • KHw_f (float) – Worst krill/individual function/fitness value.

Returns

Crossover probability.

Return type

float

ElitistSelection(KH, KH_f, KHo, KHo_f)[source]

Select krills/individuals that are better than odl krills.

Parameters
  • KH (numpy.ndarray) – Current herd/population.

  • KH_f (numpy.ndarray[float]) – Current herd/populations function/fitness values

  • KHo (numpy.ndarray) – New herd/population.

  • KHo_f (numpy.ndarray[float]) – New herd/populations function/fitness vales.

Returns

  1. New herd/population.

  2. New herd/populations function/fitness values.

Return type

Tuple[numpy.ndarray, numpy.numpy[float]]

Foraging(KH, KH_f, KHo, KHo_f, W_f, F, KH_wf, KH_bf, x_food, x_food_f, task)[source]

Foraging operator.

Parameters
  • KH (numpy.ndarray) – Current heard/population.

  • KH_f (numpy.ndarray[float]) – Current herd/populations function/fitness values.

  • KHo (numpy.ndarray) – New heard/population.

  • KHo_f (numpy.ndarray[float]) – New heard/population function/fitness values.

  • W_f (numpy.ndarray) – Weights for foraging.

  • () (F) –

  • KH_wf (numpy.ndarray) – Worst krill in herd/population.

  • KH_bf (numpy.ndarray) – Best krill in herd/population.

  • x_food (numpy.ndarray) – Foods position.

  • x_food_f (float) – Foods function/fitness value.

  • task (Task) – Optimization task.

Returns

Return type

numpy.ndarray

Name = ['KrillHerdV11', 'KHv11']
Neighbors(i, KH, KH_f, iw, ib, N, W_n, task)[source]

Neighbors operator.

Parameters
  • i (int) – Index of krill being applied with operator.

  • KH (numpy.ndarray) – Current herd/population.

  • KH_f (numpy.ndarray[float]) – Current herd/populations function/fitness values.

  • iw (int) – Index of worst krill/individual.

  • ib (int) – Index of best krill/individual.

  • () (N) –

  • W_n (numpy.ndarray) – Weights for neighbors operator.

  • task (Task) – Optimization task.

Returns

Return type

numpy.ndarray

initPopulation(task)[source]

Initialize firt herd/population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized herd/population.

  2. Initialized herd/populations function/fitness values.

  3. Additional arguments:
    • KHo (): –

    • KHo_f (): –

    • N (): –

    • F (): –

    • Dt (): –

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

runIteration(task, KH, KH_f, xb, fxb, KHo, KHo_f, N, F, Dt, **dparams)[source]

Core function of KrillHerdV11 algorithm.

Parameters
  • task (Task) – Optimization task.

  • KH (numpy.ndarray) – Current herd/population.

  • KH_f (numpy.ndarray[float]) – Current herd/populations function/fitness values.

  • xb (numpy.ndarray) – Global best krill.

  • fxb (float) – Global best krill function/fitness value.

  • () (Dt) –

  • ()

  • ()

  • ()

  • ()

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New herd/population.

  2. New herd/populations function/fitness values.

  3. Additional arguments:

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

class NiaPy.algorithms.basic.KrillHerdV2(**kwargs)[source]

Bases: NiaPy.algorithms.basic.kh.KrillHerd

Implementation of krill herd algorithm.

Algorithm:

Krill Herd Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

http://www.sciencedirect.com/science/article/pii/S1007570412002171

Reference paper:

Amir Hossein Gandomi, Amir Hossein Alavi, Krill herd: A new bio-inspired optimization algorithm, Communications in Nonlinear Science and Numerical Simulation, Volume 17, Issue 12, 2012, Pages 4831-4845, ISSN 1007-5704, https://doi.org/10.1016/j.cnsns.2012.05.010.

Variables

Name (List[str]) – List of strings representing algorithm name.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['KrillHerdV2', 'KHv2']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

mutate(x, x_b, Mu)[source]

Mutate individual.

Parameters
  • x (numpy.ndarray) – Individual to mutate.

  • x_b (numpy.ndarray) – Global best individual.

  • Mu (float) – Mutation probability.

Returns

Mutated individual.

Return type

numpy.ndarray

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

Dictionary with testing functions for algorithms parameters.

Return type

Dict[str, Callable]

See also

  • :func:NiaPy.algorithms.basic.kh.KrillHerd.typeParameters`

class NiaPy.algorithms.basic.KrillHerdV3(**kwargs)[source]

Bases: NiaPy.algorithms.basic.kh.KrillHerd

Implementation of krill herd algorithm.

Algorithm:

Krill Herd Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

http://www.sciencedirect.com/science/article/pii/S1007570412002171

Reference paper:

Amir Hossein Gandomi, Amir Hossein Alavi, Krill herd: A new bio-inspired optimization algorithm, Communications in Nonlinear Science and Numerical Simulation, Volume 17, Issue 12, 2012, Pages 4831-4845, ISSN 1007-5704, https://doi.org/10.1016/j.cnsns.2012.05.010.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['KrillHerdV3', 'KHv3']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

crossover(x, xo, Cr)[source]

Crossover operator.

Parameters
  • x (numpy.ndarray) – Krill/individual being applied with operator.

  • xo (numpy.ndarray) – Krill/individual being used in operator.

  • Cr (float) – Crossover probability.

Returns

Crossover krill/individual.

Return type

numpy.ndarray

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

Dictionary with testing functions for algorithms parameters.

Return type

Dict[str, Callable]

See also

  • :func:NiaPy.algorithms.basic.kh.KrillHerd.typeParameters`

class NiaPy.algorithms.basic.KrillHerdV4(**kwargs)[source]

Bases: NiaPy.algorithms.basic.kh.KrillHerd

Implementation of krill herd algorithm.

Algorithm:

Krill Herd Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

http://www.sciencedirect.com/science/article/pii/S1007570412002171

Reference paper:

Amir Hossein Gandomi, Amir Hossein Alavi, Krill herd: A new bio-inspired optimization algorithm, Communications in Nonlinear Science and Numerical Simulation, Volume 17, Issue 12, 2012, Pages 4831-4845, ISSN 1007-5704, https://doi.org/10.1016/j.cnsns.2012.05.010.

Variables

Name (List[str]) – List of strings representing algorithm name.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['KrillHerdV4', 'KHv4']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

setParameters(NP=50, N_max=0.01, V_f=0.02, D_max=0.002, C_t=0.93, W_n=0.42, W_f=0.38, d_s=2.63, **ukwargs)[source]

Set algorithm core parameters.

Parameters
  • NP (int) – Number of kills in herd.

  • N_max (Optional[float]) – TODO

  • V_f (Optional[float]) – TODO

  • D_max (Optional[float]) – TODO

  • C_t (Optional[float]) – TODO

  • W_n (Optional[Union[int, float, numpy.ndarray, list]]) – Weights for neighborhood.

  • W_f (Optional[Union[int, float, numpy.ndarray, list]]) – Weights for foraging.

  • d_s (Optional[float]) – TODO

  • **ukwargs (Dict[str, Any]) – Additional arguments.

See also

  • :func:NiaPy.algorithms.basic.kh.KrillHerd.KrillHerd.setParameters`

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

Dictionary with testing functions for parameters.

Return type

Dict[str, Callable]

See also

  • :func:NiaPy.algorithms.basic.kh.KrillHerd.typeParameters`

class NiaPy.algorithms.basic.MonarchButterflyOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Monarch Butterfly Optimization.

Algorithm:

Monarch Butterfly Optimization

Date:

2019

Authors:

Jan Banko

License:

MIT

Reference paper:

Wang, G. G., Deb, S., & Cui, Z. (2019). Monarch butterfly optimization. Neural computing and applications, 31(7), 1995-2014.

Variables
  • Name (List[str]) – List of strings representing algorithm name.

  • PAR (float) – Partition.

  • PER (float) – Period.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['MonarchButterflyOptimization', 'MBO']
adjustingOperator(t, max_t, D, NP1, NP2, Butterflies, best)[source]

Apply the adjusting operator.

Parameters
  • t (int) – Current generation.

  • max_t (int) – Maximum generation.

  • D (int) – Number of dimensions.

  • NP1 (int) – Number of butterflies in Land 1.

  • NP2 (int) – Number of butterflies in Land 2.

  • Butterflies (numpy.ndarray) – Current butterfly population.

  • best (numpy.ndarray) – The best butterfly currently.

Returns

Adjusted butterfly population.

Return type

numpy.ndarray

static algorithmInfo()[source]

Get information of the algorithm.

Returns

Algorithm information.

Return type

str

See also

  • NiaPy.algorithms.algorithm.Algorithm.algorithmInfo()

evaluateAndSort(task, Butterflies)[source]

Evaluate and sort the butterfly population.

Parameters
  • task (Task) – Optimization task

  • Butterflies (numpy.ndarray) – Current butterfly population.

Returns

Tuple[numpy.ndarray, float, numpy.ndarray]:
  1. Best butterfly according to the evaluation.

  2. The best fitness value.

  3. Butterfly population.

Return type

numpy.ndarray

getParameters()[source]

Get parameters values for the algorithm.

Returns

TODO.

Return type

Dict[str, Any]

initPopulation(task)[source]

Initialize the starting population.

Parameters

task (Task) – Optimization task

Returns

  1. New population.

  2. New population fitness/function values.

  3. Additional arguments:
    • dx (float): A small value used in local seeding stage.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

levy(step_size, D)[source]

Calculate levy flight.

Parameters
  • step_size (float) – Size of the walk step.

  • D (int) – Number of dimensions.

Returns

Calculated values for levy flight.

Return type

numpy.ndarray

migrationOperator(D, NP1, NP2, Butterflies)[source]

Apply the migration operator.

Parameters
  • D (int) – Number of dimensions.

  • NP1 (int) – Number of butterflies in Land 1.

  • NP2 (int) – Number of butterflies in Land 2.

  • Butterflies (numpy.ndarray) – Current butterfly population.

Returns

Adjusted butterfly population.

Return type

numpy.ndarray

repair(x, lower, upper)[source]

Truncate exceeded dimensions to the limits.

Parameters
  • x (numpy.ndarray) – Individual to repair.

  • lower (numpy.ndarray) – Lower limits for dimensions.

  • upper (numpy.ndarray) – Upper limits for dimensions.

Returns

Repaired individual.

Return type

numpy.ndarray

runIteration(task, Butterflies, Evaluations, xb, fxb, tmp_best, **dparams)[source]

Core function of Forest Optimization Algorithm.

Parameters
  • task (Task) – Optimization task.

  • Butterflies (numpy.ndarray) – Current population.

  • Evaluations (numpy.ndarray[float]) – Current population function/fitness values.

  • xb (numpy.ndarray) – Global best individual.

  • fxb (float) – Global best individual fitness/function value.

  • tmp_best (numpy.ndarray) – Best individual currently.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. New population.

  2. New population fitness/function values.

  3. New global best solution.

  4. New global best solutions fitness/objective value.

  5. Additional arguments:
    • dx (float): A small value used in local seeding stage.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=20, PAR=0.4166666666666667, PER=1.2, **ukwargs)[source]

Set the parameters of the algorithm.

Parameters
  • NP (Optional[int]) – Population size.

  • PAR (Optional[int]) – Partition.

  • PER (Optional[int]) – Period.

  • ukwargs (Dict[str, Any]) – Additional arguments.

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • PAR (Callable[[float], bool]): Checks if partition parameter has a proper value.

  • PER (Callable[[float], bool]): Checks if period parameter has a proper value.

Return type

Dict[str, Callable]

See also

  • NiaPy.algorithms.algorithm.Algorithm.typeParameters()

class NiaPy.algorithms.basic.MonkeyKingEvolutionV1(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of monkey king evolution algorithm version 1.

Algorithm:

Monkey King Evolution version 1

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.sciencedirect.com/science/article/pii/S0950705116000198

Reference paper:

Zhenyu Meng, Jeng-Shyang Pan, Monkey King Evolution: A new memetic evolutionary algorithm and its application in vehicle fuel consumption optimization, Knowledge-Based Systems, Volume 97, 2016, Pages 144-157, ISSN 0950-7051, https://doi.org/10.1016/j.knosys.2016.01.009.

Variables
  • Name (List[str]) – List of strings representing algorithm names.

  • F (float) – Scale factor for normal particles.

  • R (float) – Procentual value of now many new particle Monkey King particle creates.

  • C (int) – Number of new particles generated by Monkey King particle.

  • FC (float) – Scale factor for Monkey King particles.

See also

  • NiaPy.algorithms.algorithm.Algorithm

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['MonkeyKingEvolutionV1', 'MKEv1']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information.

Return type

str

getParameters()[source]

Get algorithms parametes values.

Returns

Dict[str, Any]

initPopulation(task)[source]

Init population.

Parameters

task (Task) – Optimization task

Returns

  1. Initialized solutions

  2. Fitness/function values of solution

  3. Additional arguments

Return type

Tuple(numpy.ndarray[MkeSolution], numpy.ndarray[float], Dict[str, Any]]

moveMK(x, task)[source]

Move Mokey King paticle.

For moving Monkey King particles algorithm uses next formula: \(\mathbf{x} + \mathit{FC} \odot \mathbf{R} \odot \mathbf{x}\) where \(\mathbf{R}\) is two dimensional array with shape {C * D, D}. Componentes of this array are in range [0, 1]

Parameters
  • x (numpy.ndarray) – Monkey King patricle position.

  • task (Task) – Optimization task.

Returns

New particles generated by Monkey King particle.

Return type

numpy.ndarray

moveMokeyKingPartice(p, task)[source]

Move Monky King Particles.

Parameters
  • p (MkeSolution) – Monkey King particle to apply this function on.

  • task (Task) – Optimization task.

moveP(x, x_pb, x_b, task)[source]

Move normal particle in search space.

For moving particles algorithm uses next formula: \(\mathbf{x_{pb} - \mathit{F} \odot \mathbf{r} \odot (\mathbf{x_b} - \mathbf{x})\) where \(\mathbf{r}\) is one dimension array with D components. Components in this vector are in range [0, 1].

Parameters
  • x (numpy.ndarray) – Paticle position.

  • x_pb (numpy.ndarray) – Particle best position.

  • x_b (numpy.ndarray) – Best particle position.

  • task (Task) – Optimization task.

Returns

Particle new position.

Return type

numpy.ndarray

movePartice(p, p_b, task)[source]

Move patricles.

Parameters
  • p (MkeSolution) – Monke particle.

  • p_b (MkeSolution) – Population best particle.

  • task (Task) – Optimization task.

movePopulation(pop, xb, task)[source]

Move population.

Parameters
  • pop (numpy.ndarray[MkeSolution]) – Current population.

  • xb (MkeSolution) – Current best solution.

  • task (Task) – Optimization task.

Returns

New particles.

Return type

numpy.ndarray[MkeSolution]

runIteration(task, pop, fpop, xb, fxb, **dparams)[source]

Core function of Monkey King Evolution v1 algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray[MkeSolution]) – Current population.

  • fpop (numpy.ndarray[float]) – Current population fitness/function values.

  • xb (MkeSolution) – Current best solution.

  • fxb (float) – Current best solutions function/fitness value.

  • **dparams (Dict[str, Any]) – Additional arguments.

Returns

  1. Initialized solutions.

  2. Fitness/function values of solution.

  3. Additional arguments.

Return type

Tuple(numpy.ndarray[MkeSolution], numpy.ndarray[float], Dict[str, Any]]

setParameters(NP=40, F=0.7, R=0.3, C=3, FC=0.5, **ukwargs)[source]

Set Monkey King Evolution v1 algorithms static parameters.

Parameters
  • NP (int) – Population size.

  • F (float) – Scale factor for normal particle.

  • R (float) – Procentual value of now many new particle Monkey King particle creates. Value in rage [0, 1].

  • C (int) – Number of new particles generated by Monkey King particle.

  • FC (float) – Scale factor for Monkey King particles.

  • **ukwargs (Dict[str, Any]) – Additional arguments.

See also

  • NiaPy.algorithms.algorithm.Algorithm.setParameters()

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • F (Callable[[int], bool])

  • R (Callable[[Union[int, float]], bool])

  • C (Callable[[Union[int, float]], bool])

  • FC (Callable[[Union[int, float]], bool])

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.MonkeyKingEvolutionV2(**kwargs)[source]

Bases: NiaPy.algorithms.basic.mke.MonkeyKingEvolutionV1

Implementation of monkey king evolution algorithm version 2.

Algorithm:

Monkey King Evolution version 2

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.sciencedirect.com/science/article/pii/S0950705116000198

Reference paper:

Zhenyu Meng, Jeng-Shyang Pan, Monkey King Evolution: A new memetic evolutionary algorithm and its application in vehicle fuel consumption optimization, Knowledge-Based Systems, Volume 97, 2016, Pages 144-157, ISSN 0950-7051, https://doi.org/10.1016/j.knosys.2016.01.009.

Variables

Name (List[str]) – List of strings representing algorithm names.

See also

  • NiaPy.algorithms.basic.mke.MonkeyKingEvolutionV1

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['MonkeyKingEvolutionV2', 'MKEv2']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information.

Return type

str

moveMK(x, dx, task)[source]

Move Monkey King particle.

For movment of particles algorithm uses next formula: \(\mathbf{x} - \mathit{FC} \odot \mathbf{dx}\)

Parameters
  • x (numpy.ndarray) – Particle to apply movment on.

  • dx (numpy.ndarray) – Difference between to random paricles in population.

  • task (Task) – Optimization task.

Returns

Moved particles.

Return type

numpy.ndarray

moveMokeyKingPartice(p, pop, task)[source]

Move Monkey King particles.

Parameters
  • p (MkeSolution) – Monkey King particle to move.

  • pop (numpy.ndarray[MkeSolution]) – Current population.

  • task (Task) – Optimization task.

movePopulation(pop, xb, task)[source]

Move population.

Parameters
  • pop (numpy.ndarray[MkeSolution]) – Current population.

  • xb (MkeSolution) – Current best solution.

  • task (Task) – Optimization task.

Returns

Moved population.

Return type

numpy.ndarray[MkeSolution]

class NiaPy.algorithms.basic.MonkeyKingEvolutionV3(**kwargs)[source]

Bases: NiaPy.algorithms.basic.mke.MonkeyKingEvolutionV1

Implementation of monkey king evolution algorithm version 3.

Algorithm:

Monkey King Evolution version 3

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.sciencedirect.com/science/article/pii/S0950705116000198

Reference paper:

Zhenyu Meng, Jeng-Shyang Pan, Monkey King Evolution: A new memetic evolutionary algorithm and its application in vehicle fuel consumption optimization, Knowledge-Based Systems, Volume 97, 2016, Pages 144-157, ISSN 0950-7051, https://doi.org/10.1016/j.knosys.2016.01.009.

Variables

Name (List[str]) – List of strings that represent algorithm names.

See also

  • NiaPy.algorithms.basic.mke.MonkeyKingEvolutionV1

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['MonkeyKingEvolutionV3', 'MKEv3']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information.

Return type

str

initPopulation(task)[source]

Initialize the population.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized population.

  2. Initialized population function/fitness values.

  3. Additional arguments:
    • k (int): Starting number of rows to include from lower triangular matrix.

    • c (int): Constant.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

See also

  • NiaPy.algorithms.algorithm.Algorithm.initPopulation()

neg(x)[source]

Transform function.

Parameters

x (Union[int, float]) – Sould be 0 or 1.

Returns

If 0 thet 1 else 1 then 0.

Return type

float

runIteration(task, X, X_f, xb, fxb, k, c, **dparams)[source]

Core funciton of Monkey King Evolution v3 algorithm.

Parameters
  • task (Task) – Optimization task.

  • X (numpy.ndarray) – Current population.

  • X_f (numpy.ndarray[float]) – Current population fitness/function values.

  • xb (numpy.ndarray) – Current best individual.

  • fxb (float) – Current best individual function/fitness value.

  • k (int) – Starting number of rows to include from lower triangular matrix.

  • (int (c) – Constant.

  • **dparams – Additional arguments

Returns

  1. Initialized population.

  2. Initialized population function/fitness values.

  3. Additional arguments:
    • k (int): Starting number of rows to include from lower triangular matrix.

    • c (int): Constant.

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

setParameters(**ukwargs)[source]

Set core parameters of MonkeyKingEvolutionV3 algorithm.

Parameters

**ukwargs (Dict[str, Any]) – Additional arguments.

class NiaPy.algorithms.basic.MothFlameOptimizer(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

MothFlameOptimizer of Moth flame optimizer.

Algorithm:

Moth flame optimizer

Date:

2018

Author:

Kivanc Guckiran and Klemen Berkovič

License:

MIT

Reference paper:

Mirjalili, Seyedali. “Moth-flame optimization algorithm: A novel nature-inspired heuristic paradigm.” Knowledge-Based Systems 89 (2015): 228-249.

Variables

Name (List[str]) – List of strings representing algorithm name.

See also

  • NiaPy.algorithms.algorithm.Algorithm

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['MothFlameOptimizer', 'MFO']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information.

Return type

str

initPopulation(task)[source]

Initialize starting population.

Parameters

task (Task) – Optimization task

Returns

  1. Initialized population

  2. Initialized population function/fitness values

  3. Additional arguments:
    • best_flames (numpy.ndarray): Best individuals

    • best_flame_fitness (numpy.ndarray): Best individuals fitness/function values

    • previous_population (numpy.ndarray): Previous population

    • previous_fitness (numpy.ndarray[float]): Previous population fitness/function values

Return type

Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]

See also

  • NiaPy.algorithms.algorithm.Algorithm.initPopulation()

runIteration(task, moth_pos, moth_fitness, xb, fxb, best_flames, best_flame_fitness, previous_population, previous_fitness, **dparams)[source]

Core function of MothFlameOptimizer algorithm.

Parameters
  • task (Task) – Optimization task.

  • moth_pos (numpy.ndarray) – Current population.

  • moth_fitness (numpy.ndarray) – Current population fitness/function values.

  • xb (numpy.ndarray) – Current population best individual.

  • fxb (float) – Current best individual.

  • best_flames (numpy.ndarray) – Best found individuals.

  • best_flame_fitness (numpy.ndarray) – Best found individuals fitness/function values.

  • previous_population (numpy.ndarray) – Previous population.

  • previous_fitness (numpy.ndarray) – Previous population fitness/function values.

  • **dparams (Dict[str, Any]) – Additional parameters

Returns

  1. New population.

  2. New population fitness/function values.

  3. New global best solution.

  4. New global best fitness/objective value.

  5. Additional arguments:
    • best_flames (numpy.ndarray): Best individuals.

    • best_flame_fitness (numpy.ndarray): Best individuals fitness/function values.

    • previous_population (numpy.ndarray): Previous population.

    • previous_fitness (numpy.ndarray): Previous population fitness/function values.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=25, **ukwargs)[source]

Set the algorithm parameters.

Parameters

NP (int) – Number of individuals in population

See also

  • NiaPy.algorithms.algorithm.Algorithm.setParameters()

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

TODO

Return type

Dict[str, Callable]

See also

  • NiaPy.algorithms.algorithm.Algorithm.typeParameters()

class NiaPy.algorithms.basic.MultiStrategyDifferentialEvolution(**kwargs)[source]

Bases: NiaPy.algorithms.basic.de.DifferentialEvolution

Implementation of Differential evolution algorithm with multiple mutation strateys.

Algorithm:

Implementation of Differential evolution algorithm with multiple mutation strateys

Date:

2018

Author:

Klemen Berkovič

License:

MIT

Variables

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['MultiStrategyDifferentialEvolution', 'MsDE']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

evolve(pop, xb, task, **kwargs)[source]

Evolve population with the help multiple mutation strategies.

Parameters
  • pop (numpy.ndarray) – Current population.

  • xb (numpy.ndarray) – Current best individual.

  • task (Task) – Optimization task.

  • **kwargs (Dict[str, Any]) – Additional arguments.

Returns

New population of individuals.

Return type

numpy.ndarray

getParameters()[source]

Get parameters values of the algorithm.

Returns

TODO.

Return type

Dict[str, Any]

setParameters(strategies=(<function CrossRand1>, <function CrossBest1>, <function CrossCurr2Best1>, <function CrossRand2>), **ukwargs)[source]

Set the arguments of the algorithm.

Parameters
static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

Testing functions for parameters.

Return type

Dict[str, Callable]

class NiaPy.algorithms.basic.MutatedCenterParticleSwarmOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.basic.pso.CenterParticleSwarmOptimization

Implementation of Mutated Particle Swarm Optimization.

Algorithm:

Mutated Center Particle Swarm Optimization

Date:

2019

Authors:

Klemen Berkovič

License:

MIT

Reference paper:

TODO find one

Variables

nmutt (int) – Number of mutations of global best particle.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['MutatedCenterParticleSwarmOptimization', 'MCPSO']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

getParameters()[source]

Get value of parametrs for this instance of algorithm.

Returns

Dictionary which has parameters maped to values.

Return type

Dict[str, Union[int, float, np.ndarray]]

runIteration(task, pop, fpop, xb, fxb, **dparams)[source]

Core function of algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population of particles.

  • fpop (numpy.ndarray) – Current particles function/fitness values.

  • xb (numpy.ndarray) – Current global best particle.

  • (float (fxb) – Current global best particles function/fitness value.

  • **dparams – Additional arguments.

Returns

  1. New population of particles.

  2. New populations function/fitness values.

  3. New global best particle.

  4. New global best particle function/fitness value.

  5. Additional arguments.

Return type

Tuple[np.ndarray, np.ndarray, np.ndarray, float, dict]

See also

  • NiaPy.algorithm.basic.WeightedVelocityClampingParticleSwarmAlgorithm.runIteration()

setParameters(nmutt=10, **kwargs)[source]

Set core algorithm parameters.

Parameters
  • nmutt (int) – Number of mutations of global best particle.

  • **kwargs – Additional arguments.

See also

NiaPy.algorithm.basic.CenterParticleSwarmOptimization.setParameters()

class NiaPy.algorithms.basic.MutatedCenterUnifiedParticleSwarmOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.basic.pso.MutatedCenterParticleSwarmOptimization

Implementation of Mutated Particle Swarm Optimization.

Algorithm:

Mutated Center Unified Particle Swarm Optimization

Date:

2019

Authors:

Klemen Berkovič

License:

MIT

Reference paper:

Tsai, Hsing-Chih. “Unified particle swarm delivers high efficiency to particle swarm optimization.” Applied Soft Computing 55 (2017): 371-383.

Variables

nmutt (int) – Number of mutations of global best particle.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['MutatedCenterUnifiedParticleSwarmOptimization', 'MCUPSO']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

setParameters(**kwargs)[source]

Set core algorithm parameters.

Parameters

**kwargs – Additional arguments.

See also

NiaPy.algorithm.basic.MutatedCenterParticleSwarmOptimization.setParameters()

updateVelocity(V, p, pb, gb, w, vMin, vMax, task, **kwargs)[source]

Update particle velocity.

Parameters
  • V (numpy.ndarray) – Current velocity of particle.

  • p (numpy.ndarray) – Current position of particle.

  • pb (numpy.ndarray) – Personal best position of particle.

  • gb (numpy.ndarray) – Global best position of particle.

  • w (numpy.ndarray) – Weights for velocity adjustment.

  • vMin (numpy.ndarray) – Minimal velocity allowed.

  • vMax (numpy.ndarray) – Maxmimal velocity allowed.

  • task (Task) – Optimization task.

  • kwargs – Additional arguments.

Returns

Updated velocity of particle.

Return type

numpy.ndarray

class NiaPy.algorithms.basic.MutatedParticleSwarmOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.basic.pso.ParticleSwarmAlgorithm

Implementation of Mutated Particle Swarm Optimization.

Algorithm:

Mutated Particle Swarm Optimization

Date:

2019

Authors:

Klemen Berkovič

License:

MIT

Reference paper:
  1. Wang, C. Li, Y. Liu, S. Zeng, A hybrid particle swarm algorithm with cauchy mutation, Proceedings of the 2007 IEEE Swarm Intelligence Symposium (2007) 356–360.

Variables

nmutt (int) – Number of mutations of global best particle.

See also

  • NiaPy.algorithms.basic.WeightedVelocityClampingParticleSwarmAlgorithm

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['MutatedParticleSwarmOptimization', 'MPSO']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

getParameters()[source]

Get value of parametrs for this instance of algorithm.

Returns

Dictionary which has parameters maped to values.

Return type

Dict[str, Union[int, float, np.ndarray]]

runIteration(task, pop, fpop, xb, fxb, **dparams)[source]

Core function of algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population of particles.

  • fpop (numpy.ndarray) – Current particles function/fitness values.

  • xb (numpy.ndarray) – Current global best particle.

  • fxb (float) – Current global best particles function/fitness value.

  • **dparams – Additional arguments.

Returns

  1. New population of particles.

  2. New populations function/fitness values.

  3. New global best particle.

  4. New global best particle function/fitness value.

  5. Additional arguments.

Return type

Tuple[np.ndarray, np.ndarray, np.ndarray, float, dict]

See also

  • NiaPy.algorithm.basic.WeightedVelocityClampingParticleSwarmAlgorithm.runIteration()

setParameters(nmutt=10, **kwargs)[source]

Set core algorithm parameters.

Parameters
  • nmutt (int) – Number of mutations of global best particle.

  • **kwargs – Additional arguments.

See also

NiaPy.algorithm.basic.WeightedVelocityClampingParticleSwarmAlgorithm.setParameters()

class NiaPy.algorithms.basic.OppositionVelocityClampingParticleSwarmOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.basic.pso.ParticleSwarmAlgorithm

Implementation of Opposition-Based Particle Swarm Optimization with Velocity Clamping.

Algorithm:

Opposition-Based Particle Swarm Optimization with Velocity Clamping

Date:

2019

Authors:

Klemen Berkovič

License:

MIT

Reference paper:

Shahzad, Farrukh, et al. “Opposition-based particle swarm optimization with velocity clamping (OVCPSO).” Advances in Computational Intelligence. Springer, Berlin, Heidelberg, 2009. 339-348

Variables
  • p0 – Probability of opposite learning phase.

  • w_min – Minimum inertial weight.

  • w_max – Maximum inertial weight.

  • sigma – Velocity scaling factor.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['OppositionVelocityClampingParticleSwarmOptimization', 'OVCPSO']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

getParameters()[source]

Get value of parametrs for this instance of algorithm.

Returns

Dictionary which has parameters maped to values.

Return type

Dict[str, Union[int, float, np.ndarray]]

initPopulation(task)[source]

Init starting population and dynamic parameters.

Parameters

task (Task) – Optimization task.

Returns

  1. Initialized population.

  2. Initialized populations function/fitness values.

  3. Additional arguments:
    • popb (numpy.ndarray): particles best population.

    • fpopb (numpy.ndarray[float]): particles best positions function/fitness value.

    • vMin (numpy.ndarray): Minimal velocity.

    • vMax (numpy.ndarray): Maximal velocity.

    • V (numpy.ndarray): Initial velocity of particle.

    • S_u (numpy.ndarray): Upper bound for opposite learning.

    • S_l (numpy.ndarray): Lower bound for opposite learning.

Return type

Tuple[np.ndarray, np.ndarray, dict]

oppositeLearning(S_l, S_h, pop, fpop, task)[source]

Run opposite learning phase.

Parameters
  • S_l (numpy.ndarray) – Lower limit of opposite particles.

  • S_h (numpy.ndarray) – Upper limit of opposite particles.

  • pop (numpy.ndarray) – Current populations positions.

  • fpop (numpy.ndarray) – Current populations functions/fitness values.

  • task (Task) – Optimization task.

Returns

  1. New particles position

  2. New particles function/fitness values

  3. New best position of opposite learning phase

  4. new best function/fitness value of opposite learning phase

Return type

Tuple[np.ndarray, np.ndarray, np.ndarray, float]

runIteration(task, pop, fpop, xb, fxb, popb, fpopb, vMin, vMax, V, S_l, S_h, **dparams)[source]

Core function of Opposite-based Particle Swarm Optimization with velocity clamping algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current population.

  • fpop (numpy.ndarray) – Current populations function/fitness values.

  • xb (numpy.ndarray) – Current global best position.

  • fxb (float) – Current global best positions function/fitness value.

  • popb (numpy.ndarray) – Personal best position.

  • fpopb (numpy.ndarray) – Personal best positions function/fitness values.

  • vMin (numpy.ndarray) – Minimal allowed velocity.

  • vMax (numpy.ndarray) – Maximal allowed velocity.

  • V (numpy.ndarray) – Populations velocity.

  • S_l (numpy.ndarray) – Lower bound of opposite learning.

  • S_h (numpy.ndarray) – Upper bound of opposite learning.

  • **dparams – Additional arguments.

Returns

  1. New population.

  2. New populations function/fitness values.

  3. New global best position.

  4. New global best positions function/fitness value.

  5. Additional arguments:
    • popb: particles best population.

    • fpopb: particles best positions function/fitness value.

    • vMin: Minimal velocity.

    • vMax: Maximal velocity.

    • V: Initial velocity of particle.

    • S_u: Upper bound for opposite learning.

    • S_l: Lower bound for opposite learning.

Return type

Tuple[np.ndarray, np.ndarray, np.ndarray, float, dict]

setParameters(p0=0.3, w_min=0.4, w_max=0.9, sigma=0.1, C1=1.49612, C2=1.49612, **kwargs)[source]

Set core algorithm parameters.

Parameters
  • p0 (float) – Probability of running Opposite learning.

  • w_min (numpy.ndarray) – Minimal value of weights.

  • w_max (numpy.ndarray) – Maximum value of weights.

  • sigma (numpy.ndarray) – Velocity range factor.

  • **kwargs – Additional arguments.

See also

  • NiaPy.algorithm.basic.ParticleSwarmAlgorithm.setParameters()

class NiaPy.algorithms.basic.ParticleSwarmAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of Particle Swarm Optimization algorithm.

Algorithm:

Particle Swarm Optimization algorithm

Date:

2018

Authors:

Lucija Brezočnik, Grega Vrbančič, Iztok Fister Jr. and Klemen Berkovič

License:

MIT

Reference paper:

Kennedy, J. and Eberhart, R. “Particle Swarm Optimization”. Proceedings of IEEE International Conference on Neural Networks. IV. pp. 1942–1948, 1995.

Variables
  • Name (List[str]) – List of strings representing algorithm names

  • C1 (float) – Cognitive component.

  • C2 (float) – Social component.

  • w (Union[float, numpy.ndarray[float]]) – Inertial weight.

  • vMin (Union[float, numpy.ndarray[float]]) – Minimal velocity.

  • vMax (Union[float, numpy.ndarray[float]]) – Maximal velocity.

  • Repair (Callable[[numpy.ndarray, numpy.ndarray, numpy.ndarray, mtrnd.RandomState], numpy.ndarray]) – Repair method for velocity.

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['WeightedVelocityClampingParticleSwarmAlgorithm', 'WVCPSO']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

getParameters()[source]

Get value of parametrs for this instance of algorithm.

Returns

Dictionary which has parameters maped to values.

Return type

Dict[str, Union[int, float, np.ndarray]]

init(task)[source]

Initialize dynamic arguments of Particle Swarm Optimization algorithm.

Parameters

task (Task) – Optimization task.

Returns

  • w (numpy.ndarray): Inertial weight.

  • vMin (numpy.ndarray): Mininal velocity.

  • vMax (numpy.ndarray): Maximal velocity.

  • V (numpy.ndarray): Initial velocity of particle.

Return type

Dict[str, Union[float, np.ndarray]]

initPopulation(task)[source]

Initialize population and dynamic arguments of the Particle Swarm Optimization algorithm.

Parameters

task – Optimization task.

Returns

  1. Initial population.

  2. Initial population fitness/function values.

  3. Additional arguments:
    • popb (numpy.ndarray): particles best population.

    • fpopb (numpy.ndarray[float]): particles best positions function/fitness value.

    • w (numpy.ndarray): Inertial weight.

    • vMin (numpy.ndarray): Minimal velocity.

    • vMax (numpy.ndarray): Maximal velocity.

    • V (numpy.ndarray): Initial velocity of particle.

Return type

Tuple[np.ndarray, np.ndarray, dict]

runIteration(task, pop, fpop, xb, fxb, popb, fpopb, w, vMin, vMax, V, **dparams)[source]

Core function of Particle Swarm Optimization algorithm.

Parameters
  • task (Task) – Optimization task.

  • pop (numpy.ndarray) – Current populations.

  • fpop (numpy.ndarray) – Current population fitness/function values.

  • xb (numpy.ndarray) – Current best particle.

  • fxb (float) – Current best particle fitness/function value.

  • popb (numpy.ndarray) – Particles best position.

  • fpopb (numpy.ndarray) – Particles best positions fitness/function values.

  • w (numpy.ndarray) – Inertial weights.

  • vMin (numpy.ndarray) – Minimal velocity.

  • vMax (numpy.ndarray) – Maximal velocity.

  • V (numpy.ndarray) – Velocity of particles.

  • **dparams – Additional function arguments.

Returns

  1. New population.

  2. New population fitness/function values.

  3. New global best position.

  4. New global best positions function/fitness value.

  5. Additional arguments:
    • popb (numpy.ndarray): Particles best population.

    • fpopb (numpy.ndarray[float]): Particles best positions function/fitness value.

    • w (numpy.ndarray): Inertial weight.

    • vMin (numpy.ndarray): Minimal velocity.

    • vMax (numpy.ndarray): Maximal velocity.

    • V (numpy.ndarray): Initial velocity of particle.

Return type

Tuple[np.ndarray, np.ndarray, np.ndarray, float, dict]

See also

  • NiaPy.algorithms.algorithm.runIteration

setParameters(NP=25, C1=2.0, C2=2.0, w=0.7, vMin=-1.5, vMax=1.5, Repair=<function reflectRepair>, **ukwargs)[source]

Set Particle Swarm Algorithm main parameters.

Parameters
  • NP (int) – Population size

  • C1 (float) – Cognitive component.

  • C2 (float) – Social component.

  • w (Union[float, numpy.ndarray]) – Inertial weight.

  • vMin (Union[float, numpy.ndarray]) – Minimal velocity.

  • vMax (Union[float, numpy.ndarray]) – Maximal velocity.

  • Repair (Callable[[np.ndarray, np.ndarray, np.ndarray, dict], np.ndarray]) – Repair method for velocity.

  • **ukwargs – Additional arguments

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • NP (Callable[[int], bool])

  • C1 (Callable[[Union[int, float]], bool])

  • C2 (Callable[[Union[int, float]], bool])

  • w (Callable[[float], bool])

  • vMin (Callable[[Union[int, float]], bool])

  • vMax (Callable[[Union[int, float], bool])

Return type

Dict[str, Callable[[Union[int, float]], bool]]

updateVelocity(V, p, pb, gb, w, vMin, vMax, task, **kwargs)[source]

Update particle velocity.

Parameters
  • V (numpy.ndarray) – Current velocity of particle.

  • p (numpy.ndarray) – Current position of particle.

  • pb (numpy.ndarray) – Personal best position of particle.

  • gb (numpy.ndarray) – Global best position of particle.

  • w (numpy.ndarray) – Weights for velocity adjustment.

  • vMin (numpy.ndarray) – Minimal velocity allowed.

  • vMax (numpy.ndarray) – Maximal velocity allowed.

  • task (Task) – Optimization task.

  • kwargs – Additional arguments.

Returns

Updated velocity of particle.

Return type

numpy.ndarray

class NiaPy.algorithms.basic.ParticleSwarmOptimization(**kwargs)[source]

Bases: NiaPy.algorithms.basic.pso.ParticleSwarmAlgorithm

Implementation of Particle Swarm Optimization algorithm.

Algorithm:

Particle Swarm Optimization algorithm

Date:

2018

Authors:

Lucija Brezočnik, Grega Vrbančič, Iztok Fister Jr. and Klemen Berkovič

License:

MIT

Reference paper:

Kennedy, J. and Eberhart, R. “Particle Swarm Optimization”. Proceedings of IEEE International Conference on Neural Networks. IV. pp. 1942–1948, 1995.

Variables
  • Name (List[str]) – List of strings representing algorithm names

  • C1 (float) – Cognitive component.

  • C2 (float) – Social component.

  • Repair (Callable[[numpy.ndarray, numpy.ndarray, numpy.ndarray, mtrnd.RandomState], numpy.ndarray]) – Repair method for velocity.

See also

  • NiaPy.algorithms.basic.WeightedVelocityClampingParticleSwarmAlgorithm

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['ParticleSwarmAlgorithm', 'PSO']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

getParameters()[source]

Get value of parametrs for this instance of algorithm.

Returns

Dictionary which has parameters maped to values.

Return type

Dict[str, Union[int, float, np.ndarray]]

setParameters(**ukwargs)[source]

Set core parameters of algorithm.

Parameters

**ukwargs (Dict[str, Any]) – Additional parameters.

See also

  • NiaPy.algorithms.basic.WeightedVelocityClampingParticleSwarmAlgorithm.setParameters()

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • NP: Population size.

  • C1: Cognitive component.

  • C2: Social component.

Return type

Dict[str, Callable[[Union[int, float]], bool]]

class NiaPy.algorithms.basic.SineCosineAlgorithm(**kwargs)[source]

Bases: NiaPy.algorithms.algorithm.Algorithm

Implementation of sine cosine algorithm.

Algorithm:

Sine Cosine Algorithm

Date:

2018

Authors:

Klemen Berkovič

License:

MIT

Reference URL:

https://www.sciencedirect.com/science/article/pii/S0950705115005043

Reference paper:

Seyedali Mirjalili, SCA: A Sine Cosine Algorithm for solving optimization problems, Knowledge-Based Systems, Volume 96, 2016, Pages 120-133, ISSN 0950-7051, https://doi.org/10.1016/j.knosys.2015.12.022.

Variables
  • Name (List[str]) – List of string representing algorithm names.

  • a (float) – Parameter for control in \(r_1\) value

  • Rmin (float) – Minimu value for \(r_3\) value

  • Rmax (float) – Maximum value for \(r_3\) value

Initialize algorithm and create name for an algorithm.

Parameters

seed (int) – Starting seed for random generator.

Name = ['SineCosineAlgorithm', 'SCA']
static algorithmInfo()[source]

Get basic information of algorithm.

Returns

Basic information of algorithm.

Return type

str

getParameters()[source]

Get algorithm parameters values.

Returns

Return type

Dict[str, Any]

See also

  • NiaPy.algorithms.algorithm.Algorithm.getParameters()

initPopulation(task)[source]

Initialize the individuals.

Parameters

task (Task) – Optimization task

Returns

  1. Initialized population of individuals

  2. Function/fitness values for individuals

  3. Additional arguments

Return type

Tuple[numpy.ndarray, numpy.ndarray, Dict[str, Any]]

nextPos(x, x_b, r1, r2, r3, r4, task)[source]

Move individual to new position in search space.

Parameters
  • x (numpy.ndarray) – Individual represented with components.

  • x_b (nmppy.ndarray) – Best individual represented with components.

  • r1 (float) – Number dependent on algorithm iteration/generations.

  • r2 (float) – Random number in range of 0 and 2 * PI.

  • r3 (float) – Random number in range [Rmin, Rmax].

  • r4 (float) – Random number in range [0, 1].

  • task (Task) – Optimization task.

Returns

New individual that is moved based on individual x.

Return type

numpy.ndarray

runIteration(task, P, P_f, xb, fxb, **dparams)[source]

Core function of Sine Cosine Algorithm.

Parameters
  • task (Task) – Optimization task.

  • P (numpy.ndarray) – Current population individuals.

  • P_f (numpy.ndarray[float]) – Current population individulas function/fitness values.

  • xb (numpy.ndarray) – Current best solution to optimization task.

  • fxb (float) – Current best function/fitness value.

  • dparams (Dict[str, Any]) – Additional parameters.

Returns

  1. New population.

  2. New populations fitness/function values.

  3. New global best solution.

  4. New global best fitness/objective value.

  5. Additional arguments.

Return type

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, Dict[str, Any]]

setParameters(NP=25, a=3, Rmin=0, Rmax=2, **ukwargs)[source]

Set the arguments of an algorithm.

Parameters
  • NP (Optional[int]) – Number of individual in population

  • a (Optional[float]) – Parameter for control in \(r_1\) value

  • Rmin (Optional[float]) – Minimu value for \(r_3\) value

  • Rmax (Optional[float]) – Maximum value for \(r_3\) value

See also

  • NiaPy.algorithms.algorithm.Algorithm.setParameters()

static typeParameters()[source]

Get dictionary with functions for checking values of parameters.

Returns

  • a (Callable[[Union[float, int]], bool]): TODO

  • Rmin (Callable[[Union[float, int]], bool]): TODO

  • Rmax (Callable[[Union[float, int]], bool]): TODO

Return type

Dict[str, Callable]

NiaPy.algorithms.basic.multiMutations(pop, i, xb, F, CR, rnd, task, itype, strategies, **kwargs)[source]

Mutation strategy that takes more than one strategy and applys them to individual.

Parameters
  • pop (numpy.ndarray[Individual]) – Current population.

  • i (int) – Index of current individual.

  • xb (Individual) – Current best individual.

  • F (float) – Scale factor.

  • CR (float) – Crossover probabili