moocore.

local_crossover#

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

Local crossover.

Each crossover operation on a pair of parents \(x, y\) produces two offspring. With probability pair_prob, they are

\[u_j = a_j x_j + (1 - a_j) y_j, \qquad v_j = (1 - a_j) x_j + a_j y_j,\]

where each weight \(a_j\) is drawn uniformly from \([0, 1)\). The offspring lie in the box spanned by their parents, and \(u + v = x + y\). 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

single_arithmetic_crossover

Average a single variable.

blend_alpha_crossover

Sample around the parents.

Notes

This operator is described by Dumitrescu et al. (2000) and compared with other real-coded crossover operators by Picek, Jakobovic and Golub (2013).

References

D. Dumitrescu, B. Lazzerini, L. C. Jain and A. Dumitrescu (2000). Evolutionary Computation. CRC Press. https://doi.org/10.1201/9781482273960

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], [1.0, 1.0, 1.0]])
>>> moocore.local_crossover(parents, seed=42)
array([[0.04928569, 0.26800606, 0.40134152],
       [0.95071431, 0.73199394, 0.59865848]])