basic problem

6
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.

Upload: nyx

Post on 06-Jan-2016

21 views

Category:

Documents


0 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Basic problem

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.

Page 2: Basic problem

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

• Estimated relative accuracy based on 142 is• Exact relative accuracy is

√1/142=0.0842

2

10.0799

1000

e

e

Page 3: Basic problem

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.1182Repeated 3 times

Page 4: Basic problem

Question

• Why the number of accepted samples is more stable than the estimate of the probability?

Page 5: Basic problem

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.

Page 6: Basic problem

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