[Math] Stratified Monte Carlo

MATLABmonte carlonumerical methodsstatistics

Consider the integral $I=\int_{0}^{1}e^{-x}dx$.

Now consider the stratifed Monte Carlo estimate $\hat{I^{s}}$, that has $N_{st}=8$ strata. What is the variance of $\hat{I^{s}}$? What is the percent reduction in variance over the simple Monte Carlo estimate?

This follows the problem I asked and solved here: Expected Value and Variance of Monte Carlo Estimate of $\int_{0}^{1}e^{-x}dx$

True value: $\int_{0}^{1}e^{-x}dx=0.6321205588…$

Matlab code for basic Monte Carlo:

m=1000;
N = 1000;
z=zeros(1,m);
for j=1:m
    U = rand(1,N);
    X = exp(-U);
    i=mean(X);
    z(j)=i;
end
expectedvalue = mean(z)
variance = var(z)

Results: integral = 0.6382953, variance = 3.1346e-05

Stratified Monte Carlo attempt:

m=1000;
N=1000;
z=zeros(1,m);
for j=1:m
    K = 8;
    Ni = N/K;
        for i = 1 : K
            XS = exp(-((i-1+rand(1,Ni))/K));
            XSB(i) = mean(XS);
            SS(i) = var(XS);
        end,
    SST = mean(SS/N);
    z(j)=mean(XSB);
end
expectedvalue=mean(z)
variance = var(z)

Results: integral = 0.6321, variance = 5.4545e-07

If anyone who knows Matlab can chime in and help out here, I'd be thankful.

Best Answer

When you see $10^{-29}$ on a machine with finite precision, think zero. What the first snippet calculates is a rounding error, not a variance. The random variable $U$ is never used, and the variable $x$ is never initialized.