Nodes implementation
In message passing framework one of the most important concept is factor node. Factor node represents a local function in a factorised representation of a generative model.
To quickly check the list of all available factor nodes that can be used in the model specification language call ?make_node
or Base.doc(make_node)
.
Node traits
Each factor node has to define as_node_functional_form
trait function and to specify ValidNodeFunctionalForm
singleton as a return object. By default as_node_functional_form
returns UndefinedNodeFunctionalForm
. Objects that do not specify this property correctly cannot be used in model specification.
@node
macro does that automatically
ReactiveMP.ValidNodeFunctionalForm
— TypeValidNodeFunctionalForm
Trait specification for an object that can be used in model specification as a factor node.
See also: as_node_functional_form
, UndefinedNodeFunctionalForm
ReactiveMP.UndefinedNodeFunctionalForm
— TypeUndefinedNodeFunctionalForm
Trait specification for an object that can not be used in model specification as a factor node.
See also: as_node_functional_form
, ValidNodeFunctionalForm
ReactiveMP.as_node_functional_form
— Functionas_node_functional_form(object)
Determines object
node functional form trait specification. Returns either ValidNodeFunctionalForm()
or UndefinedNodeFunctionalForm()
.
See also: ValidNodeFunctionalForm
, UndefinedNodeFunctionalForm
Node types
We distinguish different types of factor nodes to have a better control over Bethe Free Energy computation. Each factor node has either Deterministic
or Stochastic
functional form type.
ReactiveMP.Deterministic
— TypeDeterministic
Deterministic
object used to parametrize factor node object with determinstic type of relationship between variables.
See also: Stochastic
, isdeterministic
, isstochastic
, sdtype
ReactiveMP.Stochastic
— TypeStochastic
Stochastic
object used to parametrize factor node object with stochastic type of relationship between variables.
See also: Deterministic
, isdeterministic
, isstochastic
, sdtype
ReactiveMP.isdeterministic
— Functionisdeterministic(node)
Function used to check if factor node object is deterministic or not. Returns true or false.
See also: Deterministic
, Stochastic
, isstochastic
, sdtype
ReactiveMP.isstochastic
— Functionisstochastic(node)
Function used to check if factor node object is stochastic or not. Returns true or false.
See also: Deterministic
, Stochastic
, isdeterministic
, sdtype
ReactiveMP.sdtype
— Functionsdtype(object)
Returns either Deterministic
or Stochastic
for a given object (if defined).
See also: Deterministic
, Stochastic
, isdeterministic
, isstochastic
For example +
node has the Deterministic
type:
plus_node = make_node(+)
println("Is `+` node deterministic: ", isdeterministic(plus_node))
println("Is `+` node stochastic: ", isstochastic(plus_node))
Is `+` node deterministic: true
Is `+` node stochastic: false
On the other hand Bernoulli
node has the Stochastic
type:
bernoulli_node = make_node(Bernoulli)
println("Is `Bernoulli` node deterministic: ", isdeterministic(bernoulli_node))
println("Is `Bernoulli` node stochastic: ", isstochastic(bernoulli_node))
Is `Bernoulli` node deterministic: false
Is `Bernoulli` node stochastic: true
To get an actual instance of the type object we use sdtype
function:
println("sdtype() of `+` node is ", sdtype(plus_node))
println("sdtype() of `Bernoulli` node is ", sdtype(bernoulli_node))
sdtype() of `+` node is Deterministic()
sdtype() of `Bernoulli` node is Stochastic()