Skip to main content

binary_uniform_crossover

Function binary_uniform_crossover 

Source
pub fn binary_uniform_crossover<B: Backend>(
    parent_a: Tensor<B, 2, Int>,
    parent_b: Tensor<B, 2, Int>,
    p: f32,
    rng: &mut dyn Rng,
    device: &<B as BackendTypes>::Device,
) -> Tensor<B, 2, Int>
Expand description

Binary uniform crossover on Tensor<B, 2, Int> populations.

The Int-tensor counterpart of uniform_crossover, intended for binary genomes. For each gene, the child inherits parent_a’s allele with probability p and parent_b’s allele with probability 1 − p. No blending is performed; the operation is a pure bitwise swap.

Both parents must hold values in {0, 1}. The returned tensor has the same shape and element type as the inputs. All n·d Bernoulli draws are taken from the caller-supplied host rng and loaded onto the device via Tensor::from_data; no backend-global RNG state is touched.

§Panics

Panics if parent_a and parent_b do not have identical shapes.