1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Rejection sampling from gamma distribution

  1. Dec 19, 2009 #1
    1. The problem statement, all variables and given/known data
    So this isn't homework, but it's on the level of a homework question, so I'll put it here. I'm trying to figure out how to sample just one value from a gamma distribution using rejection sampling.

    2. Relevant equations
    How to do it:
    page 10
    http://www.thefutureofmath.com/matlabstuff/matlabintro.pdf [Broken]

    3. The attempt at a solution
    I understand the loop until a value is found, and I understand finding a maximum to compare [gammadistribution] against a [maxval*uniform(0,1)].
    But for x in the gammadistribution, they use [tex]\left|kt^2 \mathrm{randn} +kt \right|[/tex] as x. What is this? Shape parameter times scale parameter squared times a normal distribution plus the scale parameter times the shape parameter? What? My eventual goal is to sample from an arbitrary function, and I think if I can figure out where they're picking this x from I understand the rest.
    Last edited by a moderator: May 4, 2017
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted