4

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.

Chris
  • 457

1 Answers1

2

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.

joriki
  • 242,601
  • Thanks again for the help, joriki. Does it look any better now? – Chris Mar 01 '13 at 07:19
  • No, it's clearly wrong -- how likely is it that you'd get a mean value that's off by $462$ standard deviations? – joriki Mar 01 '13 at 07:34
  • Embarrassing. Trying to fix... – Chris Mar 01 '13 at 07:44
  • Okay, grasping at straws here. How does that look? – Chris Mar 01 '13 at 08:32
  • @Chris: The means look OK, but I don't know where the expressions that you're outputting as variances are coming from. The variance in the unstratified case should be $1/1000$ times the variance of a single sample, which I believe should be about $0.08$, so that looks way off. Why aren't you calculating the variance with the standard formula, or even just using var (X)? Also the variance reduction by stratification looks way too good; I think the variance should be reduced roughly by a factor of $8$. – joriki Mar 01 '13 at 08:54