Computes the probability Pr(l<X<u), where 'X' is a zero-mean multivariate normal vector with covariance 'Sig'.
In high dimensions, this algorithm is vastly superior to the one in Matlab's statistics toolbox, see example.
Reference: Z. I. Botev (2015), "The Normal Law Under Linear Restrictions: Simulation and Estimation via Minimax Tilting", submitted to JRSS(B)
Zdravko Botev (2020). Multivariate normal cumulative distribution (https://www.mathworks.com/matlabcentral/fileexchange/53583-multivariate-normal-cumulative-distribution), MATLAB Central File Exchange. Retrieved .
very useful, Solve my problems when d>25. Thanks!
man, I should rate you 5-star even before I use the code. This 25-limitation of the inbuild function in matlab is useless
Another example: in the code below, if you change to
then my code is more than 10,000 times more efficient!
I hope this performance will earn a 5-star rating ;-)
yet again, you are not using the code appropriately, and are making incorrect conclusions.
Please read the documentation carefully if you want to obtain better efficiency.
I do not know how much you know about the difference between quasi Monte Carlo and Monte Carlo.
For the dimensions you have chosen, you have to use Quasi Monte Carlo (mvNqmc), not Monte Carlo
(mvNcdf). Quasi Monte Carlo is more efficient in low dimensions, but becomes uncompetitive in high-dimensions (Matlab’s function does not go beyond d=25, whereas my code can handle d>25)
If you use the code correctly, then my code is about 20 times more efficient, as demonstrated here:
Thank you for clarifying that. I made another test with 9 variables. Like this
tic; for i=1:50; t=mvncdf(l,u,rho9, 5*10^5); est(i)=t.prob; end; toc
The matlab built in took 21.903402 seconds and the standard deviation of the values was 2.4996e-05. This function took 23.656228 seconds and the standard deviation of the values was 1.7669e-04. So, the matlab built had a lower variance.
LuisCardona, the reason you get this result is that you used dimension=d=3, which is too low and does not need Monte Carlo simulation. For d<=3, Matlab uses deterministic numerical quadrature, so naturally there is no randomness and the variance is 0. If you try, say d=5, or higher, then mvNcdf performs much better, because there is no deterministic quadrature that can compute accurately integrals of high dimension.
The explanation for the results that I obtained in the last comment may be because I = -Inf. May be for finite intervals, it outperforms
I tested this function calculated 50 times with the same parameters to compare this one and the one from Matlab for 3 random variables.
for i=1:50; est = mvncdf(l,u,Sig,10^6); devs(i)= est.prob; end; toc
this one took 12.184780 seconds and matlab took 0.039231 seconds. The std of this one was 8.7441e-05, while matlab's was 0.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!