pub struct ReparamGradEstimator {
pub config: ReparamGradConfig,
pub baseline: f64,
pub n_estimates: usize,
pub grad_variance: Vec<f64>,
}Expand description
Reparameterization gradient estimator for ELBO optimization
This struct provides a clean interface for estimating the gradient of the ELBO using the reparameterization trick. It supports:
- Vanilla reparameterization: z = f(epsilon; phi), grad_phi ELBO via chain rule
- Variance reduction with control variates: Uses an exponential moving average baseline to reduce gradient variance
- Rao-Blackwellization: Analytically marginalizes when possible
Fields§
§config: ReparamGradConfigConfiguration
baseline: f64Baseline value for control variate (exponential moving average of ELBO)
n_estimates: usizeTotal number of gradient estimates computed
grad_variance: Vec<f64>Running estimate of gradient variance (per-parameter)
Implementations§
Source§impl ReparamGradEstimator
impl ReparamGradEstimator
Sourcepub fn new(config: ReparamGradConfig) -> Self
pub fn new(config: ReparamGradConfig) -> Self
Create a new reparameterization gradient estimator
Sourcepub fn estimate<F>(
&mut self,
family: &dyn VariationalFamily,
log_joint_fn: F,
step: usize,
) -> Result<(f64, Array1<f64>)>
pub fn estimate<F>( &mut self, family: &dyn VariationalFamily, log_joint_fn: F, step: usize, ) -> Result<(f64, Array1<f64>)>
Estimate the ELBO gradient w.r.t. variational parameters phi.
Uses the reparameterization trick: grad_phi E_q[f(z)] = E_{epsilon}[grad_phi f(g(epsilon; phi))] where z = g(epsilon; phi) is the reparameterization.
§Arguments
family: The variational family q(z; phi)log_joint_fn: Closure returning (log p(x,z), grad_z log p(x,z))step: Current optimization step (for seed variation)
§Returns
(elbo_estimate, grad_phi)
Sourcepub fn gradient_snr(&self) -> Vec<f64>
pub fn gradient_snr(&self) -> Vec<f64>
Compute the signal-to-noise ratio (SNR) of the gradient estimate.
High SNR (> 1) indicates stable gradient estimates. Low SNR suggests increasing n_samples or using variance reduction.
Trait Implementations§
Source§impl Clone for ReparamGradEstimator
impl Clone for ReparamGradEstimator
Source§fn clone(&self) -> ReparamGradEstimator
fn clone(&self) -> ReparamGradEstimator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ReparamGradEstimator
impl RefUnwindSafe for ReparamGradEstimator
impl Send for ReparamGradEstimator
impl Sync for ReparamGradEstimator
impl Unpin for ReparamGradEstimator
impl UnsafeUnpin for ReparamGradEstimator
impl UnwindSafe for ReparamGradEstimator
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
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>
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.