segmentation-fault / InverseSamplingBivariate

A bivariate sampler to generate samples from a bivariate distribution

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InverseSamplingBivariate

A bivariate sampler to generate samples from a bivariate distribution

Some theory

For a univariate distribution with CDF equation , 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:

equation ,

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 equation, 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 equation
  • Then, generate a sample of Y by using the conditional CDF of Y given that X=x, i.e.

equation .

In case the marginal is not readily available, one can calculate it as:

equation .

In practice this means calculating the Joint CDF at a very high value of y (in my code I used 1e5).

Files description

  • generate_sample generates a sample from a univariate distribution given its CDF
  • generate_sample_bivariate generates two samples given the joint CDF, and, optionally, the marginal CDF
  • test_generate_sample tests the generation against some univariate distributions
  • test_bivariate tests the bivariate distribution against a multivariate exponential type II

Validation

Here two plots for the bivariate testing:

Bivariate test

Bivariate test

About

A bivariate sampler to generate samples from a bivariate distribution

License:GNU General Public License v3.0


Languages

Language:MATLAB 100.0%