pub struct StochasticVI {
pub variational: MeanFieldGaussian,
pub config: SviConfig,
pub diagnostics: VariationalDiagnostics,
/* private fields */
}Expand description
Stochastic Variational Inference (SVI)
Implements scalable variational inference using stochastic gradient ascent on the ELBO. Supports:
- Mini-batch ELBO estimation for large datasets
- Natural gradient updates for faster convergence
- Adam adaptive learning rates
- Gradient clipping for stability
The model assumes a mean-field Gaussian posterior approximation q(z) = prod_i N(z_i; mu_i, sigma_i^2)
The user provides a log joint density function log p(z, x_batch) that takes the latent variables z and a mini-batch of data.
Fields§
§variational: MeanFieldGaussianVariational distribution (mean-field Gaussian)
config: SviConfigConfiguration
diagnostics: VariationalDiagnosticsDiagnostics
Implementations§
Source§impl StochasticVI
impl StochasticVI
Sourcepub fn fit<F>(
&mut self,
data: ArrayView2<'_, f64>,
log_joint: F,
n_total: usize,
) -> Result<SviResult>
pub fn fit<F>( &mut self, data: ArrayView2<'_, f64>, log_joint: F, n_total: usize, ) -> Result<SviResult>
Run SVI optimization with a log joint density function
§Arguments
data- Full dataset (rows are observations)log_joint- Function computing log p(z, x_batch) given latent variables and a batch of data. Returns (log_prob, gradient_wrt_z).n_total- Total number of data points (for scaling mini-batch ELBO)
§Returns
- The optimized variational distribution and diagnostics
Sourcepub fn variational_distribution(&self) -> &MeanFieldGaussian
pub fn variational_distribution(&self) -> &MeanFieldGaussian
Get the current variational distribution
Sourcepub fn diagnostics(&self) -> &VariationalDiagnostics
pub fn diagnostics(&self) -> &VariationalDiagnostics
Get diagnostics
Sourcepub fn reset_optimizer(&mut self)
pub fn reset_optimizer(&mut self)
Reset the optimizer state (useful for warm restarts)
Trait Implementations§
Source§impl Clone for StochasticVI
impl Clone for StochasticVI
Source§fn clone(&self) -> StochasticVI
fn clone(&self) -> StochasticVI
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for StochasticVI
impl RefUnwindSafe for StochasticVI
impl Send for StochasticVI
impl Sync for StochasticVI
impl Unpin for StochasticVI
impl UnsafeUnpin for StochasticVI
impl UnwindSafe for StochasticVI
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
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,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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 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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.