Solved – Sampling from a continuous 2 dimensional probability distribution function for importance sampling

importance-samplingquantilesrandom-generationsamplingsimulation

I just want to clarify a few points with regarding to sampling from a continuous 2-dimensional probability density function. If I want to sample from this pdf, I could sample from a 1D pdf, $P(x)$, along $x$ and one along $y$ using the inverse transform sampling method. This method starts with cumulatively integrating a 1D pdf to calculate the cumulative density function,

$$ C(x) = \int^{x}_{-\infty} \frac{1}{A}P(x') \ dx' $$

Once the cdf has been calculated, it can be inverted to produce the ppf function. Once that has been done, the last step is to sample uniformly in [0,1), then pass those values through the ppf function which redistributes the initially uniformed sampled points in accordance to the original pdf.

In the case of the 2D pdf, I can repeat this process along $x$ and along $y$ to get samples for the 2D pdf. Now, if I want to calculate an integral via importance sampling MC. When I sample in accordance with the 2D pdf for $N$ samples, do I sample along $x$ and $y$ with $N$ samples each so I would have an array of (N,2) or do I sample along $x$ and $y$ with $N$ samples and calculate a $N$ by $N$ mesh of all combinations of $x$ and $y$?

Best Answer

Actually, the inverse cdf method only works in dimension one as $(F_X(X),F_Y(Y))$ is not a Uniform $\mathcal U(0,1)^2$ variate, unless $X$ and $Y$ are independent. To simulate from an arbitrary bivariate distribution with joint pdf $p_{X,Y}(x,y)$, one (among many) possible solution is to

  1. Generate $X$ from the marginal $p_X(x)=\int_{\mathcal Y} p_{X,Y}(x,y)\,\text{d}y$, possibly by inverse cdf means
  2. Generate $Y$ given $X=x$ from the conditional $p_{Y|X}(y|x)=p_{X,Y}(x,y)/p_X(x)$, again possibly by inverse cdf means

As an example, consider a joint distribution defined by the density $$p(x,y)=\frac{x^y}{y!}\exp\{-2x\}\mathbb I_{x>0}\mathbb I_{\mathbb N}(y)$$Then $$p_{Y|X}(y|x)\propto \frac{x^y}{y!} \mathbb I_{\mathbb N}(y)$$ meaning that $Y$ conditional on $X=x$ is distributed as a Poisson $\mathcal P(x)$ variate. And $$p_X(x)=\dfrac{p(x,y)}{p_{Y|X}(y|x)}=\dfrac{\frac{x^y}{y!}\exp\{-2x\}}{\frac{x^y}{y!}\exp\{-x\}}=\exp\{-x\}$$ implies that the marginal distribution of $X$ is an Exponential $\mathcal E(1)$ distribution. Hence simulating from the joint distribution can be done by

  1. generate an Exponential $\mathcal E(1)$ variate, $X=-\log(U_1)$
  2. generate a Poisson $\mathcal P(x)$ variate, $$Y=\sum_{i=1}^\infty \mathbb I_{U_2\le\sum_{j=0}^i \frac{x^i}{i!}\exp\{-x\}}$$
Related Question