Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
The code is correct in its current form. –  Chris Mar 2 '13 at 12:23

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Thanks again for the help, joriki. Does it look any better now? –  Chris Mar 1 '13 at 7: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 1 '13 at 7:34
    
Embarrassing. Trying to fix... –  Chris Mar 1 '13 at 7:44
    
Okay, grasping at straws here. How does that look? –  Chris Mar 1 '13 at 8: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 1 '13 at 8:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.