



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Monday, November 17, 2008 Rice University STAT 631 / ELEC 639: Graphical Models
Instructor: Dr. Volkan CEVHER
Scribe: Ryan E. Guerra ( [email protected] ) Tahira N. Saleem ( [email protected] ) Terrance D. Savitsky ( [email protected] )
In machine learning and statistics, we’re often tasked with computing the expected value of a function f (x) with respect to a probability distribution p(x), where x ∈ Rn. In many cases, the canonical technique of evaluating the integral (^) ∫
x
f (x)p(x)dx,
is intractable due to the nature or complexity of p(x). On one hand, if a cumulative distribution function is non-decreasing and easily invertible then we can draw samples from its distribution by using inverse transform sampling [1] where we map i.i.d. samples from U [0, 1] through the inverse CDF P −^1 (y). If one wishes to draw samples from a multivariate Gaussian distribution, then the well-known Box-Muller method [1] will suffice. On the other hand, many distributions are difficult or impossible to invert, and in some cases a closed-form representation might not exist or be computationally intractable to obtain. This is a problem since finding expected values of functions is often a step in larger engineering problems or algorithms. Importance sampling is a discrete method for approximating I[f ] = Ep[f (x)] by replacing p(x) with a similar, but easily sampled, distribution q(x) and then correcting for the error introduced by making this switch. It is generally cited as a Monte Carlo variance reduction technique in that it provides a framework for reducing the computational complexity of computing the expectation I[f ] while directly relating the complexity to decreased simulation variance. In this paper, we will try to develop the theory of importance sampling and highlight certain important properties to consider when utilizing the technique. In the final section we present a MATLAB simulation with discussion.
Consider a set of samples {x(i)} generated from p(x), a given probability distribution. Then the form of the expectation of f (x) under p in (1) can be approximated by the average of f (x) evaluated at those samples (2). For the sake of notation, we will be using I[f ] to represent the expectation throughout this discussion.
I[f ] = Ep[f (x)] =
f (x)p(x)dx (1)
i=
f (x(i)) (2)
As in the previous section, we are operating under the assumption that while we can evaluate the value of p(x) at a given x, we cannot easily draw the samples from the distribution needed for our estimate. To deal
with this, we introduce another distribution q(x) called the sampling distribution that we will draw samples {x(i)} from instead.
I[f ] =
f (x) p(x) q(x)
q(x)dx
i=
p(x(i)) q(x(i))
f (x(i))
Iˆ[f ] = 1 N
i=
wf ˜ (x(i)), w˜ =
p(x(i)) q(x(i))
The basic idea of importance sampling is to draw from a similar distribution other than p(x), say q(x), and then modify the resulting equation to correct the bias introduced by sampling from the wrong distribution. In (3) we can see that the bias correction, or the importance weight w˜ can be determined exactly for a given x(i)^ since we assumed that we could evaluate p(x) at a point. In practice, our actual p(x) or q(x) will often be unnormalized [1], in other words p(x) = (^) Z^1 p p˜(x) and
q(x) = (^) Z^1 q q˜(x) so that
w ˜ =
p(x(i)) q(x(i))
Zq Zp
p ˜(x(i)) q˜(x(i))
where
Zp Zq
p˜(x)dx Zq
p˜(x) q˜(x)
q(x)
i=
p ˜(x) q˜(x)
and we have used the set of our samples from q(x) in order to estimate the normalization factor in (4). If we redefine our importance weight as wi we emerge with two forms of our approximation, where (6) is simply the approximation derived in (3)
I^ ˆ 1 [f ] =
i=
wif (x(i)), wi =
p˜(x(i))/q˜(x(i)) ∑N k=1 p˜(x(k))/q˜(x(k))^
I^ ˆ 2 [f ] = 1 N
i=
p(x(i)) q(x(i))
f (x(i)) (6)
It is important to note that (5) is an approximation where the probability distribution of q(x) has been approximated twice : once for the main term and once to normalize the importance weights in (4). This approximation is necessary when there is no guarantee that either p(x) or q(x) are normalized. The second form of the approximation (6) assumes that both distributions are normalized and generally will not be
equal to the original except for in the expectation: E
I[f ] − Iˆi[f ]
There is one particular property to keep in mind when using the importance sampling method. Clearly, as the number of samples is increased the variance of our estimation Iˆ[f ] will decrease. Since E{ Iˆ[f ]} = I[f ], this is quantified in [2] as the asymptotic variance σ f^2 ,
var( Iˆ[f ]) =
σ^2 f N =^
f 2 (x)p^2 (x) q(x) dx^ −^ I
(^2) [f ]
0 1 2 3 4 5 6
−0.
−0.
0
1
x
p(x) q(x) p(x)f(x)
Figure 1: A plot of p(x) and q(x) shows how well the sampling distribution covers p(x). We show p(x)f (x) in order to justify using numerical evaluation from [0,5] to approximate the expectation.
% MATLAB code for implementing a simple importance sampling scheme % Ryan Guerra % Nov 17, 2008 clear all; mu = 0.8; % gaussian mean parameter sigma = sqrt(1.5); % gaussian standard deviation parameter k=1.65; % chi DOF parameter c=2; % multiplicative constant to make p < cq num_iterations = 100; % number of Monte Carlo runs to execute p = @(x) x^(k-1)exp(-x^2/2); % target distribution q = @(x) c/sqrt(2pisigma^2)... % sampling distribution exp(-(mu-x)^2/(2sigma^2)); f = @(x) 2sin(pi/1.5x); % function we want to take expectation of for iter=1:num_iterations samp_size = 1000; % number of initial samples to draw from q X = normrnd(mu,sigma,[samp_size 1]); % generate vector of samples from q for i=1:length(X) if X(i)>=0 % we will discard all sampled X that are not in the support of p W(i) = p(X(i))/q(X(i)); % calculate importance weight for sample i I(i) = W(i)f(X(i)); % weigh our function else W(i)=0; % these values will be ignored I(i)=0; samp_size = samp_size - 1; end end I_hat = sum(I)/sum(W); % perform summation in (5) [tmp tmp2 non_zero_weights] = find(W); % remove all discarded importance weights variance = var(non_zero_weights); % calculate the variance of the importance weights eff_samp_size = samp_size/(1 + variance); % calculate the effective sample size format short g % store the results of this run results(iter,:) = [I_hat variance samp_size eff_samp_size]; end % print compiled results totals = [mean(results(:,1)) mean(results(:,2)) mean(results(:,3)) mean(results(:,4));... var(results(:,1)) var(results(:,2)) var(results(:,3)) var(results(:,4))] In order to explore the effects of selecting a poor distribution to cover p, we repeat the experiment and shift the mean of q so that the centers of mass for each distribution are far apart. Again, our N 0 = { 10 , 100 , 103 , 104 }
0 1 2 3 4 5 6 7 8 9 10
0
x
p(x) q(x)
Figure 2: By shifting the mean of the sampling distribution to μ = 6, we can see the results of choosing a q(x) with a center of mass far away from p(x).
Sample Size Per Trial
Good Sampling Distribution Match Poor Sampling Distribution Match Estimate Weight Variance Sample Size ESS Estimate Weight Variance Sample Size ESS 10 Mean of 100 Trials 0.795140 0.06476 7.3 6.88 0.3675 14.00 10 9. Trial Variance 0.221170 0.0011 1.94 1.71 1.78 12,144 0 6 100 Mean of 100 Trials 0.730630 0.06824 74.1 69.41 0.3304 6.81 100 88. Trial Variance 0.025659 0.00010 17.82 16.14 1.38 2,455 0 691 1000 Mean of 100 Trials 0.764220 0.07020 744.9 696.07 -0.8650 1,110.80 1,000 391. Trial Variance 0.001929 0.000011 201 190 0.81 31,354,000 0 144, 10000 Mean of 100 Trials 0.768300 0.06970 7,434 6,949.70 -0.1625 6,199.90 10,000 343. Trial Variance 0.000219 0.000001 2,415 2,136 1.07 437,300,000 0 407,
When this code is run with several different sample sizes N 0 = { 10 , 100 , 103 , 104 } we can see that around 25% of our samples from q(x) are discarded as being unsupported, thus making our real sample sizes on average N = { 7 , 74 , 745 , 7434 }. Naturally, when the mean of our sampling distribution is shifted to μ = 6, the probability of sampling an unsupported x value becomes negligibly small. Numerical evaluation of Ep{f (x)} on the interval [0, 5] with MATLAB’s adaptive Simpson quadrature integrator yields 0.7753 for comparison with our results. As expected, when we have a sampling distribution that closely matches our target distribution then an increased sample size has an inverse relationship to the Monte Carlo simulation variance. This can be interpreted as a direct result of the effective sample size scaling linearly with increased sample size due to the constant variance of the importance weights. When our sampling distribution is a poor match, we can see that an increased sample size has little or no effect on the Monte Carlo simulation variance. As we can see, this is a direct result of the effective sample size failing to scale with sample size. Thus naively increasing the sample size without improving our sampling distribution will lead to dramatically decreased computational efficiency without any tangible benefit. While we chose a sampling distribution in this experiment by empirical observation, an even better method would be to use the result of a Laplace approximation or optimizing the α-divergence as recom- mended in the previous section to discover an optimal sampling distribution. This would be required in a more complicated problem where observation is not possible.