# Importance sampling

In statistics, importance sampling is a general technique for estimating properties of a particular distribution, while only having samples generated from a different distribution than the distribution of interest. It is related to umbrella sampling in computational physics. Depending on the application, the term may refer to the process of sampling from this alternative distribution, the process of inference, or both.

## Basic theory

Let ${\displaystyle X:\Omega \to \mathbb {R} }$  be a random variable in some probability space ${\displaystyle (\Omega ,{\mathcal {F}},P)}$ . We wish to estimate the expected value of X under P, denoted E[X;P]. If we have statistically independent random samples ${\displaystyle x_{1},\ldots ,x_{n}}$ , generated according to P, then an empirical estimate of E[X;P] is

${\displaystyle {\widehat {\mathbf {E} }}_{n}[X;P]={\frac {1}{n}}\sum _{i=1}^{n}x_{i}}$

and the precision of this estimate depends on the variance of X:

${\displaystyle \operatorname {var} [{\widehat {\mathbf {E} }}_{n};P]={\frac {\operatorname {var} [X;P]}{n}}.}$

The basic idea of importance sampling is to sample the states from a different distribution to lower the variance of the estimation of E[X;P], or when sampling from P is difficult. This is accomplished by first choosing a random variable ${\displaystyle L\geq 0}$  such that E[L;P] = 1 and that P-almost everywhere ${\displaystyle L(\omega )\neq 0}$ . With the variate L we define a probability ${\displaystyle P^{(L)}}$  that satisfies

${\displaystyle \mathbf {E} [X;P]=\mathbf {E} \left[{\frac {X}{L}};P^{(L)}\right].}$

The variable X/L will thus be sampled under P(L) to estimate E[X;P] as above and this estimation is improved when ${\displaystyle \operatorname {var} \left[{\frac {X}{L}};P^{(L)}\right]<\operatorname {var} [X;P]}$ .

When X is of constant sign over Ω, the best variable L would clearly be ${\displaystyle L^{*}={\frac {X}{\mathbf {E} [X;P]}}\geq 0}$ , so that X/L* is the searched constant E[X;P] and a single sample under P(L*) suffices to give its value. Unfortunately we cannot take that choice, because E[X;P] is precisely the value we are looking for! However this theoretical best case L* gives us an insight into what importance sampling does:

{\displaystyle {\begin{aligned}\forall a\in \mathbb {R} ,\;P^{(L^{*})}(X\in [a;a+da])&=\int _{\omega \in \{X\in [a;a+da]\}}{\frac {X(\omega )}{E[X;P]}}\,dP(\omega )\\[6pt]&={\frac {1}{E[X;P]}}\;a\,P(X\in [a;a+da])\end{aligned}}}

to the right, ${\displaystyle a\,P(X\in [a;a+da])}$  is one of the infinitesimal elements that sum up to E[X;P]:

${\displaystyle E[X;P]=\int _{a=-\infty }^{+\infty }a\,P(X\in [a;a+da])}$

therefore, a good probability change P(L) in importance sampling will redistribute the law of X so that its samples' frequencies are sorted directly according to their weights in E[X;P]. Hence the name "importance sampling."

Importance sampling is often used as a Monte Carlo integrator. When ${\displaystyle P}$  is the uniform distribution and ${\displaystyle \Omega =\mathbb {R} }$ , E[X;P] corresponds to the integral of the real function ${\displaystyle X:\mathbb {R} \to \mathbb {R} }$ .

## Application to probabilistic inference

Such methods are frequently used to estimate posterior densities or expectations in state and/or parameter estimation problems in probabilistic models that are too hard to treat analytically, for example in Bayesian networks.

## Application to simulation

Importance sampling is a variance reduction technique that can be used in the Monte Carlo method. The idea behind importance sampling is that certain values of the input random variables in a simulation have more impact on the parameter being estimated than others. If these "important" values are emphasized by sampling more frequently, then the estimator variance can be reduced. Hence, the basic methodology in importance sampling is to choose a distribution which "encourages" the important values. This use of "biased" distributions will result in a biased estimator if it is applied directly in the simulation. However, the simulation outputs are weighted to correct for the use of the biased distribution, and this ensures that the new importance sampling estimator is unbiased. The weight is given by the likelihood ratio, that is, the Radon–Nikodym derivative of the true underlying distribution with respect to the biased simulation distribution.

The fundamental issue in implementing importance sampling simulation is the choice of the biased distribution which encourages the important regions of the input variables. Choosing or designing a good biased distribution is the "art" of importance sampling. The rewards for a good distribution can be huge run-time savings; the penalty for a bad distribution can be longer run times than for a general Monte Carlo simulation without importance sampling.

Consider ${\displaystyle X}$  to be the sample and ${\displaystyle {\frac {f(X)}{g(X)}}}$  to be the likelihood ratio, where ${\displaystyle f}$  is the probability density (mass) function of the desired distribution and ${\displaystyle g}$  is the probability density (mass) function of the biased/proposal/sample distribution. Then the problem can be characterized by choosing the sample distribution ${\displaystyle g}$  that minimizes the variance of the scaled sample:

${\displaystyle g^{*}=\min _{g}\operatorname {var} _{g}\left(X{\frac {f(X)}{g(X)}}\right).}$

It can be shown that the following distribution minimizes the above variance:[1]

${\displaystyle g^{*}(X)={\frac {|X|f(X)}{\int |x|f(x)\,dx}}.}$

Notice that when ${\displaystyle X\geq 0}$ , this variance becomes 0.

### Mathematical approach

