The marginal probability \(p(X_i=x_i)=\prod_{f_C\in N(X_i)} m_{f_C\rightarrow X_i}(x_i)\). Choose a variable node as the root (\(X_R\)), then starting from the leaves:

- If \(f_C\) is a leaf node, then \(m_{f_C\rightarrow X}(x_C)=f_C(x_C)\)
- If \(X\) is a leaf node, then \(m_{X\rightarrow f_C}(x)=1\)
- The message sent from a non-leaf factor node \(f_C\) to a variable node \(X_i\) is \[m_{f_C\rightarrow X_i}(x_i)=\sum_{x_{N(f_C)-X_i}}f_C(\mathbf{x}_C)\prod_{x': X'\in {N(f_C)-X_i}} m_{X'\rightarrow f_C}(x')\]
- The message sent from a non-leaf variable node \(X_i\) to a factor node \(f_C\) is: \[m_{X_i\rightarrow f_C}(x_i) =\prod_{f_{C'} \in N(X_i)-f_C} m_{f_{C'}\rightarrow X_i}(x_i)\]