Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Probabilistic Graphical Models in R

You're reading from   Learning Probabilistic Graphical Models in R Familiarize yourself with probabilistic graphical models through real-world problems and illustrative code examples in R

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher Packt
ISBN-13 9781784392055
Length 250 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Rejection sampling


Suppose we want to sample from a distribution that is not a simple one. Let's call this distribution p(x) and let's assume we can evaluate p(x) for any given value x, up to a normalizing constant Z, that is:

In this context, p(x) is too complex to sample from but we have another simpler distribution q(x) from which we can draw samples. Next, we assume there exists a constant k such that for all values of x. The function kq(x) is the comparison function as shown in the following figure:

The distribution p(x) has been generated with a simple plot:

0.6*dnorm(x,1)+0.4*dnorm(x,5)

The rejection sampling algorithm is based on the following idea:

  • Draw a sample z0 from q(z), the proposal distribution

  • Draw a second u0 sample from a uniform distribution on [0, kq(z0)]
  • If then the sample is rejected otherwise u0 is accepted

In the following figure, the pair (z0, u0) is rejected if it lies in the gray area. The accepted pairs are a uniform distribution under the curve of p(z) and therefore...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime