Skip to main content

TastePosterior

Struct TastePosterior 

Source
pub struct TastePosterior {
    pub cfg: TasteConfig,
    pub samples: Vec<TasteSample>,
    pub weights: Vec<f64>,
}
Expand description

A fitted posterior: thinned MCMC draws, their importance weights, and summaries. Weights are uniform straight out of a fit and concentrate as TastePosterior::reweighted folds in observations between fits.

Fields§

§cfg: TasteConfig

The config this posterior was fit under.

§samples: Vec<TasteSample>

Thinned posterior draws.

§weights: Vec<f64>

Normalized importance weights, parallel to samples. Empty means uniform (and is what older persisted posteriors deserialize to).

Implementations§

Source§

impl TastePosterior

Source

pub fn k_styles(&self) -> usize

Number of style components.

Source

pub fn weight(&self, i: usize) -> f64

Importance weight of draw i (uniform when no weights are stored).

Source

pub fn ess(&self) -> f64

Effective sample size of the weighted draws, 1 / Σ wₛ². Equals the draw count for uniform weights and collapses toward 1 as the weights concentrate — the trigger for paying for a full MCMC refit.

Source

pub fn resampled(&self) -> TastePosterior

Systematic resampling: draw the weighted set back to a uniformly weighted one of the same size, deterministically.

Importance weights degenerate — after enough updates almost all the mass sits on one draw, and a “posterior” of one point tells the acquisition function that it is certain when it is merely exhausted. Resampling trades that for duplicate draws, which is the honest cost: the sample is impoverished but still spans the posterior’s support, and Self::ess on the fresh uniform weights no longer claims more information than is there. It is a stopgap between full refits, not a substitute for one; Engine::needs_refit is still the thing to watch.

Deterministic (systematic, offset ½N) rather than multinomial, because every other stochastic step in this engine is seeded and reproducible and this one has no reason not to be.

Source

pub fn reweighted(&self, feedback: &Feedback, session: usize) -> TastePosterior

Fold one new standardized observation into the weights by sequential importance sampling: w_s ← w_s · p(y | θ_s), renormalized.

This is what makes each duel respond to the one before it. A full refit costs seconds of MCMC and cannot run per-vote; without this the acquisition function reads a frozen posterior and re-asks the same question until the next refit.

Source

pub fn aligned(&self) -> TastePosterior

Resolve label switching: relabel each sample’s styles to best match a reference (the last sample, then one refinement pass against the aligned mean), by total θ cosine similarity. Per-style summaries (Self::theta_mean etc.) are only meaningful on an aligned posterior. No-op at K = 1. K is assumed small (≤ 5): alignment is exhaustive over permutations.

Source

pub fn theta_mean(&self, style: usize) -> Vec<f64>

Posterior mean of θ for a style (align first at K > 1).

Source

pub fn theta_std(&self, style: usize) -> Vec<f64>

Per-dimension posterior std of θ for a style (credible-interval widths for taste instrumentation; align first at K > 1).

Source

pub fn style_share(&self, phis: &[Vec<f64>]) -> Vec<f64>

Share of the given candidates claimed by each style: for each φ, the posterior probability that style k is its best lens, averaged over candidates. A style with ≈0 share is inactive — the user’s taste has fewer islands than K. Align first at K > 1.

Source

pub fn utility(&self, phi: &[f64], style: usize) -> (f64, f64)

Posterior mean and std of the per-style utility u_k(φ).

Source

pub fn utility_mix(&self, phi: &[f64]) -> (f64, f64)

Posterior mean and std of the mixture utility (the ranking score).

Source

pub fn responsibilities(&self, phi: &[f64]) -> Vec<f64>

Style responsibilities of a candidate: the posterior probability that each style is its best lens (align first at K > 1).

Source

pub fn prob_prefers(&self, a: &[f64], b: &[f64]) -> f64

Posterior probability that candidate a beats candidate b in a duel (marginalizing θ, weights, and the per-observation lens).

Source

pub fn save(&self, path: &Path) -> Result<()>

Serialize to a JSON file (posterior snapshot; the log remains the source of truth).

Source

pub fn load(path: &Path) -> Result<Self>

Load from a JSON file.

Trait Implementations§

Source§

impl Clone for TastePosterior

Source§

fn clone(&self) -> TastePosterior

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 TastePosterior

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for TastePosterior

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TastePosterior

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

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