Skip to main content

EvolutionModel

Struct EvolutionModel 

Source
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>>
where P: GenomePrior, F: Fitness<Genome = P::Genome, Value = f64> + Clone + Send + Sync + 'static,

Source

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.

Source

pub fn fitness_value(&self, genome: &P::Genome) -> f64

Raw fitness f(x) (higher is better).

Source

pub fn log_weight(&self, genome: &P::Genome) -> f64

The tempered fitness log-factor β · f(x).

Source

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>

Source

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.

Source

pub fn with_beta(self, beta: f64) -> Self

Set the inverse temperature β directly (β ≥ 0).

Source

pub fn with_temperature(self, temperature: f64) -> Self

Set the temperature T; equivalent to β = 1/T.

Source

pub fn beta(&self) -> f64

Current inverse temperature β.

Source

pub fn temperature(&self) -> f64

Current temperature T = 1/β.

Source

pub fn prior(&self) -> &P

The prior program.

Source

pub fn likelihood(&self) -> &L

The observation program.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source§

fn clone(&self) -> EvolutionModel<P, L>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<P, L> Freeze for EvolutionModel<P, L>
where P: Freeze, L: Freeze,

§

impl<P, L> RefUnwindSafe for EvolutionModel<P, L>

§

impl<P, L> Send for EvolutionModel<P, L>

§

impl<P, L> Sync for EvolutionModel<P, L>

§

impl<P, L> Unpin for EvolutionModel<P, L>
where P: Unpin, L: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V