# Gaussian Mixture Reduction for Time-Constrained Approximate Inference in Hybrid Bayesian Networks +
## 3 Extended Hybrid Message Passing Algorithm  
The previous sections introduced message passing inference and Gaussian mixture reduction. This section combines these methods into an extended hybrid message passing algorithm for CG BNs. The GMR operation is denoted as a function, \(\tau(gmm,max\_nc)\) that applies Equation (16), where \(gmm\) is a Gaussian mixture model and \(max\_nc\) is the maximum number of allowable mixture components. To specify the algorithm, we need to define where in the inference process, GMR will be applied. For this, the Pi/Lambda functions for \(X\) and Pi/Lambda messages \(U\to X\) in Type 14 and \(\{A,U\}\to X\) in Type 17 are chosen. Hence, the function \(\tau(gmm,max\_nc)\) is applied to Equations (7)-(11), (14) and (15). For the extended algorithm, these equations become:  
\[\pi(X)=\tau\left(\int\limits_{\mathbf{U}}P(X|\mathbf{U})\prod\limits_{i}\pi_{ X}(U_{i})\,d\mathbf{U},M\right) \tag{17}\]  
\[\pi(X)=\tau\left(\sum\limits_{\mathbf{A}}\int\limits_{\mathbf{U}}P(X|\mathbf{ A},\mathbf{U})\prod\limits_{i}\pi_{X}(A_{i})\prod\limits_{j}\pi_{X}(U_{j})\,d \mathbf{U},M\right) \tag{18}\]  
\[\lambda(X)=\tau\left(\prod\limits_{j}\lambda_{Y_{j}}(X),M\right) \tag{19}\]  
\[\pi_{Y_{j}}(X)=\pi\tau\left(\prod\limits_{k\
eq j}\lambda_{Y_{k}}(X),M\right) \pi(X) \tag{20}\]  
\[\lambda_{X}(U_{j})=\int\limits_{X}\lambda(X)\tau\left(\int\limits_{\mathbf{U }}P(X|\mathbf{U})\prod\limits_{k\
eq j}\pi_{X}(U_{k})\,d\mathbf{U},M\right)\; dX \tag{21}\]  
\[\lambda_{X}(U_{j})=\int\limits_{X}\lambda(X)\tau\left(\sum\limits_{\mathbf{A} }\int\limits_{\mathbf{U}}P(X|\mathbf{A},\mathbf{U})\prod\limits_{i}\pi_{X}(A_ {i})\prod\limits_{k\
eq j}\pi_{X}(U_{k})\,d\mathbf{U},M\right)\;dX \tag{22}\]  
and  
\[\lambda_{X}(A_{i}=a)=\int\limits_{X}\lambda(X)\tau\left(\sum\limits_{\mathbf{ A}}\int\limits_{\mathbf{U}}P(X|A_{i}=a,\overline{\mathbf{A}},\mathbf{U})\prod \limits_{k\
eq i}\pi_{X}(A_{k})\prod\limits_{j}\pi_{X}(U_{j})\,d\mathbf{U},M \right)\;dX, \tag{23}\]where \(M=max\_nc\) denotes the maximum allowable number of components. The above equations are implemented in Algorithm 1, called _Hybrid Message Passing Algorithm with Gaussian Mixture Reduction_ (HMP-GMR). Algorithm 1 is an extension of a Hybrid Message Passing algorithm (HMP) from Reference [29] to which we apply GMR. An initial version of this algorithm was introduced in Reference [28]. In contrast with the initial version, this is an anytime algorithm that can provide a solution even if it is interrupted before completion. HMP-GMR (Algorithm 1) has five inputs. The first input, _net_, is the Hybrid BN with specified evidence nodes and their values. The second input, \(max\_time\), is the maximum execution time used to control how long this algorithm runs by comparing to the current execution time, \(exe\_time\), representing a period from the algorithm starting time to the current time. The third input, \(max\_iteration\), is the maximum number of iterations allowed, where an iteration is one round in which all nodes in the BN perform their operations. The fourth input, \(max\_nc\), is the maximum number of Gaussian components that may be output by the GMR function \(\tau\). The fifth input, \(max\_prcs\), is a threshold on the distance between posterior distributions of nodes in the current and previous iterations. The algorithm terminates when the distance is lower than the threshold. HMP-GMR outputs approximate posterior distributions of all nodes. Given these inputs, Algorithm 1 proceeds as follows. * The algorithm iterates message passing from 1 to the maximum number of iterations or until it is interrupted due to exceeding the time limit. * The algorithm cycles through all nodes in the BN. * For the \(j\)-th node, all Pi messages from its parents are computed to calculate the Pi value \(\pi_{j}\). If the RV is discrete, Equation (3) is used, while if it is continuous and has only discrete, only continuous or hybrid parents, Equation (11), (17) or (18), is used, respectively.