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$?

  • $\begingroup$ What should the definition of the cdf be then? $\endgroup$ Commented Jun 13, 2020 at 13:55

1 Answer 1


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\}}$$
  • $\begingroup$ So, if I calculate the marginal $P_x(x)$ and sample from that, from perhaps an inverse cdf method. How exactly is $y$ calculated then? Because in order to calculate the numerator in the conditional probability definition I need a value of $y$. Are both values of $x$ and $y$ drawn from their own respective marginals? Then passed through the joint distribution? Sorry for the silly question, I'm just a bit confused by step 2 in your explanation. $\endgroup$ Commented Jun 13, 2020 at 14:00
  • $\begingroup$ $p_{Y|X}(y|x)=p_{X,Y}(x,y)/p_X(x)$ is the density of the distribution one need simulate from in Step 2. This distribution also has a cdf, which can be inverted to produce a simulation of $Y$, at least ideally. $\endgroup$
    – Xi'an
    Commented Jun 13, 2020 at 14:28
  • $\begingroup$ Ah, so in a way, I need to do the cumulative integral of $p_{Y \vert X}(y|x)$ w.r.t $y$. That would then give me a conditional cdf with arguments of $x$. I generate $x$ from the marginal $p_x(x)$ then generate $y$ based on this conditional cdf? If I have assumed this procedure correctly? $\endgroup$ Commented Jun 13, 2020 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.