# Built-in Functional Forms

This section describes built-in functional forms that can be used for posterior marginal and/or messages form constraints specification. Read more information about constraints specification syntax in the Constraints Specification section. An important part of the functional forms constraint implementation is the prod function. More information about prod function is present in the Prod Implementation section.

## Custom functional forms

See the Custom functional form specification section for more information about defining novel custom functional forms that are compatible with ReactiveMP inference backend.

## UnspecifiedFormConstraint

Unspecified functional form constraint is used by default and uses only analytical update rules for computing posterior marginals. Throws an error if a product of two colliding messages cannot be computed analytically.

@constraints begin
q(x) :: Nothing # This is the default setting
end
ReactiveMP.UnspecifiedFormConstraintType
UnspecifiedFormConstraint

One of the form constraint objects. Does not imply any form constraints and simply returns the same object as receives. However it does not allow DistProduct to be a valid functional form in the inference backend.

Traits

• is_point_mass_form_constraint = false
• default_form_check_strategy = FormConstraintCheckLast()
• default_prod_constraint = ProdAnalytical()
• make_form_constraint = Nothing (for use in @constraints macro)
source

## PointMassFormConstraint

The most basic form of posterior marginal approximation is the PointMass function. In a few words PointMass represents delta function. In the context of functional form constraints PointMass approximation corresponds to the MAP estimate. For a given distribution d - PointMass functional form simply finds the argmax of the logpdf(d, x) by default.

@constraints begin
q(x) :: PointMass # Materializes to the PointMassFormConstraint object
end
ReactiveMP.PointMassFormConstraintType
PointMassFormConstraint

One of the form constraint objects. Constraint a message to be in a form of dirac's delta point mass. By default uses Optim.jl package to find argmin of -logpdf(x). Accepts custom optimizer callback which might be used to customise optimisation procedure with different packages or different arguments for Optim.jl package.

Keyword arguments

• optimizer: specifies a callback function for logpdf optimisation. See also: ReactiveMP.default_point_mass_form_constraint_optimizer
• starting_point: specifies a callback function for initial optimisation point: See also: ReactiveMP.default_point_mass_form_constraint_starting_point
• boundaries: specifies a callback function for determining optimisation boundaries: See also: ReactiveMP.default_point_mass_form_constraint_boundaries

Custom optimizer callback interface

# This is an example of the custom_optimizer interface
function custom_optimizer(::Type{ Univariate }, ::Type{ Continuous }, constraint::PointMassFormConstraint, distribution)
# should return argmin of the -logpdf(distribution)
end

Custom starting point callback interface

# This is an example of the custom_starting_point interface
function custom_starting_point(::Type{ Univariate }, ::Type{ Continuous }, constraint::PointMassFormConstraint, distribution)
# built-in optimizer expects an array, even for a univariate distribution
return [ 0.0 ]
end

Custom boundaries callback interface

# This is an example of the custom_boundaries interface
function custom_boundaries(::Type{ Univariate }, ::Type{ Continuous }, constraint::PointMassFormConstraint, distribution)
# returns a tuple of lower and upper boundaries
return (-Inf, Inf)
end

Traits

• is_point_mass_form_constraint = true
• default_form_check_strategy = FormConstraintCheckLast()
• default_prod_constraint = ProdGeneric()
• make_form_constraint = PointMass (for use in @constraints macro)
source

## SampleListFormConstraint

SampleListFormConstraints approximates the resulting posterior marginal (product of two colliding messages) as a list of weighted samples. Hence, it requires one of the arguments to be a proper distribution (or at least be able to sample from it). This setting is controlled with LeftProposal(), RightProposal() or AutoProposal() objects. It is worth to note that SampleListFormConstraints approximates only DistProduct object and leaves any other distribution untouched. It also accepts an optional method object, but the only one available sampling method currently is the BootstrapImportanceSampling.

@constraints begin
q(x) :: SampleList(1000)
# or
q(y) :: SampleList(1000, LeftProposal())
end
ReactiveMP.SampleListFormConstraintType
SampleListFormConstraint(rng, strategy, method)

One of the form constraint objects. Approximates DistProduct with a SampleList object.

Traits

• is_point_mass_form_constraint = false
• default_form_check_strategy = FormConstraintCheckLast()
• default_prod_constraint = ProdGeneric()
• make_form_constraint = SampleList (for use in @constraints macro)
source

## FixedMarginalFormConstraint

Fixed marginal form constraint replaces the resulting posterior marginal obtained during the inference procedure with the prespecified one. Worth to note that the inference backend still tries to compute real posterior marginal and may fail during this process. Might be useful for debugging purposes. If nothing is passed then the computed posterior marginal is returned.

@constraints function block_updates(x_posterior = nothing)
# nothing returns the computed posterior marginal
q(x) :: Marginal(x_posterior)
end
ReactiveMP.FixedMarginalFormConstraintType
FixedMarginalFormConstraint

One of the form constraint objects. Provides a constraint on the marginal distribution such that it remains fixed during inference. Can be viewed as blocking of updates of a specific edge associated with the marginal. If nothing is passed then the computed posterior marginal is returned.

Traits

• is_point_mass_form_constraint = false
• default_form_check_strategy = FormConstraintCheckLast()
• default_prod_constraint = ProdAnalytical()
• make_form_constraint = Marginal (for use in @constraints macro)
source

## CompositeFormConstraint

It is possible to create a composite functional form constraint with either + operator or using @constraints macro, e.g:

form_constraint = SampleListFormConstraint(1000) + PointMassFormConstraint()
@constraints begin
q(x) :: SampleList(1000) :: PointMass()
end
ReactiveMP.CompositeFormConstraintType
CompositeFormConstraint

Creates a composite form constraint that applies form constraints in order. The composed form constraints must be compatible and have the exact same form_check_strategy. Any functional form constraint that defines is_point_mass_form_constraint() = true may be used only as the last element of the composition.

source