



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!




October 2, 2008 Rice University STAT 631 / ELEC 633: Graphical Models
Instructor: Dr. Volkan Cevher
Scribes: Konstantinos Tsianos Ahmad Beirami Matthew Nokleby
Index terms: Sampling, Jacobian, Cumulative distribution function (CDF), Acceptance-rejection sampling.
We have spent considerable effort in this class approximating intractable probability distributions. These approxima- tions have several uses: they allow us to give a compact (but fairly accurate) representation for a complicated data set, or allow us to perform prediction or inference that would otherwise be impossible. The last few lectures have focused on deterministic methods for approximating probability distributions, such as the Laplace approximation, Variational Bayes, and Expectation propagation. While these methods give powerful and tractable approximate solutions, they often have no guarantee of convergence or optimality. This lecture starts the discussion about simulation methods. In deterministic methods we start with a posterior distribution that needs to be approximated. In simulation methods, we try to simulate the distribution. Specifically, we’ll approximate by drawing samples from the desired distribution. This scribe is organized as follows. In Section 2, we motivate the sampling methods with a simple example. In Section 3 we discuss sampling via by using Jacobians, which allow us to define transformations between random variables with different distributions. Finally, in Section 4 we discuss acceptance-rejection sampling, another method for generating samples from arbitrary distributions.
Suppose, for example, we have a function f (z). Then E[f (z)] =
f (z)p(z) dz, where E[·] denotes the statistical expectation. If p(z) is sufficiently complicated, we cannot compute E[f (z)] in closed form. One possibility is to evaluate the integral numerically by, for example, a Riemann sum. For instance, using uniform samples we can take the value of f at N uniformly selected points z 1 ,... , zN , and then compute
E[f ] ∼= (^) N^1
i=
f (zi)p(zi) ≡ f. (1)
As long as f (z)p(z) is Riemann integrable, this Riemann sum will converge to the true expectation as N → ∞. It turns out that this method for approximating E[f ] is not efficient in general, especially for multi-dimensional data. The required number of grid points goes up exponentially with the dimensionality of the data. (Sometimes this is called the “curse of dimensionality”.) So, we need a more efficient method of approximating E[f ]. Instead of using points on a grid, we could perform the approximation using samples that are drawn from our
distribution p(z):
E[f ] ∼= (^) N^1
i=
f (zi), zi ∼ p(z). (2)
This approach raises an important issue. Generating random samples according to a particular probability distribution function (PDF) is in general much harder than evaluating the PDF at a certain point. So, we’ll focus on methods that allow us to transform easy-to-generate samples (such as uniform or Gaussian samples) into samples from arbitrary distributions.
Assume we have vectors x = [x 1 ,... , xn]T^ and y = [y 1 ,... , yn]T^ such that x = g(y) for some vector function g. Suppose we have the integral I =
f (x) dx, and that we want to transform I into an integral over y. To do this, we need to compute the Jacobian of g(y):
∂g 1 ∂y 1 · · ·^
∂g 1 ∂yn .. . ∂gn ∂y 1 · · ·^
∂gn ∂yn
∂(x 1 ,... , xn) ∂(y 1 ,... , yn).^ (3)
Now we can write I =
f (g(y))|J|dy, where |J| is the determinant of the Jacobian. This determinant is essentially a scaling factor. Assuming integration over a small “square” in the x-space, |J| gives the “area” of the corresponding patch mapped through g onto the y-space. How can we use this to draw samples from complicated distributions? Given a function that generates samples from some simple distribution, how can we generate samples that follow a different distribution? Specifically, suppose we have a random number generator that gives us z ∼ U(0, 1), the uniform distribution over (0, 1). How do we find a function g such that, if y = g(z), then y ∼ p(y); i.e., y follows some other desired distribution p? The relation between y and z is deterministic through the bijective relation y = g(z). Therefore, y ≤ y ⇔ z ≤ z, i.e., Fy (y) = Fz (z) and we have
Fy (y) =
∫ (^) y
−∞
py (y) dy =
∫ (^) z
−∞
pz (z) dz =
∫ (^) z
0
pz (z) dz = z,
since z is uniformly distributed in [0, 1). This yields Fy (y) = z ⇒ y = F (^) y− 1 (z) where Fy is the cumulative distribution function (CDF) of y. Therefore, if we have samples from uniform distribution and we apply the function F (^) y− 1 to them, we will obtain samples that follow the distribution py.
If p(y) = λe−λy^ , then Fy (y) = 1 − e−λy^ and thus y = − (^1) λ log(1 − z), where z ∼ u(0, 1). This example is taken from [1].
Assume we have a uniform random sampler inside a square z 1 × z 2 = [0, 1] × [0, 1] i.e., z 1 and z 2 are independent and zi ∼ u(0, 1). Also consider the inscribed circle of radius 1. Given that the area of that circle is equal to π, we can try to approximate the value of π by sampling. Specifically, we generate uniform random samples for (z 1 , z 2 ). Then,
sample from by hypothesis. To see that this algorithm will result, let’s look at the CDF of the resulting samples:
x ≤ t|u ≤ (^) cba((yy))
P (x ≤ t, u ≤ (^) cba((yy)) ) P (u ≤ (^) cba((yy)) )
∫ (^) t −∞
∫ (^) cba((yy)) 0 b(x)^ dudx ∫ (^) ∞ −∞
∫ (^) cba((yy)) 0 b(x)^ dudx
∫ (^) t −∞
a(x) ∫ cb(x)^ b(x)^ dx ∞ −∞
a(x) cb(x) b(x)^ dx^
∫ (^) t ∫^ −∞ (^) ∞a(x)^ dx −∞a(x)^ dx^
∫ (^) t
−∞
a(x) dx (8)
= Fa(t). (9)
So, the CDF of the sample x is Fa(x), as desired. For any well-behaved a(x), we can always find a c > 0 such that a(x) ≤ cb(x), for a sufficiently simple b(x). But, if c is large, the algorithm will perform slowly. This is since the acceptance probability depends on the gap between of cb(x) and a(x). If c is chosen too large, the Acceptance-Rejection algorithm will have very poor efficiency.
Suppose that we only have uniform generators at hand and we need samples drawn from a Gaussian distribution (a(x) ∼ N (0, 1)). By letting b(x) = U(− 5 , 5), we can satisfy a(x)/b(x) ≤ 0. 5. As shown in Figure 1, the histogram of the samples generated in this manner follows the N (0, 1) Gaussian distribution as desired.
(^0) -4 -3 -2 -1 0 1 2 3 4
100
200
300
400
500
600
x
Figure 1: Gaussian distribution: histogram for samples generated by acceptance-rejection sampling.
Next, consider a simple “triangle” distribution defined by the density function
a(x) =
1 − |x|, for |x| ≤ 1 0 , otherwise
We can draw samples from a(x) by using acceptance-rejection sampling. By letting b(x) = U(− 1 , 1), we have a(x) ≤ 2 b(x), as shown in Figure 2. Now we can easily draw samples from b(x) and U(0, 1) and reject them according to the criterion u ≤ (^) cba((yy)). Figure 3 shows the histogram of 105 samples generated in this manner. Figures 2 and 3 agree well, showing that acceptance-rejection sampling works well in this case.
−1.5^0 −1 −0.5 0 0.5 1 1.
0.
0.
0.
0.
1
1.
x
p(x)
a(x) 2b(x)
Figure 2: Density functions for Example 2 (Triangle distribution).
[1] C. M. Bishop, Pattern Recognition and Machine Learning. Oxford: Springer, 2007.