# Internals

This page documents the internals of the ForneyLab package. It is mainly tailored for software developers interested in understanding the inner workings of the package. Coding style conventions can be found in `STYLEGUIDE.md`

.

## Directory structure

ForneyLab's directories and files are structured as follows:

`/demo/`

: demos in Jupyter (iJulia) notebook format (`.ipynb`

)`/src/`

: all source files`algorithms/`

: inference algorithm implementations`expectation_propagation/`

: EP algorithm implementation`sum_product/`

: SP algorithm implementation`variational_bayes/`

: VMP algorithm implementation

`engines/`

: rendering of message passing schedules to executable code`julia/`

: Julia engine and update rule implementations

`factor_nodes/`

: all node-specific files`update_rules/`

: message passing update rules

`/test/`

: test files with directory structure similar to`/src/`

.

## Update rules naming convention

The name of an update rule is composed of several parts:

- The word
`rule`

- Type of algorithm
`SP`

: sum-product`VB`

: variational Bayes`SVB`

: structured variational Bayes`M`

: marginal, used with SVB

- Type of factor node
- Interface of the outgoing message
- Types of incoming messages (absent for
`VB`

rules)`N`

: Nothing`P`

: point mass`D`

: distribution`[I]`

: first letter of the message's probability distribution

###### Example 1: `ruleSPGaussianMeanPrecisionMPNP`

`rule`

: update rule`SP`

: sum-product algorithm`GaussianMeanPrecision`

: Gaussian mean precision factor node`M`

: outgoing message through 'Mean' interface`PNP`

: incoming message types are: point mass, Nothing and point mass

###### Example 2: `ruleVBBernoulliOut`

`rule`

: update rule`VB`

: variational Bayes algorithm`Bernoulli`

: Bernoulli factor node`Out`

: outgoing message through 'Out' interface`-`

###### Example 3: `ruleEPProbitIn1GB`

`rule`

: update rule`EP`

: expectation propagation algorithm`Probit`

: probit factor node`In1`

: outgoing message through 'in1' interface`GB`

: incoming message types are: Gaussian and Bernoulli

*Note that EP update rules do not have*`N`

(nothing) in the set of incoming messages given that in EP there is an incoming message through the interface of the outgoing message that is being calculated.