60 likes | 179 Views
Basic problem. A random variable X follows the exponential distribution, p(x)= exp (-x) for x=>0. Check how different ways of sampling will compare in terms of accuracy for estimating the probability of x>2 with 1,000 samples. Exact value of probability is exp (-2)=0.1353.
E N D
Basic problem • A random variable X follows the exponential distribution, p(x)=exp(-x) for x=>0. Check how different ways of sampling will compare in terms of accuracy for estimating the probability of x>2 with 1,000 samples. • Exact value of probability is exp(-2)=0.1353.
From actual distribution x=exprnd(1,1,1000); y=sum((sign(x-2)+1)/2)=142 x=exprnd(1,1,1000); y=sum((sign(x-2)+1)/2)=126 x=exprnd(1,1,1000); y=sum((sign(x-2)+1)/2)=138 x=exprnd(1,1,1000); y=sum((sign(x-2)+1)/2)=115 x=exprnd(1,1,1000); y=sum((sign(x-2)+1)/2)=154 x=exprnd(1,1,1000); y=sum((sign(x-2)+1)/2)=134 • Estimatedrelativeaccuracybasedon 142 is • Exactrelativeaccuracyis
Rejection sampling from a gamma distribution • Pick a gamma distribution with a=1, b=2. • Need M=2 for bounding. x=gamrnd(1,2,1,1000); p=exppdf(x); q=gampdf(x,1,2); ratio=p./(2*q); ratio(1:10) accepttest=rand(1,1000); accept=(sign(ratio-accepttest)+1)/2; acceptsample=x.*accept; exceed=sum(sign(acceptsample-2)+1)/2=72; 64; 61 nsamples=sum(sign(acceptsample))=490;519; 516 prob=exceed/nsamples=0.1469;0.1233; 0.1182 Repeated 3 times
Question • Why the number of accepted samples is more stable than the estimate of the probability?
Importance sampling from same distribution ratio=p./q; exceedsamples=(sign(x-2)+1)/2; exceed=sum(exceedsamples.*ratio)=145.4; 131.7; 132.4 %To get estimate of probability divide by 1,000 ratio=ratio/sum(ratio); exceed=sum(exceedsamples.*ratio)=0.1499; 0.1311; 0.1279 %With normalized weight get probability directly.
Bootstrapping • Illustrate bootstrapping for estimating accuracy of probability of x>2 from actual distribution. x=exprnd(1,1,1000); y=sum((sign(x-2)+1)/2)=143 for i=1:100 xs=datasample(x,1000); y(i)=sum((sign(xs-2)+1)/2); end mean(y)=143.0500 std(y)=10.4566 y(1:10)=159 140 134 121 149 147 126 163 138 141