Expand description
Population containers.
Population<B, K> is a thin wrapper around a device tensor plus the
shape metadata strategies need. For real-valued kinds it holds a
Tensor<B, 2>; binary and integer kinds use Tensor<B, 2, Int>.
The wrapper exists so operators and strategies have a single shape
contract to validate against (they check pop_size and genome_dim
rather than repeatedly interrogating tensor.dims()).
§Constructing a population
Each genome kind has a dedicated constructor that takes the already-allocated tensor:
use burn::backend::Flex;
use burn::tensor::{Tensor, TensorData};
use rlevo_evolution::genome::Real;
use rlevo_evolution::population::Population;
let device = Default::default();
// 4 individuals, each with a 3-gene real-valued genome.
let data = TensorData::new(vec![0.1f32, 0.2, 0.3,
0.4, 0.5, 0.6,
0.7, 0.8, 0.9,
1.0, 1.1, 1.2], [4, 3]);
let tensor = Tensor::<Flex, 2>::from_data(data, &device);
// Construction validates that the tensor is non-empty, so it returns a
// `Result`; a 0×n or m×0 tensor is rejected as a `ConfigError`.
let pop = Population::<Flex, Real>::new_real(tensor).unwrap();
assert_eq!(pop.pop_size(), 4);
assert_eq!(pop.genome_dim(), 3);Structs§
- Population
- Population stored on a Burn backend device.