2

I have a probability distribution function that I don't have its analytical form (so I can't determine its CDF). How can I generate random numbers based on this distribution function? I'm looking for a way that is similar to that of using CDF.

2 Answers2

2

Your goal is to obtain the inverse function.

Given the probability distribution $\rho(x)$ you are looking for the point $y$ such that the cumulative probability up to this point coincides with the result of a uniform distribution $U$ (you are converting a uniform distribution into your own distribution).

Therefore you have:

$$ \int_{-\infty}^y \rho(x)\,dx=U$$

The value $y$ can be obtained iteratively, for example, using Newton Raphson method:

$$y^{n+1}=y^n-\frac{\int_{-\infty}^{y^n} \rho(x)\,dx-U}{\rho(y^n)}$$

The resulting $y$ series will be arranged with a probability according to your distribution given the pair $(U,y)$ obtained from each uniform evaluation $U\rightarrow y$.

What is more, you must solve the integrals with numerical methods since you have no analytic expression for the density.

HBR
  • 1,638
  • 8
  • 7
  • Actually, it wold take a lot of time to do this, I mean computationally it's not efficient since for evaluating the integral numerically, I need to do another MC integration which makes me face the same problem. – Pourya Vakilipourtakalou Apr 12 '18 at 21:13
  • If the dimension of $x$ is low, then evaluating the integral numerically is probably a good way to go. If not, then a Markov Chain Monte Carlo method is probably best. – Brian Borchers Apr 12 '18 at 21:46
1

That is exactly what the Monte Carlo method is designed to do. One example of a method to draw samples from your distribution is the Metropolis-Hastings sampler.

Wolfgang Bangerth
  • 55,373
  • 59
  • 119