Sei sulla pagina 1di 49

Reduction variance techniques

Chapter 9 from Ross (2013)

Freddy Hernndez Barajas


Universidad Nacional de Colombia

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

Introduction

Suppose as usual that we wish to estimate . Then the standard


simulation algorithm is:
1
2
3

Generate U1 , U2 , . . . , Un .
P
Estimate with n = n

j=1 Xj /n

where Xj = h(Uj )

Approximate 100(1 )% confidence intervals are given by

n
n z/2
n

n
n + z/2
n

where
n is the usual estimate of Var (X ) based on X1 , X2 , . . . , Xn .

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

Introduction
We would like IC to be small, but sometimes this is difficult to
achieve. This may be because Var (X ) is too large, or too much
computational effort is required to simulate each Xj so that n is
necessarily small, or some combination of the two.
There are a number of things we can do:
Develop a good simulation algorithm.
Program carefully to minimize execution time.
Program carefully to minimize storage requirements. For
example we do not need to store all the Xj s: we only need to
P
P
keep track of Xj and Xj2 .
Decrease the variability of the simulation output that we use to
estimate . The techniques used to do this are usually called
variance reduction techniques.
Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

Variance reduction techniques

Antithetic variables.

Control variates.

Conditioning.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

1. Antithetic variables

Suppose we are interested in using simulation to estimate = E [X ]


and suppose we have generated X1 and X2 , identically distributed
random variables having mean . Then

Var

X1 + X2
2

1
(Var (X1 ) + Var (X2 ) + 2Cov (X1 , X2 ))
4

Hence it would be adventageous if X1 and X2 rather than being


independent were negatively correlated.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
To see how we migth arrange for X1 and X2 to be negatively
correlated, suppose that X1 is a function of m random numbers
X1 = h(U1 , U2 , . . . , Um )
where U1 , U2 , . . . , Um are m independent random numbers.
If U U(0, 1) then 1 U is also distribuited as U(0, 1) and
X2 = h(1 U1 , 1 U2 , . . . , 1 Um )
has the same distribution as X1 and it is negatively correlated with
X1 .
What type of function could be h()? Consult page 156.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

Example 9d

Suppose we were interested in using simulation to estimate


= E [e u ] =

Z 1

e x dx

It is apropiate the use of the antithetic variable 1 u?


We will compare the variance without and with antithetic variables
to decide.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

First

Second

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

We see that the use of independent variables results in a variance of

whereas the use of the antithetic variables U and 1 U gives a


variance of

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
Without antithetic variables
g <- function(x) exp(x)
n <- 1000
u1 <- runif(n)
u2 <- runif(n)
x1 <- ( g(u1) + g(u2) ) / 2
mean(x1)

## [1] 1.721373
var(x1)

## [1] 0.1284228

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

Using antithetic variables


x2 <- ( g(u1) + g(1-u1) ) / 2
mean(x2)

## [1] 1.722226
var(x2)

## [1] 0.004299438

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
Comparing the two approaches
Without antithetic variables
2.0

With antithetic variable


2.0

True integral value

1.9

Mean evolution

Mean evolution

1.9

1.8

1.7

1.6

1.8

1.7

1.6

1.5

1.5
0

200

400

600

800

1000

Iterations

Freddy Hernndez BarajasUniversidad Nacional de Colombia

200

400

600

Iterations

Reduction variance techniques

800

1000

. . . continuation

f <- function(x) exp(x)


# The true value to estimate is:
integrate(f, lower=0, upper=1)

## 1.718282 with absolute error < 1.9e-14

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

aprox <- function(n=1000, antithetic=FALSE) {


u <- runif(n/2)
if (!antithetic)
v <- runif(n/2)
else
v <- 1 - u
u <- c(u, v)
x <- f(u)
mean(x)
}

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

n <- 1000
without.anti <- replicate(n=n, aprox(antithetic=FALSE))
with.anti <- replicate(n=n, aprox(antithetic=TRUE))

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
mean(without.anti)
## [1] 1.718942
sd(without.anti)
## [1] 0.01525596
mean(with.anti)
## [1] 1.718274
sd(with.anti)
## [1] 0.002755573
Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

Example 1

Estimate the integral

R
0

g(x ) dx =

R
0

log(1 + x 2 )e x dx .

To solve the integral we can use the change variable t = 1 e x to


ensure that f () is a monotonic function.
f (t) = log(1 + log2 (1 t))
and the integral to solve is

R1
0

f (t) = log(1 + log2 (1 t)) dt.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

f(x)

0.0

0.00

0.5

0.05

1.0

1.5

0.15
0.10

g(x)

2.0

0.20

2.5

0.25

3.0

. . . continuation

10

15

Freddy Hernndez BarajasUniversidad Nacional de Colombia

0.0

0.2

0.4

0.6
x

Reduction variance techniques

0.8

1.0

. . . continuation

f <- function(x) log(1 + (log(1 - x)) ^ 2)


# The true value to estimate is:
integrate(f, lower=0, upper=1)

## 0.6867559 with absolute error < 9.7e-07

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

aprox <- function(n=1000, antithetic=FALSE) {


u <- runif(n/2)
if (!antithetic)
v <- runif(n/2)
else
v <- 1 - u
u <- c(u, v)
x <- f(u)
mean(x)
}

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
n <- 1000
without.anti <- replicate(n=n, aprox(antithetic=FALSE))
with.anti <- replicate(n=n, aprox(antithetic=TRUE))
mean(without.anti)

## [1] 0.6867205

sd(without.anti)

## [1] 0.02383796

mean(with.anti)

## [1] 0.6865537

sd(with.anti)

## [1] 0.01382919

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

Example 2

Estimate V =

R /4 R /4 2 2
x y sin(x + y ) ln(x + y )dxdy .
0
0

If we use x = u1 /4, y = u2 /4 the integral limits are 0 and 1.


Note that f (u1 , u2 ) is monotonic in both variables, for u1 [0, 1]
and u2 [0, 1] .

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
Not using antithetic variables
g <- function(x) prod(x)^2*sin(sum(x))*log(sum(x))
n <- 1000
u1 <- matrix(runif(2*n), ncol=2)
x1 <- apply(u1*pi/4, 1, g) * pi^2 / 16
u2 <- matrix(runif(2*n), ncol=2)
x2 <- apply(u2*pi/4, 1, g) * pi^2 / 16
x <- ( x1 + x2 ) / 2
mean(x)

## [1] 0.004155943
var(x)

## [1] 9.682597e-05

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
Using antithetic variables
g <- function(x) prod(x)^2*sin(sum(x))*log(sum(x))
n <- 1000
u1 <- matrix(runif(2*n), ncol=2)
x1 <- apply(u1*pi/4, 1, g) * pi^2 / 16
u2 <- 1 - u1
x2 <- apply(u2*pi/4, 1, g) * pi^2 / 16
y <- ( x1 + x2 ) / 2
mean(y)

## [1] 0.003887711
var(y)

## [1] 7.70069e-05

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
Comparing results.

0.010

Without a.v.
With a.v.

Mean evolution

0.008

0.006

0.004

0.002

0.000
0

200

400

600

800

Iterations

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

1000

Exercise from Rizzo (2008)

Use Monte Carlo integration with antithetic variables to estimate


Z 1
e x
0

1 + x2

dx ,

and find the approximate reduction in variance as a percentage of


the variance without variance reduction.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

2. Control variates

Suppose that we want to use simulation to estimate = E [X ],


where X is the output of a simulation. Now suppose that for some
other output variable Y, the expected value of Y is known-say,
E [Y ] = Y .
Then for any constant c, the quantity
X + c(Y Y )
is also an unbiased estimator of .

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

To determine the best value of c, note that

Simple calculus now shows that the above is minimized when


c = c ? , where
c? =

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Cov (X , Y )
Var (Y )

Reduction variance techniques

. . . continuation

and for this value the variance of the estimator is

The quantity Y is called a control variate for the simulation


estimator X .
The quantity X + c(Y Y ) is called the controlled
estimator.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

Upon dividing the last Equation by Var (X ), we obtain that

is the correlation between X and Y . Hence, the variance reduction


