pub struct EvolutionModel<P, L>{ /* private fields */ }Expand description
A probabilistic model of an evolutionary population: a genome prior
program, an observation program (likelihood), and an inverse temperature
β.
Implementations§
Source§impl<P, F> EvolutionModel<P, FactorFitness<F>>
impl<P, F> EvolutionModel<P, FactorFitness<F>>
Sourcepub fn new(prior: P, fitness: F) -> Self
pub fn new(prior: P, fitness: F) -> Self
Create a model with a black-box scalar fitness entering as
factor(β·f(x)) (the classical Gibbs-posterior mode), at β = 1.
Sourcepub fn fitness_value(&self, genome: &P::Genome) -> f64
pub fn fitness_value(&self, genome: &P::Genome) -> f64
Raw fitness f(x) (higher is better).
Sourcepub fn log_weight(&self, genome: &P::Genome) -> f64
pub fn log_weight(&self, genome: &P::Genome) -> f64
The tempered fitness log-factor β · f(x).
Sourcepub fn to_weighted_trace(&self, genome: &P::Genome) -> Trace
pub fn to_weighted_trace(&self, genome: &P::Genome) -> Trace
Create a fugue trace whose choices equal the genome’s encoding under
this model’s prior and whose total_log_weight() equals β · f(x) —
the “fitness as likelihood” weighted-trace contract (EV-52): a genuine
factor(β·f) model run through
TraceScoringHandler,
so the mass lands in log_factors.
Source§impl<P, L> EvolutionModel<P, L>
impl<P, L> EvolutionModel<P, L>
Sourcepub fn from_likelihood(prior: P, likelihood: L) -> Self
pub fn from_likelihood(prior: P, likelihood: L) -> Self
Create a model from an arbitrary observation program (observe
statements, latent nuisance parameters, factors), at β = 1.
Sourcepub fn with_temperature(self, temperature: f64) -> Self
pub fn with_temperature(self, temperature: f64) -> Self
Set the temperature T; equivalent to β = 1/T.
Sourcepub fn temperature(&self) -> f64
pub fn temperature(&self) -> f64
Current temperature T = 1/β.
Sourcepub fn likelihood(&self) -> &L
pub fn likelihood(&self) -> &L
The observation program.
Sourcepub fn target_model(&self) -> impl Fn() -> Model<P::Genome> + Clone + '_
pub fn target_model(&self) -> impl Fn() -> Model<P::Genome> + Clone + '_
The fixed-β target as a program:
log π_β(x) = log p(x) + β·log p(data|x). This is the model MH runs
against.
Sourcepub fn smc_model(&self) -> impl Fn() -> Model<P::Genome> + Clone + '_
pub fn smc_model(&self) -> impl Fn() -> Model<P::Genome> + Clone + '_
The untempered (β = 1) joint program for tempered SMC: fugue’s
adaptive_smc supplies β by tempering
log_likelihood + log_factors, applying it exactly once.
Sourcepub fn sample_prior<R: Rng>(&self, rng: &mut R) -> P::Genome
pub fn sample_prior<R: Rng>(&self, rng: &mut R) -> P::Genome
Draw a genome from the prior p(x) by running the prior program.
Sourcepub fn score(&self, genome: &P::Genome) -> (P::Genome, Trace)
pub fn score(&self, genome: &P::Genome) -> (P::Genome, Trace)
Score a genome under the fixed-β target by replaying its encoding
under this model’s prior (GenomePrior::trace_of) through the
target program — so this works for every prior, including generative
grammars over trees.
The returned trace satisfies log π_β(g) = trace.total_log_weight()
and log p(g) = trace.log_prior. A genome outside the prior’s support
scores log_prior = −∞.
Note: if the likelihood contains latent nuisance sites, they are not
part of trace_of(g) and would abort a strict replay — score via the
SMC/MH drivers in that case (which sample them), or marginalize them
externally.
Sourcepub fn log_boltzmann_target(&self, genome: &P::Genome) -> f64
pub fn log_boltzmann_target(&self, genome: &P::Genome) -> f64
Unnormalised log target log π_β(x) = log p(x) + β·log p(data|x).
Trait Implementations§
Source§impl<P, L> Clone for EvolutionModel<P, L>
impl<P, L> Clone for EvolutionModel<P, L>
Source§fn clone(&self) -> EvolutionModel<P, L>
fn clone(&self) -> EvolutionModel<P, L>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<P, L> Freeze for EvolutionModel<P, L>
impl<P, L> RefUnwindSafe for EvolutionModel<P, L>where
P: RefUnwindSafe,
L: RefUnwindSafe,
impl<P, L> Send for EvolutionModel<P, L>
impl<P, L> Sync for EvolutionModel<P, L>
impl<P, L> Unpin for EvolutionModel<P, L>
impl<P, L> UnsafeUnpin for EvolutionModel<P, L>where
P: UnsafeUnpin,
L: UnsafeUnpin,
impl<P, L> UnwindSafe for EvolutionModel<P, L>where
P: UnwindSafe,
L: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.