Graphical Models¶
Crema includes a few packages to work with probabilistc graphical models. These include support the network representations, algorithms and modifiers.
Working with networks¶
As an exercise we will be creating a Bayesian Networks with 3 nodes connected in a V shape, as shown in the following picture.
digraph example1 { A -> C; B -> C; }Graphical Networks are implemented in the models.graphical
package and they extend the Graph
class.
The class has a generic parameter to specify the concrete Factor used in order to express the probability models that
parametrise the relationships between variables defined by the network.
There are currenlty 2 concrete implementations of graphical networks that differ in the underlying storage of the edges and nodes. From an inference and algorithmic point of view the actual implementation is irrelevant.
DAG Models¶
The main implementation for directed acyclic graphs is the DAGModel
class.
Crema uses JGraphT SimpleGraph to store the actual graph.
For a Bayesian Network we will use a BayesianFactor
.
el<BayesianFactor> model = new DAGModel<>();
addVariable(2); // C
addVariable(3); // A
addVariable(2); // B
Note
In its current implementation crema stores networks using a double adjacency lists. This is for each node in the network we store the collection of parents and children.