moocore.

blend_alpha_crossover#

moocore.blend_alpha_crossover(parents, /, *, lower=None, upper=None, alpha=0.5, pair_prob=1.0, seed=None)[source]#

Blend crossover (BLX-\(\alpha\)).

Each crossover operation on a pair of parents \(x, y\) produces one offspring \(z\). With probability pair_prob, for each variable \(j\), let \(m_j = \min(x_j, y_j)\), \(M_j = \max(x_j, y_j)\) and \(d_j = M_j - m_j\). Then \(z_j\) is sampled uniformly from \([m_j - \alpha d_j, M_j + \alpha d_j]\), clipped to the bounds of the variable. Otherwise, the offspring is a copy of the first parent \(x\).

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. Every value must be within the bounds.

  • lower (ArrayLike | None) – Lower bounds of the decision variables. Either a single value, which will be used for all variables, or one value per column. None means no lower bound. (default: None)

  • upper (ArrayLike | None) – Upper bounds of the decision variables. Either a single value, which will be used for all variables, or one value per column. None means no upper bound. (default: None)

  • alpha (float) – Fraction of the distance between the parents by which the sampling interval extends beyond them on each side. With alpha=0, the offspring lie between their parents. (default: 0.5)

  • 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 \(\lceil n/2 \rceil\) rows, where \(n\) is the number of rows of parents. Row i is the offspring of rows 2i and 2i + 1 of parents.

See also

local_crossover

Offspring inside the box spanned by the parents.

Notes

BLX-\(\alpha\) was proposed by Eshelman and Schaffer[1], who recommend \(\alpha = 0.5\) because it makes an offspring as likely to lie outside its parents as between them. Each variable is sampled independently, so the offspring fill the whole (clipped) box around the parents. Eshelman and Schaffer do not handle bounds, and they produce two offspring per pair.

To produce more than one offspring per pair, call the function again. If seed is an integer, every call returns the same offspring. Pass the same numpy.random.Generator to every call to get different offspring each time, as in the example below.

References

Examples

>>> parents = np.array([[0.2, 0.2], [0.6, 0.8]])
>>> rng = np.random.default_rng(42)
>>> moocore.blend_alpha_crossover(parents, lower=0, upper=1, seed=rng)
array([[0.4174605 , 0.81353203]])
>>> moocore.blend_alpha_crossover(parents, lower=0, upper=1, seed=rng)
array([[0.03527987, 0.73987298]])