pub struct GammaMatrix { /* private fields */ }Implementations§
Source§impl GammaMatrix
impl GammaMatrix
Sourcepub fn release_stats(&mut self)
pub fn release_stats(&mut self)
Drop the sufficient-stat planes (a_stat / b_stat) after
calibration, keeping only the posterior estimates. Use when the
consumer reads posterior means / log-means but never
posterior_sample (which is the only reader of a_stat/b_stat).
Halves the resident footprint of a calibrated parameter.
Sourcepub fn sparsify_mean_to_support(&mut self, numerator: &DMatrix<f32>)
pub fn sparsify_mean_to_support(&mut self, numerator: &DMatrix<f32>)
Zero every estimated_mean entry whose corresponding numerator is
zero, collapsing the per-column Gamma prior baseline (a0/denom,
present at every unobserved cell) to exact zero. This lets a
downstream triplet-ization of the mean be sparse — only the
observed support survives. It’s the lossy-but-correct choice for
count-based consumers (the baseline is a regularization floor, not
signal). numerator must match the mean’s shape; only meaningful
after a mean calibration.
Sourcepub fn has_data_support(&self, row: usize, col: usize) -> bool
pub fn has_data_support(&self, row: usize, col: usize) -> bool
Whether the posterior at (row, col) carries any data beyond the
prior: a_stat > a0. The read-only counterpart of
Self::sparsify_mean_to_support, for consumers that serialize the
mean without owning the numerator — an unsupported entry’s mean is the
prior floor a0 / (b0 + denom), which is regularization, not signal.
Writing those floors out turns a sparse posterior dense: a carried
pseudobulk reference measured 100.0% dense (34M of 34M entries) before
its writer checked this.
Sourcepub fn evidence_mean(&self, row: usize, col: usize) -> f32
pub fn evidence_mean(&self, row: usize, col: usize) -> f32
The unregularized rate at (row, col): (a_stat − a0) / (b_stat − b0)
— data sum over data denominator, no prior in either. Zero when the
entry has no data support.
This is what a serialized posterior should usually store: paired with
its denominator, it is a bijection of the sufficient statistics, so a
consumer reconstructs a_stat/b_stat exactly. The posterior mean
(a0 + sum)/(b0 + n) is the right estimate but the wrong carrier —
its prior shrinkage (1.85× at sum = 1, n = 12) gets re-ingested as if
it were data, and a second posterior forms around an already-shrunk
value.
Sourcepub fn with_row_prior(
dims: (usize, usize),
a0: &DVector<f32>,
b0: &DVector<f32>,
) -> Self
pub fn with_row_prior( dims: (usize, usize), a0: &DVector<f32>, b0: &DVector<f32>, ) -> Self
A matrix whose row d has prior Gamma(a0[d], b0[d]). The statistics
start at the prior, as with TwoStatParam::new.
Sourcepub fn set_row_prior(&mut self, a0: &DVector<f32>, b0: &DVector<f32>)
pub fn set_row_prior(&mut self, a0: &DVector<f32>, b0: &DVector<f32>)
Replace the per-row prior. Accumulated statistics are left as they
are; the new prior applies at the next reset_stat / update_stat.
Sourcepub fn row_prior(&self) -> Option<(&DVector<f32>, &DVector<f32>)>
pub fn row_prior(&self) -> Option<(&DVector<f32>, &DVector<f32>)>
The per-row prior, if one is set.
Sourcepub fn vconcat(blocks: Vec<GammaMatrix>, stack_stats: bool) -> Self
pub fn vconcat(blocks: Vec<GammaMatrix>, stack_stats: bool) -> Self
Row-stack per-feature-block parameters (from a gene-blocked fit)
into one [Σrowsᵢ × K] parameter. All blocks must share the column
count and either share the scalar hyper-params or all carry a row
prior, in which case the row priors are concatenated. Calibrated
planes present in the first block
are stacked; lazily-empty planes stay empty. stack_stats controls
whether a_stat/b_stat are carried through — pass false when the
output only needs posterior estimates, so the heavy sufficient-stat
planes are never assembled at full width.
Trait Implementations§
Source§impl Clone for GammaMatrix
impl Clone for GammaMatrix
Source§impl Debug for GammaMatrix
impl Debug for GammaMatrix
Source§impl Inference for GammaMatrix
impl Inference for GammaMatrix
type Mat = Matrix<f32, Dyn, Dyn, VecStorage<f32, Dyn, Dyn>>
type Scalar = f32
fn posterior_mean(&self) -> &Self::Mat
fn posterior_sd(&self) -> &Self::Mat
fn posterior_log_mean(&self) -> &Self::Mat
fn posterior_log_sd(&self) -> &Self::Mat
fn posterior_sample(&self) -> Result<Self::Mat>
Source§fn posterior_log_sample(&self, seed: u64) -> Result<Self::Mat>
fn posterior_log_sample(&self, seed: u64) -> Result<Self::Mat>
log λ per element. Delta-method
approximation: log λ ≈ Normal(posterior_log_mean, posterior_log_sd²). Caller must have called
calibrate_with(CalibrateTarget::All) first so log_mean / log_sd
are populated. Read morefn nrows(&self) -> usize
fn ncols(&self) -> usize
Source§impl ParamIo for GammaMatrix
impl ParamIo for GammaMatrix
Source§impl TwoStatParam for GammaMatrix
impl TwoStatParam for GammaMatrix
type Mat = Matrix<f32, Dyn, Dyn, VecStorage<f32, Dyn, Dyn>>
type Scalar = f32
fn new(dims: (usize, usize), a: Self::Scalar, b: Self::Scalar) -> Self
fn add_stat(&mut self, add_a: &Self::Mat, add_b: &Self::Mat)
fn update_stat(&mut self, update_a: &Self::Mat, update_b: &Self::Mat)
fn reset_stat(&mut self)
fn update_stat_col( &mut self, update_a: &Self::Mat, update_b: &Self::Mat, k: usize, )
fn map_calibrate_mean(&mut self)
fn map_calibrate_sd(&mut self)
fn map_calibrate_log_mean(&mut self)
fn map_calibrate_log_sd(&mut self)
Source§fn calibrate_with(&mut self, target: CalibrateTarget)
fn calibrate_with(&mut self, target: CalibrateTarget)
target.Auto Trait Implementations§
impl Freeze for GammaMatrix
impl RefUnwindSafe for GammaMatrix
impl Send for GammaMatrix
impl Sync for GammaMatrix
impl Unpin for GammaMatrix
impl UnsafeUnpin for GammaMatrix
impl UnwindSafe for GammaMatrix
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.