pub struct TasteModel {
pub cfg: TasteConfig,
}Expand description
The taste model: prior over latents + observation-log likelihood.
Fields§
§cfg: TasteConfigConfiguration.
Implementations§
Source§impl TasteModel
impl TasteModel
Sourcepub fn new(cfg: TasteConfig) -> Self
pub fn new(cfg: TasteConfig) -> Self
Build with the given config.
Sourcepub fn model(&self, data: &FitSet) -> Model<TasteSample>
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.
Sourcepub fn model_at(
&self,
data: &FitSet,
addrs: &Arc<SiteAddrs>,
) -> Model<TasteSample>
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.
Sourcepub fn fit<R: Rng>(
&self,
rng: &mut R,
data: &FitSet,
n_samples: usize,
n_warmup: usize,
) -> TastePosterior
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 RSS | mature-fit checksum | |
|---|---|---|
| before | 303.1 MB | 07d204764b58c88b |
| after | 18.2 MB | 07d204764b58c88b |
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.
Sourcepub fn prior_sample<R: Rng>(&self, rng: &mut R, data: &FitSet) -> TasteSample
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
impl Clone for TasteModel
Source§fn clone(&self) -> TasteModel
fn clone(&self) -> TasteModel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more