Fixed-length vector of real-valued genes for continuous optimization.
use fugue_evo::genome::real_vector::RealVector;
// From vector
let genome = RealVector::new(vec![1.0, 2.0, 3.0]);
// With dimension
let genome = RealVector::zeros(10);
// Random within bounds
let genome = RealVector::random(&bounds, &mut rng);
| Method |
Return |
Description |
genes() |
&[f64] |
Immutable gene access |
genes_mut() |
&mut [f64] |
Mutable gene access |
dimension() |
usize |
Number of genes |
get(i) |
Option<f64> |
Get gene at index |
| Method |
Description |
add(&other) |
Element-wise addition |
sub(&other) |
Element-wise subtraction |
scale(factor) |
Multiply all genes by factor |
norm() |
Euclidean norm |
euclidean_distance(&other) |
Distance between vectors |
dot(&other) |
Dot product |
| Method |
Description |
mean() |
Mean of genes |
variance() |
Variance of genes |
sum() |
Sum of genes |
Genes are stored at indexed addresses:
// Trace structure
addr!("gene", 0) → genes[0]
addr!("gene", 1) → genes[1]
// ...
// Simulated Binary Crossover
SbxCrossover::new(20.0)
// Blend Crossover
BlendCrossover::new(0.5)
// Uniform Crossover
UniformCrossover::new()
// Polynomial Mutation
PolynomialMutation::new(20.0)
// Gaussian Mutation
GaussianMutation::new(0.1)
use fugue_evo::prelude::*;
let bounds = MultiBounds::symmetric(5.12, 10);
let mut genome = RealVector::random(&bounds, &mut rng);
// Modify genes
genome.genes_mut()[0] = 1.0;
// Vector operations
let other = RealVector::random(&bounds, &mut rng);
let distance = genome.euclidean_distance(&other);
// Use in GA
let result = SimpleGABuilder::<RealVector, f64, _, _, _, _, _>::new()
.bounds(bounds)
// ...