'How to compute a high dimensional multiple integral with infinite bounds using vegas in Julia
I am trying to compute a high dimensional integral using Julia (>1400 dimensions). I am thus trying to do this using the function vegas, as it can presumably compute high dimensional integrals. However, vegas assumes that the domain of integration is [0,1]^n but my integral is over R^n. The documentation of vegas suggests a change of variables, but I cannot get it to work in multiple dimensions.
So, if I type in Julia the following integral in 2 dimensions:
using LinearAlgebra, Cuba
multinormal(x,μ,Σ) = det(2*π*Σ)^(-1/2)*exp(-1/2*(x-μ)'*inv(Σ)*(x-μ))
vegas((x,f)->f=multinormal(x,[0;0],[1 0;0 1]),2)
I get the result
Component:
1: 0.0 ± 7.025180405943273e-18 (prob.: -999.0)
Integrand evaluations: 1000
Number of subregions: 0
Note: The desired accuracy was reached
which assumes that the integral is over [0,1]^2.
Trying to compute the same integral over [0,infinity)^2, I tried the change of variables suggested here as
vegas((x,f)->f=multinormal(x./(1 .- x),[0;0],[1 0;0 1])./(1 .-x).^2,2)
which gives me the result
Component:
1: 0.0 ± 7.025180405943273e-18 (prob.: -999.0)
Integrand evaluations: 1000
Number of subregions: 0
Note: The desired accuracy was reached
But the result should be 0.5 rather than 0.
How could I compute this integral of the multivariate normal distribution with infinite integration limits using vegas?
Solution 1:[1]
I ended up just approximating the integral as suggested here: https://stats.stackexchange.com/questions/228687/approximation-expectation-integral
For example, to compute the expected value E of a multivariate normally distributed variable x in two dimensions, I did:
using Distributions, LinearAlgebra
sampleSize = 1000;
dist = MvNormal([0;0],I);
x = rand(dist,sampleSize);
E = 1/sampleSize*sum([x[:,r] for r in 1:sampleSize])
The convenience of this approach is that it works very efficiently for high dimension (in my case the dimension of x is >1400).
Solution 2:[2]
If you use Quadrature.jl it'll perform the necessary changes of variables for you automatically. Then you just use [-Inf,Inf] bounds. See examples in the tests:
https://github.com/SciML/Quadrature.jl/blob/master/test/inf_integral_tests.jl
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mauricio |
| Solution 2 | Chris Rackauckas |
