I'm working with the following code, where I define a probability distribution proportional to $1/x^4$.
pdf = ProbabilityDistribution[
a^3 b^3/(b^3 - a^3)/x^4, {x, a, b}] /. {a -> 0.01, b -> 0.5};
RandomVariate[pdf, 10000]; // Timing
RandomVariate[pdf]; // Timing
To generate $10,000$ random variables according to this distribution or to generate 1 usually takes about the same amount of time (about 2 seconds); about half the time, $10,000$ samples is faster. I understand that there's an amazing speedup that happens because of vectorized manipulations, but this is a little ridiculous. I believe that the expensive piece here is computing the inverse CDF when I call RandomVariate
; the actual sampling part is quite quick (hence why it doesn't care about the $10,000$ number). Is there some way to store the result of the inverse CDF computation, so I can generate appropriately sampled numbers from the same PDF quickly later on?
ProbabilityDistribution[a^3 b^3/(b^3 - a^3)/x^4, {x, a, b}, Method -> "Normalize"]
. $\endgroup$