Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
can be approximated by
1∑
n
I˜ = g(xi ),
n i=1
where x1 , · · · , xn are drawn independently according to the density f (x) in the interval [a, b].
The above formula is generic and very useful. However, in practice we need to compute integrals
given in the form ∫ b
I= g(x)dx
a
In other words, the density from which to draw the empirical observations for approximation
is missing. One way around it is reformulate the integral with the weight function from which
realizations can be drawn. That’s called the importance function.
∫ b ∫ b( )
g(x)
I= g(x)dx = w(x)dx,
a a w(x)
where x1 , · · · , xn are drawn independently according to the density w(x) in the interval [a, b].
Let X be a continuous random variable with pdf fX (x). Then,
∫ b ∫ b ( ) ∫ b
1
I = Pr[a ≤ X ≤ b] = fX (x)dx = (b − a) fX (x) dx = (b − a) fX (x)u(x)dx
a a b−a a
where where x1 , · · · , xn are drawn independently from a uniform distribution in the interval
iid
[a, b] or more succinctly, Xi ∼ Unif[a, b].
1-1
If one can sample directly according to fX (x), then one can use the indicator function IA (x)
to compute the probability as an expectation. Recall, that
{
1 if x ∈ A
IA (x) =
0 if x ∈ /A
Now, the probability of an event can be reformulated as an expected value as follows,
∫ b ∫
I = Pr[a ≤ X ≤ b] = fX (x)dx = I[a,b] (x)fX (x)dx = E[I[a,b] (X)],
a RX
where x1 , · · · , xn are drawn independently according to the cdf FX (x) over the whole range of
the random variable X.
where the z1 , · · · , zn are drawn independently from the standard normal distribution.
n <- 10000
z <- rnorm(n)
proba <- length(which(abs(z)<2))/n
print(proba)
n <- 10000
u <- runif(n,-2,2)
proba <- (4/n)*sum(dnorm(u))
print(proba)
Exercise: Compute Pr[ 21 ≤ X ≤ 34 ] where X ∼ FX (x) with fX (x) = 3x2 in [0, 1].
1-2
Monte Carlo Approximations in High Dimensions
Consider now two random variables X1 and X2 with joint density function f (x1 , x2 ) defined on
X1 × X2 . We now show how to compute probabilities in such a context.
∫ a12 ∫ a12
I = Pr[a11 ≤ X1 ≤ a12 ∩ a21 ≤ X2 ≤ a22 ] = f (x1 , x2 )dx1 dx2
a11 a11
where the sample {(xi1 , xi2 ), i = 1, · · · , n} is drawn iid from the multivariate uniform distribu-
tion in [a11 , a12 ] × [a21 , a22 ], namely (Xi1 , Xi2 ) ∼ MVUnif([a11 , a12 ] × [a21 , a22 ]).
Now, if X1 ∈ [a, b] and X1 ∈ [c, d], then one could also approximation I using
where the sample {(xi1 , xi2 ), i = 1, · · · , n} is drawn iid from the multivariate uniform distribu-
tion in [a, b] × [c, d], namely (Xi1 , Xi2 ) ∼ MVUnif([a, b] × [c, d]).
Example: X1 and X2 are defined on [0, 1] × [0, 1] with density f (x1 , x2 ) = 4x1 x2 . Compute
( 1 − 1 )( 3 − 1 ) ∑
n
I˜MC = 2 3 4 2 4xi1 xi2
n i=1
1-3
Multivariate Monte Carlo in R
f <- function(x1,x2){return(4*x1*x2)}
n <- 100000
a11 <- 1/3; a12 <- 1/2; a21 <- 1/2; a22<-3/4
x1 <- runif(n, a11,a12)
x2 <- runif(n, a21,a22)
# Monte Carlo
probMC <- ((a12-a11)*(a22-a21)/n)*sum(f(x1,x2))
print(probMC.2)
1-4