Delta node
ReactiveMP.DeltaMeta
— TypeDeltaMeta(method = ..., [ inverse = ... ])
DeltaMeta
structure specifies the approximation method for the outbound messages in the DeltaFn
node.
Arguments
method
: required, the approximation method, currently supported methods areLinearization
,Unscented
andCVI
.inverse
: optional, if no inverse provided, the backward rule will be computed based on RTS (Petersen et al. 2018; On Approximate Delta Gaussian Message Passing on Factor Graphs)
Is is also possible to pass the AbstractApproximationMethod
to the meta of the delta node directly. In this case inverse
is set to nothing
.
ReactiveMP.ManyOf
— TypeSome nodes use IndexedInterface
, ManyOf
structure reflects a collection of marginals from the collection of IndexedInterface
s. @rule
macro also treats ManyOf
specially.
ReactiveMP.Linearization
— TypeThe Linearization
structure defines the approximation method of the Delta
and Flow
factor nodes. This method performs a local linearization of f around expansion point x.
The Linearization
structure with default parameters can be constructed as Linearization()
.
The Linearization
structure is used inside the DeltaMeta
or FlowMeta
structures and can be included as:
y ~ f(x) where { meta = DeltaMeta(method = Linearization()) }
# or
y ~ Flow(x) where { meta = FlowMeta(flowmodel, Linearization()) }
ReactiveMP.local_linearization
— Functionlocal_linearization(g, x)
Returns linear components (a, b)
for the function g
at the point x
.
ReactiveMP.smoothRTS
— FunctionRTS smoother update for inbound marginal; based on (Petersen et al. 2018; On Approximate Delta Gaussian Message Passing on Factor Graphs)
ReactiveMP.Unscented
— TypeThe Unscented
structure defines the approximation method of the Delta
and Flow
factor nodes. More specifically, it contains the hyperparameters used for sigma points computation.
Arguments
α
: Spread parameter for unscented transform #1β
: Algorithm parameter for incorporating prior information on the (non-Gaussian) distribution of Delta node inputκ
: Spread parameter for unscented transform #2e
: Internal cache
The Unscented
structure with default parameters can be constructed as Unscented()
.
The Unscented
structure is used inside the DeltaMeta
or FlowMeta
structure and can be included as:
y ~ f(x) where { meta = DeltaMeta(method = Unscented()) }
# or
y ~ Flow(x) where { meta = FlowMeta(flowmodel, Unscented()) }
ReactiveMP.sigma_points_weights
— FunctionReturn the sigma points and weights for a Gaussian distribution
ReactiveMP.CVIApproximationDeltaFnRuleLayout
— TypeCVIApproximationDeltaFnRuleLayout
Custom rule layout for the Delta node in case of the CVI approximation method:
Layout
In order to compute:
q_out
: mirrors the posterior marginal on theout
edgeq_ins
: uses inbound message on theout
edge and all inbound messages on theins
edgesm_out
: uses the joint over theins
edgesm_in_k
: uses the inbound message on thein_k
edge andq_ins
ReactiveMP.log_approximate
— FunctionThis function calculates the log of the Gauss-laguerre integral by making use of the log of the integrable function. ln ( ∫ exp(-x)f(x) dx ) ≈ ln ( ∑ wi * f(xi) ) = ln ( ∑ exp( ln(wi) + logf(xi) ) ) = ln ( ∑ exp( yi ) ) = max(yi) + ln ( ∑ exp( yi - max(yi) ) ) where we make use of the numerically stable log-sum-exp trick: https://en.wikipedia.org/wiki/LogSumExp
ReactiveMP.ForwardDiffGrad
— TypeForwardDiffGrad(chunk_size::Int)
The auto-differentiation backend for the CVI procedure. Uses the ForwardDiff
library to compute gradients/derivatives. If chunk_size
is not specified then uses the heuristic from ForwardDiff
, which is type-unstable.
The ForwardDiff.jl
must be added to the current Julia environment.
ReactiveMP.UT
— TypeAn alias for the Unscented
approximation method.
ReactiveMP.UnscentedTransform
— TypeAn alias for the Unscented
approximation method.
ReactiveMP.ProdCVI
— TypeProdCVI
The ProdCVI
structure defines the approximation method hyperparameters of the prod(approximation::CVI, logp::F, dist)
. This method performs an approximation of the product of the dist
and logp
with Stochastic Variational message passing (SVMP-CVI) (See Probabilistic programming with stochastic variational message passing
).
ProdCVI
is deprecated in favor of CVIProjection
.
Arguments
rng
: random number generatorn_samples
: number of samples to use for statistics approximationn_iterations
: number of iteration for the natural parameters gradient optimizationopt
: optimizer, which will be used to perform the natural parameters gradient optimization stepgrad
: optional, defaults toForwardDiffGrad()
, structure to select how the gradient and the hessian will be computedn_gradpoints
: optional, defaults to 1, number of points to estimate gradient of the likelihood (dist*logp)enforce_proper_messages
: optional, defaults to true, ensures that a message, computed towards the inbound edges, is a proper distribution, must be of typeVal(true)/Val(false)
warn
: optional, defaults to true, enables or disables warnings related to the optimization steps
n_gradpoints
option is ignored in the Gaussian case
Adding the Optimisers.jl
in your Julia environment enables additional optimizers from the Optimisers.jl
for the CVI approximation method. Adding the DiffResults
in your Julia environment enables faster gradient computations in case if all inputs are of the Gaussian
type.
ReactiveMP.CVI
— TypeAlias for the ProdCVI
method. See help for ProdCVI
ReactiveMP.CVIProjection
— TypeCVIProjection(; parameters...)
A structure representing the parameters for the Conjugate Variational Inference (CVI) projection method. This structure is a subtype of AbstractApproximationMethod
and is used to configure the settings for CVI.
The CVIProjection
method requires ExponentialFamilyProjection
package installed in the current environment.
Parameters
rng::R
: The random number generator used for sampling. Default isRandom.MersenneTwister(42)
.marginalsamples::S
: The number of samples used for approximating marginal distributions. Default is10
.outsamples::S
: The number of samples used for approximating output message distributions. Default is100
.out_prjparams::OF
: the form parameter used to select the distribution form on which one to project out edge, if it's not provided will be infered from marginal formin_prjparams::IFS
: a namedtuple like object to select the form on which one to project in the input edge, if it's not provided will be infered from the incoming message onto this edge
The CVIProjection
method is an experimental enhancement of the now-deprecated CVI
, offering better stability and improved accuracy. Note that the parameters of this structure, as well as their defaults, are subject to change during the experimentation phase.
ReactiveMP.cvi_setup!
— Functioncvi_setup!(opt, λ)
Initialises the given optimiser for the CVI procedure given the structure of λ. Returns a tuple of the optimiser and the optimiser state.
ReactiveMP.cvi_update!
— Functioncvi_update!(tuple_of_opt_and_state, new_λ, λ, ∇)
Uses the optimiser, its state and the gradient ∇ to change the trainable parameters in the λ. Modifies the optimiser state and and store the output in the newλ. Returns a tuple of the optimiser and the newλ.
ReactiveMP.DeltaFnDefaultRuleLayout
— TypeDeltaFnDefaultRuleLayout
Default rule layout for the Delta node:
Layout
In order to compute:
q_out
: mirrors the posterior marginal on theout
edgeq_ins
: uses inbound message on theout
edge and all inbound messages on theins
edgesm_out
: uses all inbound messages on theins
edgesm_in_k
: uses the inbound message on thein_k
edge andq_ins
ReactiveMP.DeltaFnDefaultKnownInverseRuleLayout
— TypeDeltaFnDefaultKnownInverseRuleLayout
Default rule layout for the Delta node:
Layout
In order to compute:
q_out
: mirrors the posterior marginal on theout
edge (same as theDeltaFnDefaultRuleLayout
)q_ins
: uses inbound message on theout
edge and all inbound messages on theins
edges (same as theDeltaFnDefaultRuleLayout
)m_out
: uses all inbound messages on theins
edges (same as theDeltaFnDefaultRuleLayout
)m_in_k
: uses inbound message on theout
edge and inbound messages on theins
edges exceptk