Marginal implementation

Marginal type

All marginals are encoded with the type Marginal.

ReactiveMP.MarginalType
Marginal(data, is_clamped, is_initial, addons)

An implementation of a marginal in variational message passing framework.

Arguments

  • data::D: marginal always holds some data object associated with it, which is usually a probability distribution
  • is_clamped::Bool, specifies if this marginal was the result of constant computations (e.g. clamped constants)
  • is_initial::Bool, specifies if this marginal was used for initialization
  • addons::A, specifies the addons of the marginal, which may carry extra bits of information, e.g. debug information, memory, etc.

Example

julia> distribution = Gamma(10.0, 2.0)
Distributions.Gamma{Float64}(α=10.0, θ=2.0)

julia> message = Marginal(distribution, false, true, nothing)
Marginal(Distributions.Gamma{Float64}(α=10.0, θ=2.0))

julia> mean(message) 
20.0

julia> getdata(message)
Distributions.Gamma{Float64}(α=10.0, θ=2.0)

julia> is_clamped(message)
false

julia> is_initial(message)
true
source

From an implementation point a view the Marginal structure does nothing but hold some data object and redirects most of the statistical related functions to that data object. However, this object is used extensively in Julia's multiple dispatch.

ReactiveMP.to_marginalFunction
to_marginal(any)

Transforms an input to a proper marginal distribution. Called inside as_marginal. Some nodes do not use Distributions.jl, but instead implement their own equivalents for messages for better efficiency. Effectively to_marginal is needed to convert internal effective implementation to a user-friendly equivalent (e.g. from Distributions.jl). By default does nothing and returns its input, but some nodes may override this behaviour (see for example Wishart and InverseWishart).

Note: This function is a part of the private API and is not intended to be used outside of the ReactiveMP package.

source
using ReactiveMP, BayesBase, ExponentialFamily

distribution  = ExponentialFamily.NormalMeanPrecision(0.0, 1.0)
marginal      = Marginal(distribution, false, true, nothing)
Marginal(ExponentialFamily.NormalMeanPrecision{Float64}(μ=0.0, w=1.0))
mean(marginal), precision(marginal)
(0.0, 1.0)
logpdf(marginal, 1.0)
-1.4189385332046727
is_clamped(marginal), is_initial(marginal)
(false, true)