# 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.

Note

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.

Note

@node macro does that automatically

ReactiveMP.as_node_functional_formFunction
as_node_functional_form(object)

Determines object node functional form trait specification. Returns either ValidNodeFunctionalForm() or UndefinedNodeFunctionalForm().

source

## 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.DeterministicType
Deterministic

Deterministic object used to parametrize factor node object with determinstic type of relationship between variables.

source
ReactiveMP.StochasticType
Stochastic

Stochastic object used to parametrize factor node object with stochastic type of relationship between variables.

source
ReactiveMP.sdtypeFunction
sdtype(object)

Returns either Deterministic or Stochastic for a given object (if defined).

source

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()