Consider estimating by simulation the probability ${\displaystyle p_{t}\,}$  of an event ${\displaystyle X\geq t}$ , where ${\displaystyle X}$  is a random variable with distribution ${\displaystyle F}$  and probability density function ${\displaystyle f(x)=F'(x)\,}$ , where prime denotes derivative. A ${\displaystyle K}$ -length independent and identically distributed (i.i.d.) sequence ${\displaystyle X_{i}\,}$  is generated from the distribution ${\displaystyle F}$ , and the number ${\displaystyle k_{t}}$  of random variables that lie above the threshold ${\displaystyle t}$  are counted. The random variable ${\displaystyle k_{t}}$  is characterized by the Binomial distribution

${\displaystyle P(k_{t}=k)={K \choose k}p_{t}^{k}(1-p_{t})^{K-k},\,\quad \quad k=0,1,\dots ,K.}$

One can show that ${\displaystyle \operatorname {E} [k_{t}/K]=p_{t}}$ , and ${\displaystyle \operatorname {var} [k_{t}/K]=p_{t}(1-p_{t})/K}$ , so in the limit ${\displaystyle K\to \infty }$  we are able to obtain ${\displaystyle p_{t}}$ . Note that the variance is low if ${\displaystyle p_{t}\approx 1}$ . Importance sampling is concerned with the determination and use of an alternate density function ${\displaystyle f_{*}\,}$ (for ${\displaystyle X}$ ), usually referred to as a biasing density, for the simulation experiment. This density allows the event ${\displaystyle {X\geq t\ }}$  to occur more frequently, so the sequence lengths ${\displaystyle K}$  gets smaller for a given estimator variance. Alternatively, for a given ${\displaystyle K}$ , use of the biasing density results in a variance smaller than that of the conventional Monte Carlo estimate. From the definition of ${\displaystyle p_{t}\,}$ , we can introduce ${\displaystyle f_{*}\,}$  as below.

{\displaystyle {\begin{aligned}p_{t}&={E}[1(X\geq t)]\\[6pt]&=\int 1(x\geq t){\frac {f(x)}{f_{*}(x)}}f_{*}(x)\,dx\\[6pt]&=E_{*}[1(X\geq t)W(X)]\end{aligned}}}

where

${\displaystyle W(\cdot )\equiv {\frac {f(\cdot )}{f_{*}(\cdot )}}}$

is a likelihood ratio and is referred to as the weighting function. The last equality in the above equation motivates the estimator

${\displaystyle {\hat {p}}_{t}={\frac {1}{K}}\,\sum _{i=1}^{K}1(X_{i}\geq t)W(X_{i}),\,\quad \quad X_{i}\sim f_{*}}$

This is the importance sampling estimator of ${\displaystyle p_{t}\,}$  and is unbiased. That is, the estimation procedure is to generate i.i.d. samples from ${\displaystyle f_{*}\,}$  and for each sample which exceeds ${\displaystyle t\,}$ , the estimate is incremented by the weight ${\displaystyle W\,}$  evaluated at the sample value. The results are averaged over ${\displaystyle K\,}$  trials. The variance of the importance sampling estimator is easily shown to be

{\displaystyle {\begin{aligned}\operatorname {var} _{*}{\widehat {p}}_{t}&={\frac {1}{K}}\operatorname {var} _{*}[1(X\geq t)W(X)]\\[5pt]&={\frac {1}{K}}\left\{{E_{*}}[1(X\geq t)^{2}W^{2}(X)]-p_{t}^{2}\right\}\\[5pt]&={\frac {1}{K}}\left\{{E}[1(X\geq t)W(X)]-p_{t}^{2}\right\}\end{aligned}}}

Now, the importance sampling problem then focuses on finding a biasing density ${\displaystyle f_{*}\,}$  such that the variance of the importance sampling estimator is less than the variance of the general Monte Carlo estimate. For some biasing density function, which minimizes the variance, and under certain conditions reduces it to zero, it is called an optimal biasing density function.

### Conventional biasing methods

Although there are many kinds of biasing methods, the following two methods are most widely used in the applications of importance sampling.

#### Scaling

Shifting probability mass into the event region ${\displaystyle {X\geq t\ }}$  by positive scaling of the random variable ${\displaystyle X\,}$  with a number greater than unity has the effect of increasing the variance (mean also) of the density function. This results in a heavier tail of the density, leading to an increase in the event probability. Scaling is probably one of the earliest biasing methods known and has been extensively used in practice. It is simple to implement and usually provides conservative simulation gains as compared to other methods.

In importance sampling by scaling, the simulation density is chosen as the density function of the scaled random variable ${\displaystyle aX\,}$ , where usually ${\displaystyle a>1}$  for tail probability estimation. By transformation,

${\displaystyle f_{*}(x)={\frac {1}{a}}f{\bigg (}{\frac {x}{a}}{\bigg )}\,}$

and the weighting function is

${\displaystyle W(x)=a{\frac {f(x)}{f(x/a)}}\,}$

While scaling shifts probability mass into the desired event region, it also pushes mass into the complementary region ${\displaystyle X  which is undesirable. If ${\displaystyle X\,}$  is a sum of ${\displaystyle n\,}$  random variables, the spreading of mass takes place in an ${\displaystyle n\,}$  dimensional space. The consequence of this is a decreasing importance sampling gain for increasing ${\displaystyle n\,}$ , and is called the dimensionality effect. A modern version of importance sampling by scaling is e.g. so-called sigma-scaled sampling (SSS) which is running multiple Monte Carlo (MC) analysis with different scaling factors. In opposite to many other high yield estimation methods (like worst-case distances WCD) SSS does not suffer much from the dimensionality problem. Also addressing multiple MC outputs causes no degradation in efficiency. On the other hand, as WCD, SSS is only designed for Gaussian statistical variables, and in opposite to WCD, the SSS method is not designed to provide accurate statistical corners. Another SSS disadvantage is that the MC runs with large scale factors may become difficult, e. g. due to model and simulator convergence problems. In addition, in SSS we face a strong bias-variance trade-off: Using large scale factors, we obtain quite stable yield results, but the larger the scale factors, the larger the bias error. If the advantages of SSS does not matter much in the application of interest, then often other methods are more efficient.

#### Translation

Another simple and effective biasing technique employs translation of the density function (and hence random variable) to place much of its probability mass in the rare event region. Translation does not suffer from a dimensionality effect and has been successfully used in several applications relating to simulation of digital communication systems. It often provides better simulation gains than scaling. In biasing by translation, the simulation density is given by

${\displaystyle f_{*}(x)=f(x-c),\quad c>0\,}$

where ${\displaystyle c\,}$  is the amount of shift and is to be chosen to minimize the variance of the importance sampling estimator.

### Effects of system complexity

The fundamental problem with importance sampling is that designing good biased distributions becomes more complicated as the system complexity increases. Complex systems are the systems with long memory since complex processing of a few inputs is much easier to handle. This dimensionality or memory can cause problems in three ways:

In principle, the importance sampling ideas remain the same in these situations, but the design becomes much harder. A successful approach to combat this problem is essentially breaking down a simulation into several smaller, more sharply defined subproblems. Then importance sampling strategies are used to target each of the simpler subproblems. Examples of techniques to break the simulation down are conditioning and error-event simulation (EES) and regenerative simulation.

### Variance cost function

Variance is not the only possible cost function for a simulation, and other cost functions, such as the mean absolute deviation, are used in various statistical applications. Nevertheless, the variance is the primary cost function addressed in the literature, probably due to the use of variances in confidence intervals and in the performance measure ${\displaystyle \sigma _{MC}^{2}/\sigma _{IS}^{2}\,}$ .

An associated issue is the fact that the ratio ${\displaystyle \sigma _{MC}^{2}/\sigma _{IS}^{2}\,}$  overestimates the run-time savings due to importance sampling since it does not include the extra computing time required to compute the weight function. Hence, some people evaluate the net run-time improvement by various means. Perhaps a more serious overhead to importance sampling is the time taken to devise and program the technique and analytically derive the desired weight function.

## Notes

1. ^ Rubinstein, R. Y., & Kroese, D. P. (2011). Simulation and the Monte Carlo method (Vol. 707). John Wiley & Sons.

## References

• Arouna, Bouhari (2004). "Adaptative Monte Carlo Method, A Variance Reduction Technique". Monte Carlo Methods and Their Applications. 10 (1): 1–24. doi:10.1515/156939604323091180.
• Bucklew, James Antonio (2004). Introduction to Rare Event Simulation. New York: Springer-Verlag.
• Doucet, A.; de Freitas, N.; Gordon, N. (2001). Sequential Monte Carlo Methods in Practice. Springer. ISBN 978-0-387-95146-1.
• Ferrari, M.; Bellini, S. (2001). Importance Sampling simulation of turbo product codes. The IEEE International Conference on Communications. 9. pp. 2773–2777. doi:10.1109/ICC.2001.936655. ISBN 978-0-7803-7097-5.
• Mazonka, Oleg (2016). "Easy as Pi: The Importance Sampling Method" (PDF). Journal of Reference. 16.
• Oberg, Tommy (2001). Modulation, Detection, and Coding. New York: John Wiley & Sons.
• Press, WH; Teukolsky, SA; Vetterling, WT; Flannery, BP (2007). "Section 7.9.1 Importance Sampling". Numerical Recipes: The Art of Scientific Computing (3rd ed.). New York: Cambridge University Press. ISBN 978-0-521-88068-8.
• Ripley, B. D. (1987). Stochastic Simulation. Wiley & Sons.
• Smith, P. J.; Shafi, M.; Gao, H. (1997). "Quick simulation: A review of importance sampling techniques in communication systems". IEEE Journal on Selected Areas in Communications. 15 (4): 597–613. doi:10.1109/49.585771.
• Srinivasan, R. (2002). Importance sampling – Applications in communications and detection. Berlin: Springer-Verlag.