obtained in using the control variate Y is 100 Corr 2 (X , Y ) percent.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

The quantities Cov (X , Y ) and Var (Y ) are usually not known in


advance and must be estimated from the simulated data. If n
simulation runs are performed, and the output data Xi , Yi , with
i = 1, . . . , n, result, then using the estimators

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

we can approximate c ? by c? , where

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

Example 9h

As in Example 9d, suppose we were interested in using simulation to


compute = E [e U ]. Here, a natural variate to use as a control is
the random number U.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

Because Var (U) = 1/12 it follows that

where the above used, from Example 9d, that Var (e U ) = 0.2420.
Hence, in this case, the use of the control variate U can lead to a
variance reduction of up to 98.4 percent.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
We want to estimate E [e U ] until its standard deviation d < 0.01.
d
J0
x
s2
i

<<<<<-

0.01
20 # J0 Minimum number of variates
exp( runif(J0) )
var(x)
J0

while ( sqrt(s2/i) > d ) {


i <- i + 1
x[i] <- exp( runif(1) )
s2 <- var(x)
}

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

The results are


i
## [1] 2429
mean( x )
## [1] 1.731676

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
Using control variate.
U
X
Y
S2
i

<<<<<-

runif(J0)
exp(U)
U # Using the notation
var(X)
J0

while ( sqrt(S2/i) > d


i <- i + 1
u <- runif(1)
X[i] <- exp(u); Y[i]
c_star <- - cov(X,Y)
Z <- X + c_star * (Y
S2 <- var(Z)
}

) {

<- u
/ var(Y)
- 0.5)

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

The results are


i
## [1] 43
mean( Z )
## [1] 1.721574

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
Resuming
Without control variate

With control variate


2.0

1.9

1.9

1.8

1.8

x Mean

Z Mean

2.0

1.7

1.7

1.6

1.6

1.5

1.5
0

500

1000

1500

2000

2500

Iterations

Freddy Hernndez BarajasUniversidad Nacional de Colombia

10

20
Iterations

Reduction variance techniques

30

40

3. Variance reduction by Conditioning

Suppose we are interested in performing a simulation study so as to


ascertain the value of = E [X ], where X is an output variable of a
simulation run. Also, suppose there is a second variable Y , such
that E [X |Y ] is known and takes on a value that can be determined
from the simulation run. Since
E [E [X | Y ]] = E [X ] =
it follows that E [X | Y ] is also an unbiased estimator of .

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

Recall the conditional variance formula proved in Section 2.10 of


Chapter 2.
Var (X ) = E [Var (X | Y )] + Var (E [X | Y ])
Since both terms on the right are nonnegative,
Var (X ) Var (E [X | Y ])
it follows that as an estimator of , E [X | Y ] is superior to the
(raw) estimator X .

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

Example 9k
Show how we can estimate by determining how often a randomly
chosen point in the square of area 4 centered around the origin falls
within the inscribed circle of radius 1. Specifically, if we let
Vi = 2Ui 1, where Ui , i = 1, 2, are random numbers, and set

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

The estimators I and (1 V12 ) 2 have mean /4.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

Since

it follows that V12 and U 2 have the same distribution, so we can


1
simplify by using the estimator (1 U 2 ) 2 where U U(0, 1).
1

What are the variances of I and (1 U 2 ) 2 ?

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation

We can illustrate the example in R:


n <- 500
v1 <- runif(n, -1, 1)
v2 <- runif(n, -1, 1)
I <- (v1^2 + v2^2) <= 1
U <- runif(n)
Z <- (1-U^2)^0.5

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

. . . continuation
Mean evolution
1.2

True value
Without conditioning
With conditioning

1.1

1.0

Mean

0.9

0.8

0.7

0.6

0.5
0

100

200

300

400

Iterations

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

500

. . . continuation

We can obtain the empirical variances of I and (1 U 2 ) 2 .


var(I)
## [1] 0.1638918
var(Z)
## [1] 0.04519196

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

Homework

Do exercises.

Freddy Hernndez BarajasUniversidad Nacional de Colombia

Reduction variance techniques

Potrebbero piacerti anche