Python implementation to generate samples from a bivariate continuous distribution
For a univariate distribution with CDF , we can generate a sample from said distribution via the inverse sampling theorem; if the random variable U is drawn from a uniform distribution between 0 and 1, then a realization of the random variable X is:
or, the inverse of the CDF of X calculated in a random outcome of the uniform distribution between 0 and 1.
For a bivariate distribution with CDF , we can approximate the generation of two samples by following those two steps:
- Generate a sample from X with the Inverse sampling theorem, using the marginal CDF
- Then, generate a sample of Y by using the conditional CDF of Y given that X=x, i.e.
In case the marginal is not readily available, one can calculate it as:
In practice this means calculating the Joint CDF at a very high value of y (in my code I used 1e5).