pub trait Fitness: Send + Sync {
type Genome: EvolutionaryGenome;
type Value: FitnessValue;
// Required method
fn evaluate(&self, genome: &Self::Genome) -> Self::Value;
// Provided methods
fn as_log_likelihood(&self, genome: &Self::Genome, temperature: f64) -> f64 { ... }
fn gradient(&self, _genome: &Self::Genome) -> Option<Vec<f64>> { ... }
}Expand description
Fitness evaluation trait
Defines how to evaluate the fitness of a genome.
§Send + Sync and the parallel feature
With the parallel feature this trait has Send + Sync as supertraits
(rayon evaluates a population from several threads); without it there is
no such bound, so a fitness that holds a !Send value — a js_sys::Function
in the crate’s own WASM bindings, an Rc — is a valid implementor. This
is a deliberate, known non-additive feature (EV-N5): a crate that
compiles without parallel can implement Fitness for a !Send type
and fail to build the moment any crate in its dependency graph enables
parallel. Requiring the bound unconditionally was considered and
rejected because it would force single-threaded WASM consumers into
unsafe impl Send wrappers for their JavaScript callbacks. If your crate
must build with and without parallel, make your fitness Send + Sync;
the inference layer (ppl) requires that independently through
FactorFitness, GenomePrior and GenomeLikelihood.
Required Associated Types§
Sourcetype Genome: EvolutionaryGenome
type Genome: EvolutionaryGenome
The genome type being evaluated
Sourcetype Value: FitnessValue
type Value: FitnessValue
The fitness value type
Required Methods§
Provided Methods§
Sourcefn as_log_likelihood(&self, genome: &Self::Genome, temperature: f64) -> f64
fn as_log_likelihood(&self, genome: &Self::Genome, temperature: f64) -> f64
Convert fitness to log-likelihood for probabilistic selection
Uses Boltzmann distribution: P(x) ∝ exp(f(x) / T)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".