# Evaluating 6D Gaussian Integral in Matlab

I have to compute the accuracy of a new Gaussian mixture fitting algorithm. One of the tests include computing the probabilities in certain intervals in a 6D hyperspace. Also, the integral of the square of the difference between PDF has to be evaluated. But problem is, Matlab doesn't have library functions that handle integrals above 3 dimensions. Googling, I found several results that involve some sort of nesting using wither quad2d or integral2/integral3. Unfortunately, my attempts to implement nesting haven't been successful. All I have to do is to evaluate the Integral of $(N_{1}(x,\mu_{1},P_{1})-N_{2}(x,\mu_{2},P_{2}))^{2}$ over any given interval in $R^{6}$. Thank you for suggestions

• Is evaluating $N_1,N_2$ expensive? Or can you do it a few milliseconds? – Wolfgang Bangerth Sep 14 '14 at 20:19

In general, the standard quadrature codes do not perform well in higher dimensions, which is probably why they are not available in Matlab.

I would propose that you use Monte Carlo Integration instead, which works very well in these cases. Here you randomly sample points of your function in order to evaluate the integral. In particular, you probably want to use Quasi Monte Carlo integration, as the convergence is faster. The only difference is that the function is not sampled randomly, but quasi-randomly. You can generate quasi-random numbers in Matlab very easily.

A simple way to estimate the precision is to simply repeat the integration twice, and look at the difference. However there are also online algorithms that allow you to estimate the variance as part of the Monte Carlo integration.

In practice, when the function is well behaved it is often sufficient to just use a large number of points and not worry unduly.

One approach to higher dimensional integrals is to use a sparse grid quadrature method (smolyak, clenshaw-curtis, etc...). The idea is to use a small portion of a tensor product of 1D quadrature rules such that certain multivariate monomials are accounted for in the final integration rule. If the integrand is reasonably approximated by a low dimensional polynomial function, sparse grid quadrature work really well. In which case, various matlab packages are available for this purpose: