Importance sampling

Importance sampling is a method to study one distribution while sampling from another. Essentially, it performs biased sampling to generate pseudorandom numbers more sparingly. For example, instead of taking the points from a uniform distribution, the points are chosen from a distribution that concentrates the points in the region of interest of the function being integrated, thus focusing on the most important samples. The formula for the integrand can be written as follows:

Importance sampling

To perform importance sampling, we need to do the following:

  • Generate n random numbers (x1, x2, …, xi) approximately g(x)
  • Introduce weights f(x)/g(x) and estimate the integrand as Importance sampling, where x is approximately equal to g
  • Compute the Monte Carlo estimate for the integrand as follows:
Importance sampling

For example, let's estimate the integral Importance sampling using this method.

Using the truncated exponential sampling distribution (λ = 0.65) truncated at T = 1, we can write:

Importance sampling
Importance sampling

Hence, Importance sampling becomes Importance sampling and the integral can be estimated as Importance sampling.

Now implement this in R as follows:

> set.seed(23564)
> n <- 100000
> T  <- 1
> lambda <- 0.65
> Rand.num <- runif(n,0,1)*(1-exp(-T*lambda))
> x = -log(1-Rand.num)/lambda
> f<-exp(-x)
> g<-lambda*exp(-lambda*x)/(1-exp(-T*lambda))
> fg<-f/g
> sum(fg)/n
[1] 0.6320664

Now let's see what we get using the standard Monte Carlo integration:

> set.seed(23564)
> X <- runif(100000, 0, 1)
> Y <- exp(-X)
> mean(Y)
[1] 0.6319162

Although both methods produce similar results, the estimate using the importance method is much closer to the true value of Importance sampling. Let's compare the variance of the two sample distributions using the following lines of code:

# Importance Sampling
> var(fg)
[1] 0.003894969
#Standard Monte Carlo Integration 
> var(Y)
[1] 0.03267516

As you can see, we achieve a much better estimation using the importance sampling method; we obtain 8.4 times less variance than with simple Monte Carlo integration.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.132.99