Skip to main content

TasteModel

Struct TasteModel 

Source
pub struct TasteModel {
    pub cfg: TasteConfig,
}
Expand description

The taste model: prior over latents + observation-log likelihood.

Fields§

§cfg: TasteConfig

Configuration.

Implementations§

Source§

impl TasteModel

Source

pub fn new(cfg: TasteConfig) -> Self

Build with the given config.

Source

pub fn model(&self, data: &FitSet) -> Model<TasteSample>

The fugue program. Returns the decoded TasteSample; the observation likelihood enters as a single factor.

Builds a fresh SiteAddrs each call, so it is the right entry point for one-shot uses (Self::prior_sample). Inference paths that rebuild the program per step must hoist the table out of the loop and call Self::model_at — that is what Self::fit does.

Source

pub fn model_at( &self, data: &FitSet, addrs: &Arc<SiteAddrs>, ) -> Model<TasteSample>

The fugue program over a precomputed address table.

addrs must have been built by SiteAddrs::new from this model’s config and this data’s session count; it is cheap to clone and is intended to be built once per fit and shared across every MH step.

The observation list and the address table both ride in Arc: the model is reconstructed every MH step, and this keeps that reconstruction O(1) in the log size and allocation-free in the address count.

Source

pub fn fit<R: Rng>( &self, rng: &mut R, data: &FitSet, n_samples: usize, n_warmup: usize, ) -> TastePosterior

Fit the posterior by adaptive single-site MH.

n_samples post-warmup draws are kept (thinned to at most 500 for summary storage). Each MH step moves one site, so budget steps ≈ sites × desired effective sweeps.

§The chain is thinned at the driver, not after it

97 % of the chain is discarded, and it is discarded as it is produced. That used to happen one line after the whole chain was built: adaptive_mcmc_chain materialized every step — a (TasteSample, Trace) per iteration pushed into a Vec returned by value — and only then did step_by(stride) keep every 20th. At K = 5 that is ~10 000 Trace clones of 206 BTreeMap entries held live at once to keep 500, scaling with n_samples: a plausible mobile-Safari OOM rather than mere waste on a 32-bit heap.

It could not be fixed here — the retention was inside fugue’s chain driver, and the pieces needed to reimplement that driver with identical RNG consumption (single_site_mh_step, propose_and_score, SingleSiteProposalHandler) are private or pub(crate). So it was fixed there: adaptive_mcmc_chain_thinned (fugue-ppl 0.2.2) takes a stride and pushes only on i % thin == 0.

The draws are bit-identical to what the old code returned. thin gates the push and nothing else: every transition still runs, so the RNG is consumed in the same order and quantity, and 0, stride, 2·stride, … is exactly what step_by(stride) kept. fit_bench’s per-fit checksum is the auracle-side witness; fugue’s own thinning_retains_exactly_the_draws_step_by_would is the upstream one.

Measured, fit_bench 10000 3000 under /usr/bin/time -l:

peak RSSmature-fit checksum
before303.1 MB07d204764b58c88b
after18.2 MB07d204764b58c88b

16.7× less peak memory for the same draws — the checksum is the point of that table, not a footnote to it. What stays resident is the 500 draws the posterior actually keeps, so the peak no longer scales with mcmc_samples at all: the budget is free to be chosen on the recovery tables (SessionConfig::mcmc_samples) rather than against a memory ceiling.

Source

pub fn prior_sample<R: Rng>(&self, rng: &mut R, data: &FitSet) -> TasteSample

Draw one prior sample (useful for prior-predictive checks).

Trait Implementations§

Source§

impl Clone for TasteModel

Source§

fn clone(&self) -> TasteModel

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

impl Debug for TasteModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,