# Package for integration over non-rectangular region

I want to compute the expected value of a multivariate function f(x) wrt to dirichlet distribution. My problem is "penta-nomial" (i.e 5 variables) so calculating the explicit form of the expected value seems unreasonable. Is there a way to numerically integrate it? Is there some package (e.g in R) that can let me do that? I realize I can solve it using first principle but I want the computation to be really fast.

f(x) = \sum_{0,4}(q_i*log(n/q_i))

• Why is your region non-rectangular? – nicoguaro Oct 12 '14 at 15:36
• Because the probability distribution is dirichlet and so the constraint that sum of probabilities should be one makes it non rectangular... That correct right? – Bob Oct 12 '14 at 18:01
• I see, this distribution us defined over a simplex (I didn't know that). One option is to use a Gauss quadrature over your simplex, like [here]( mathworks.com/matlabcentral/fileexchange/…). Also, see this [question] ( scicomp.stackexchange.com/questions/2013/…). – nicoguaro Oct 12 '14 at 18:11
• you could use stochastic integration as long as you knew what the domain was. Randomly select a point and determine whether it is in the parcel of the integral or not, within the hyper-rectangle. You know the volume of the hyper-rectangle, and as your point-count gets high enough, you have the ratio of "in" to "out". Multiply the volume by the ration to get the estimated volume of your sub-parcel. – EngrStudent Jul 7 '15 at 4:49