Messages implementation

In message passing framework one of the most important concepts is (wow!) messages. Messages flow on edges of a factor graph and usually hold some information in a form of probability distribution. In ReactiveMP.jl we distinguish two major types of messages: Belief Propagation and Variational.

Abstract message type

Both belief propagation and variational messages are subtypes of a AbstractMessage supertype.

Belief-Propagation (or Sum-Product) message

Belief propagation messages are encoded with type Message.

message Belief propagation message

Message{D, A} <: AbstractMessage

Message structure encodes a Belief Propagation message, which holds some data that usually a probability distribution, but can also be an arbitrary object. Message acts as a proxy structure to data object and proxies most of the statistical functions, e.g. mean, mode, cov etc.


  • data::D: message always holds some data object associated with it
  • is_clamped::Bool, specifies if this message is clamped
  • is_initial::Bool, specifies if this message is initial
  • addons::A, specifies the addons of the message


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

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

julia> mean(message) 

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

julia> is_clamped(message)

julia> is_initial(message)

See also: AbstractMessage, materialize!


From implementation point a view Message structure does nothing but holds some data object and redirects most of the statistical related functions to that data object. However it used extensively in Julia's multiple dispatch. Implementation also uses extra is_initial and is_clamped fields to determine if product of two messages results in is_initial or is_clamped posterior marginal.

distribution = NormalMeanPrecision(0.0, 1.0)
message      = Message(distribution, false, true, nothing)
Message(NormalMeanPrecision{Float64}(μ=0.0, w=1.0))
mean(message), precision(message)
(0.0, 1.0)
logpdf(message, 1.0)
is_clamped(message), is_initial(message)
(false, true)

The user should not really interact with Message structure while working with ReactiveMP unless doing some advanced inference procedures that involve prediction.

Variational message

Variational messages are encoded with type VariationalMessage.

message Variational message with structured factorisation q(x, y)q(z) assumption