# Gaussian Mixture Reduction for Time-Constrained Approximate Inference in Hybrid Bayesian Networks +
## 4 Optimizing the Settings of HMP-GMR
```
Input: a Hybrid BN net, a maximum execution time \(max\_time\), a number of samples \(num\_samples\), an upper limit on the maximum number of iterations \(ul\_max\_it\), an upper limit on the maximum allowable number of components \(ul\_max\_nc\) Output: An optimal number of components \(nc\) and an optimal number of iterations \(it\)
1 FunctionHMP-GMR-OS ( net, max\_time, num\_samples, ul\_max\_it, ul\_max\_nc ) for\(i\gets 1\)to\(num\_samples\)do
2\(e_{\mathrm{i}}\leftarrow\) generate randomly a set of evidence values from \(net\)\(s_{\mathrm{i}}\leftarrow\) inference using a sampling algorithm with \(net\) and \(e_{\mathrm{i}}\)for\(j\gets 1\)to\(ul\_max\_nc\)do
3 for\(k\gets 1\)to\(ul\_max\_it\)do
4\(h_{\mathrm{jk}}\leftarrow\) inference using HMP-GMR with \(net\), \(e_{\mathrm{i}}\), \(max\_time\), \(j\) and \(k\)\(r_{\mathrm{ijk}}\leftarrow\) calculate an inference error value between \(s_{\mathrm{i}}\) and \(h_{\mathrm{jk}}\)\(r_{\mathrm{jk}}\leftarrow\) add \(r_{\mathrm{ijk}}\) to a set of inference error values \(r_{\mathrm{jk}}\) for \(j\) and \(k\)
5 for\(j\gets 1\)to\(ul\_max\_nc\)do
6 for\(k\gets 1\)to\(ul\_max\_it\)do
7\(avg\_r_{\mathrm{jk}}\leftarrow\) calculate an average inference error for \(r_{\mathrm{jk}}\)
8
9[\(nc\), \(it\)] \(\leftarrow\) select best values for \(nc\) and it in (25) using \(avg\_r_{\mathrm{jk}}\)
10 return[\(nc\), \(it\)]
```  
**Algorithm 2**HMP-GMR with Optimal Settings (HMP-GMR-OS) Algorithm. The HMP-GMR-OS algorithm has five inputs. The first input \(net\) is a Hybrid BN. The second input \(max\_time\) is the maximum execution time for inference of HMP-GMR. The third input \(num\_samples\) is the number indicating how many times the simulation should be repeated. The fourth input \(ul\_max\_it\) is the number of maximum iterations used for inference of HMP-GMR. The fifth input \(ul\_max\_nc\) indicates the number of maximum allowable components which will be investigated. Given these inputs, the algorithm proceeds as follows:  
* The algorithm simulates the given number of samples. * The algorithm randomly selects some evidence nodes from the Hybrid BN \(net\). Also, it randomly selects a reasonable evidence value for each evidence node (i.e., a highly unlikely value is not used for the evidence value) and provides the \(i\)-th set of evidence values \(e_{i}\). * The set of the evidence values are used for inference of a sampling algorithm by which nearly correct results of inference \(s_{i}\) (i.e., posterior distributions) are found. * The maximum allowable number of components, denoted by \(j\), is varied from \(1\) to the upper limit on the maximum allowable number of components \(ul\_max\_nc\). * The maximum number of iterations, denoted by \(k\), is varied from \(1\) to the upper limit on the maximum number of iterations \(ul\_max\_it\). * This algorithm uses the HMP-GMR algorithm with the Hybrid BN \(net\), the set of the evidence values \(e_{i}\), the maximum execution time \(max\_time\), the maximum allowable number of components \(j\) and the maximum number of iterations \(k\). Then, the HMP-GMR algorithm provides the results \(h_{jk}\) (i.e., posterior distributions). * An inference error value \(r_{ijk}\) between the nearly correct results \(s_{i}\) and the HMP-GMR's result \(h_{jk}\) is computed by using a distance function (e.g., KL-divergence [38]). * The inference error value \(r_{ijk}\) at \(i\)-th sample for \(j\) and \(k\) is stored at a set of inference error values \(r_{\mathrm{jk}}\) for \(j\) and \(k\). Line 10, 11, 12 After simulating all samples, for all \(j\) and \(k\), an average inference error \(\textit{avg\_rj}_{\text{k}}\) is calculated using the set of the inference error values \(\textit{rj}_{\text{k}}\). Line 13A best maximum allowable number of components \(nc\) and a best maximum number of iterations \(it\) are selected by finding a minimum average inference error from \(\textit{avg\_rj}_{\text{k}}\). Line 14 The algorithm outputs the best values \(nc\) and \(it\).