moocore.

single_arithmetic_crossover#

moocore.single_arithmetic_crossover(parents, /, *, pair_prob=1.0, seed=None)[source]#

Single arithmetic crossover.

Each crossover operation on a pair of parents \(x, y\) produces two offspring. With probability pair_prob, one variable \(k\) is chosen uniformly at random and both offspring get \((x_k + y_k) / 2\) in that variable. All other variables are copied from the parents. Otherwise, the offspring are copies of their parents.

Parameters:
  • parents (ArrayLike) – 2D array of numerical values, where each row is a decision vector. Rows 2i and 2i + 1 are crossed over. If the number of rows is odd, the last row is crossed over with the first one.

  • pair_prob (float) – Probability of applying the crossover operation to each pair of parents. (default: 1.0)

  • seed (int | Generator | None) – Either an integer to seed numpy.random.default_rng(), a Numpy default random number generator (RNG) or an instance of a Numpy-compatible RNG. None uses the equivalent of a random seed, as in numpy.random.default_rng(). (default: None)

Returns:

ndarray – Array with the same shape as parents, where rows 2i and 2i + 1 are the two offspring of rows 2i and 2i + 1 of parents. If the number of rows is odd, the second offspring of the last pair is dropped, so the number of rows does not change.

See also

local_crossover

Recombine every variable with a random weight.

Notes

Eiben and Smith[1] describe single arithmetic recombination with a weight \(\alpha\), where one offspring gets \(\alpha y_k + (1 - \alpha) x_k\) and the other gets \(\alpha x_k + (1 - \alpha) y_k\). This function is their example with \(\alpha = 1/2\), where both offspring get the average. Picek, Jakobovic and Golub (2013) compare it with other real-coded crossover operators.

References

S. Picek, D. Jakobovic and M. Golub (2013). On the recombination operator in the real-coded genetic algorithms. 2013 IEEE Congress on Evolutionary Computation, pages 3103–3110. https://doi.org/10.1109/CEC.2013.6557948

Examples

>>> parents = np.array([[0.0, 0.0, 0.0, 0.0], [1.0, 1.0, 1.0, 1.0]])
>>> moocore.single_arithmetic_crossover(parents, seed=42)
array([[0. , 0. , 0. , 0.5],
       [1. , 1. , 1. , 0.5]])