pub struct BetaVI {
pub dim: usize,
pub log_alpha: Array1<f64>,
pub log_beta: Array1<f64>,
}Expand description
Variational family using a Beta distribution for probability-valued variables in [0,1]
z_i ~ Beta(alpha_i, beta_i) independently.
Parameterization: we store log(alpha_i) and log(beta_i) so that alpha, beta > 0.
Note: The reparameterization trick for Beta is approximate; we use the Kumaraswamy distribution as a surrogate (which has a simple inverse CDF). The entropy and log_prob use the exact Beta formulas.
Parameters (stored in flat form): [log_alpha_0, …, log_alpha_{d-1}, log_beta_0, …, log_beta_{d-1}]
Fields§
§dim: usizeDimension of the latent variable
log_alpha: Array1<f64>Log concentration parameters: log_alpha_i (alpha_i = exp(log_alpha_i) > 0)
log_beta: Array1<f64>Log concentration parameters: log_beta_i (beta_i = exp(log_beta_i) > 0)
Implementations§
Source§impl BetaVI
impl BetaVI
Sourcepub fn new(dim: usize) -> Result<Self>
pub fn new(dim: usize) -> Result<Self>
Create a new Beta variational family
Initializes with alpha=1, beta=1 (uniform distribution).
Sourcepub fn from_alpha_beta(alpha: Array1<f64>, beta: Array1<f64>) -> Result<Self>
pub fn from_alpha_beta(alpha: Array1<f64>, beta: Array1<f64>) -> Result<Self>
Create from explicit alpha and beta parameters (both must be > 0)
Sourcepub fn variances(&self) -> Array1<f64>
pub fn variances(&self) -> Array1<f64>
Compute the variance Var[z_i] = alphabeta / ((alpha+beta)^2(alpha+beta+1))
Sourcepub fn kl_to_uniform(&self) -> f64
pub fn kl_to_uniform(&self) -> f64
Compute KL divergence to the uniform prior Beta(1,1) analytically.
KL(Beta(a,b) || Uniform) = KL(Beta(a,b) || Beta(1,1)) = sum_i [(a_i-1)*psi(a_i) + (b_i-1)*psi(b_i) - (a_i+b_i-2)*psi(a_i+b_i) + log_B(1,1) - log_B(a_i, b_i)]
where log_B(a,b) = lgamma(a) + lgamma(b) - lgamma(a+b), and log_B(1,1) = 0.
Trait Implementations§
Source§impl VariationalFamily for BetaVI
impl VariationalFamily for BetaVI
Source§fn get_params(&self) -> Array1<f64>
fn get_params(&self) -> Array1<f64>
Source§fn set_params(&mut self, params: &Array1<f64>) -> Result<()>
fn set_params(&mut self, params: &Array1<f64>) -> Result<()>
Source§fn sample_reparam(&self, epsilon: &Array1<f64>) -> Result<(Array1<f64>, f64)>
fn sample_reparam(&self, epsilon: &Array1<f64>) -> Result<(Array1<f64>, f64)>
Auto Trait Implementations§
impl Freeze for BetaVI
impl RefUnwindSafe for BetaVI
impl Send for BetaVI
impl Sync for BetaVI
impl Unpin for BetaVI
impl UnsafeUnpin for BetaVI
impl UnwindSafe for BetaVI
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.