## Appendix B Additional Examples  
**Example A1** (Composing and decomposing a discrete BN). : _Consider the discrete BN \(\mathcal{B}\) shown in Figure 2 (top). Composing its global distribution entails computing the joint probabilities of all possible states of all variables,_  
\[\{a,b\}\times\{c,d\}\times\{e,f\}\times\{g,h\},\]  
_and arranging them in the following four-dimensional probability table in which each dimension is associated with one of the variables._  
\[ \begin{array}{c}\begin{array}{c}X_{1}=a\\ \hline X_{2}=c\\ \hline X_{3}\\ X_{4}\end{array}&\begin{array}{c}X_{2}=d\\ \hline X_{3}\\ \hline X_{4}\end{array}&\begin{array}{c}X_{2}=c\\ \hline X_{3}\\ \hline X_{4}\end{array}&\begin{array}{c}X_{3}\\ \hline X_{4}\end{array}&\begin{array}{c}X_{2}=d\\ \hline X_{3}\\ \hline X_{4}\end{array}&\begin{array}{c}X_{3}\\ \hline X_{4}\end{array}&\begin{array}{c}X_{3}\\ \hline X_{4}\end{array}\\ \begin{array}{c}X_{4}\end{array}&\begin{array}{c}e\\ \hline g\\ h\end{array}&\begin{array}{c}0.052\\ \hline 0.051\end{array}&\begin{array}{c}0.037\\ \hline h\end{array}&\begin{array}{c}g\\ 0.051\end{array}&\begin{array}{c}0.013\\ \hline 0.056\end{array}&\begin{array}{c}g\\ h\end{array}&\begin{array}{c}0.050\\ \hline 0.199\end{array}&\begin{array}{c}0.036\end{array}\end{array} \]  
_The joint probabilities are computed by multiplying the appropriate cells of the CPTs, for instance_  
\[ \begin{array}{c}\operatorname{P}(X=\{a,d,f,h\})=\\ \operatorname{P}(X_{1}=a)\operatorname{P}(X_{2}=d)\operatorname{P}(X_{3}=f \mid X_{1}=a,X_{2}=d)\operatorname{P}(X_{4}=h\mid X_{3}=f)=\\ 0.53\cdot 0.66\cdot 0.25\cdot 0.58=0.051.\end{array} \]Conversely, we can decompose the global distribution into the local distributions by summing over all variables other than the nodes and their parents. For \(X_{1}\), this means  
\[\mathrm{P}(X_{1}=a) =\sum_{x_{2}\in\{c,d\}}\sum_{x_{3}\in\{c,f\}}\sum_{x_{4}\in\{g,h\}} \mathrm{P}(X_{1}=a,X_{2}=x_{2},X_{3}=x_{3},X_{4}=x_{4})\] \[=0.005+0.064+0.022+0.089+0.052+0.037+0.210+0.051=0.53,\] \[\mathrm{P}(X_{1}=b) =\sum_{x_{2}\in\{c,d\}}\sum_{x_{3}\in\{c,f\}}\sum_{x_{4}\in\{g,h\}} \mathrm{P}(X_{1}=b,X_{2}=x_{2},X_{3}=x_{3},X_{4}=x_{4})\] \[=0.013+0.040+0.051+0.056+0.050+0.026+0.199+0.036=0.47.\]  
Similarly, for \(X_{2}\) we obtain  
\[\mathrm{P}(X_{2}=c) =\sum_{x_{1}\in\{a,b\}}\sum_{x_{3}\in\{c,f\}}\sum_{x_{4}\in\{g,h\} }\mathrm{P}(X_{1}=x_{1},X_{2}=c,X_{3}=x_{3},X_{4}=x_{4})\] \[=0.005+0.064+0.022+0.089+0.013+0.040+0.051+0.056=0.34,\] \[\mathrm{P}(X_{2}=d) =\sum_{x_{1}\in\{a,b\}}\sum_{x_{3}\in\{c,f\}}\sum_{x_{4}\in\{g,h\} }\mathrm{P}(X_{1}=x_{1},X_{2}=d,X_{3}=x_{3},X_{4}=x_{4})\] \[=0.052+0.037+0.210+0.051+0.050+0.026+0.199+0.036=0.66.\]  
For \(X_{4}\), we first compute the joint distribution of \(X_{4}\) and \(X_{3}\) by marginalising over \(X_{1}\) and \(X_{2}\),  
\[\underbrace{ \begin{matrix}e&f\\ h&\left(\begin{matrix}0.005&0.064\\ 0.022&0.089\end{matrix}\right)+\underbrace{\begin{matrix}g\\ h\\ \left\{a,d\right\}\end{matrix}}&\begin{matrix}e&f\\ \left\{a,d\right\}\end{matrix}&\begin{matrix}e&f\\ \left\{a,d\right\}\end{matrix}&\begin{matrix}e&f\\ \left\{a,d\right\}\end{matrix}&\begin{matrix}0.052&0.037\\ 0.210&0.051\end{matrix}\\ &\underbrace{\begin{matrix}g\\ h\\ \left\{b,c\right\}\end{matrix}}&\begin{matrix}e&f\\ \left\{b,d\right\}\end{matrix}&\begin{matrix}e&f\\ \left\{b,c\right\}\end{matrix}&\begin{matrix}e&f\\ \left\{b,d\right\}\end{matrix}&\begin{matrix}e&f\\ \left\{b,d\right\}\end{matrix}&\begin{matrix}e&f\\ \left\{b,d\right\}\end{matrix}&\begin{matrix}e&f\\ \left\{b,d\right\}\end{matrix}&\begin{matrix}e&f\\ \left\{b,d\right\}\end{matrix}&\begin{matrix}e&f\\ \left\{b,d\right\}\end{matrix}&\begin{matrix}g\\ \left\{b,d\right\}\end{matrix}&\begin{matrix}0.120&0.167\\ 0.481&0.232\end{matrix}\end{matrix} ;\]  
from which we obtain the CPT for \(X_{4}\mid X_{3}\) by normalising its columns. As for \(X_{3}\), we marginalise over \(X_{2}\) to obtain the joint distribution of \(X_{3}\), \(X_{1}\) and \(X_{2}\)  
\[