Skip to main content

Module vmp

Module vmp 

Source
Expand description

Variational Message Passing (VMP) for conjugate exponential families.

This module implements the algorithm of Winn & Bishop (2005) for the three families shipped in the v0.2.0 research preview — Gaussian (mean-unknown, precision-known), Categorical, and Dirichlet — along with their conjugate factor relationships (Gaussian observation, Gaussian step, Dirichlet-Categorical, Categorical observation).

All updates happen in natural-parameter space. The engine drives a coordinate-ascent loop that monotonically increases the evidence lower bound (ELBO) until either |ΔELBO| or the L∞ residual of the natural-parameter vectors falls below the configured tolerance. Divergence (an ELBO decrease beyond divergence_tolerance) surfaces as a crate::PgmError::ConvergenceFailure so a numerically broken run never silently returns a garbage posterior.

§Module map

SubmodulePurpose
exponential_familyTrait contract every VMP-compatible distribution satisfies
distributionsGaussianNP, CategoricalNP, DirichletNP + KL helpers
messagesVmpMessage / MessageDirection primitives
engineVmpConfig + VariationalMessagePassing coordinate engine
specialLocal ln_gamma / digamma (scirs2-core free)

§Minimal example

use tensorlogic_quantrs_hooks::vmp::{
    VariationalMessagePassing, VmpConfig, VmpFactor,
};

// y ~ N(μ, 1) with one observation y = 3, prior μ ~ N(0, 1).
let config = VmpConfig::new()
    .with_gaussian("mu", 0.0, 1.0).expect("register mu")
    .with_factor(VmpFactor::GaussianObservation {
        target: "mu".to_string(),
        observation: 3.0,
        precision: 1.0,
    })
    .with_limits(50, 1e-8);

let mut engine = VariationalMessagePassing::new(config).expect("engine");
let result = engine.run().expect("run");
assert!(result.converged);

§References

  • Winn, J. M. & Bishop, C. M. (2005). Variational Message Passing. Journal of Machine Learning Research 6, 661-694.

Re-exports§

pub use beta::BetaBernoulliObservation;
pub use beta::BetaNP;
pub use distributions::categorical_kl;
pub use distributions::dirichlet_kl;
pub use distributions::gaussian_kl;
pub use distributions::gaussian_kl_fixed_precision;
pub use distributions::CategoricalNP;
pub use distributions::DirichletNP;
pub use distributions::GaussianNP;
pub use engine::Family;
pub use engine::VariationalMessagePassing;
pub use engine::VariationalState;
pub use engine::VmpConfig;
pub use engine::VmpFactor;
pub use engine::VmpResult;
pub use exponential_family::ExponentialFamily;
pub use gamma::GammaNP;
pub use gamma::GammaPoissonObservation;
pub use messages::MessageDirection;
pub use messages::VmpMessage;

Modules§

beta
Beta natural parameters for Variational Message Passing.
distributions
Concrete ExponentialFamily implementations shipped with the v0.2.0 VMP research preview.
engine
Variational Message Passing engine.
exponential_family
Exponential family trait for Variational Message Passing.
gamma
Gamma natural parameters for Variational Message Passing.
messages
Natural-parameter messages for Variational Message Passing.
special
Local implementations of the special functions Dirichlet / Categorical VMP depend on (log-gamma and digamma).