VariationalParam

Enum VariationalParam 

Source
pub enum VariationalParam {
    Normal {
        mu: f64,
        log_sigma: f64,
    },
    LogNormal {
        mu: f64,
        log_sigma: f64,
    },
    Beta {
        log_alpha: f64,
        log_beta: f64,
    },
}
Expand description

Variational distribution parameters for a single random variable.

Each random variable in the model gets its own variational distribution that approximates its marginal posterior. The parameters are stored in log-space for numerical stability and to ensure positive constraints.

§Variants

  • Normal - Gaussian approximation with mean and log-standard-deviation
  • LogNormal - Log-normal approximation for positive variables
  • Beta - Beta approximation for variables constrained to [0,1]

§Examples

use fugue::*;
use rand::rngs::StdRng;
use rand::SeedableRng;

// Create variational parameters
let normal_param = VariationalParam::Normal {
    mu: 1.5,
    log_sigma: -0.693  // sigma = 0.5
};

let beta_param = VariationalParam::Beta {
    log_alpha: 1.099,  // alpha = 3.0
    log_beta: 0.693,   // beta = 2.0
};

// Sample from variational distribution
let mut rng = StdRng::seed_from_u64(42);
let sample = normal_param.sample(&mut rng);
let log_prob = normal_param.log_prob(sample);

Variants§

§

Normal

Normal/Gaussian variational distribution.

Fields

§mu: f64

Mean parameter.

§log_sigma: f64

Log of standard deviation (for positivity).

§

LogNormal

Log-normal variational distribution for positive variables.

Fields

§mu: f64

Mean of underlying normal.

§log_sigma: f64

Log of standard deviation of underlying normal.

§

Beta

Beta variational distribution for variables in [0,1].

Fields

§log_alpha: f64

Log of first shape parameter (for positivity).

§log_beta: f64

Log of second shape parameter (for positivity).

Implementations§

Source§

impl VariationalParam

Source

pub fn sample<R: Rng>(&self, rng: &mut R) -> f64

Sample a value from this variational distribution with numerical stability.

Generates a random sample using the current variational parameters. This version includes parameter validation and numerical stability checks.

§Arguments
  • rng - Random number generator
§Returns

A sample from the variational distribution, or NaN if parameters are invalid.

Source

pub fn sample_with_aux<R: Rng>(&self, rng: &mut R) -> (f64, f64)

Sample with reparameterization for gradient computation (experimental).

Returns both the sample and auxiliary information needed for computing gradients via the reparameterization trick.

Source

pub fn log_prob(&self, x: f64) -> f64

Compute log-probability of a value under this variational distribution.

This is used for computing entropy terms in the ELBO and for evaluating the quality of the variational approximation. Now includes numerical stability checks.

§Arguments
  • x - Value to evaluate
§Returns

Log-probability density at the given value.

Trait Implementations§

Source§

impl Clone for VariationalParam

Source§

fn clone(&self) -> VariationalParam

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VariationalParam

Source§

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

Formats the value using the given formatter. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V