Tuesday, July 2, 2013

Compositional models and their relation to Bayesian networks

Some time ago I noticed that Radim Jirousek published a foundational paper bringing together results on compositional models. A subclass of compositional models are an alternative formulation of Bayesian networks.

The basic idea goes as follows. Suppose \(\pi\) is a joint distribution on variables \(x_1\) and \(x_2\) specified by the following table (see the linked paper page 620).

\(\pi\) \(x_1=0\) \(x_1=1\)
\(x_2=0\) \(\frac{1}{2}\) \(\frac{1}{2}\)
\(x_2=1\) 0 0

and further suppose \(\nu\) is the uniform distribution on variables \(x_1\) and \(x_3\):

\(\pi\) \(x_1=0\) \(x_1=1\)
\(x_2=0\) \(\frac{1}{2}\) \(\frac{1}{2}\)
\(x_2=1\) 0 0

Then we define $$ (\pi \rhd \nu)(x_1,x_2,x_3) = \frac{ \pi(x_1,x_2) \nu(x_2, x_3) } { \nu^{\downarrow(2)}(x_2) } $$ where the down arrow indicates a marginal distribution. This division may not always be defined. For example the composition \(\pi \rhd \nu(x)\) is defined for all combinations of \(x_1\),\(x_2\) and \(x_3\) whereas the composition \(\nu \rhd \pi(x)\) is defined for only some, as in the table below which can be compared to that on page 630 of Jirousek's paper.

\(x_1\) \(x_2\) \(x_3\) \(\pi \rhd \nu(x)\) \(\nu \lhd \pi(x)\)
false false false Some(0.25) Some(0.125)
false false true Some(0.25) Some(0.125)
false true false Some(0.0) None
false true true Some(0.0) None
true false false Some(0.25) Some(0.125)
true false true Some(0.25) Some(0.125)
true true false Some(0.0) None
true true true Some(0.0) None

Conveniently Scala allows function names like |> and <|, and the monadic representation of results. Here None means undefined, and a finer point about the implementation below is that I might have used a ternary operator to resolve 0*0/0=0, as per Jirousek's convention.

Anyway, here's the code

No comments:

Post a Comment