# How to sample Bivariate Normal Distribution with Accept reject method

I have to write python code in jupyter due to sampling bivariate normal distribution with 3 sampling methods:

1. Prior Sampling
2. Gibbs Sampling
3. Rejection Sampling

I have done the first two samplings and I also have clear understanding of what accept reject method or so-called rejection sampling is. yet I can not find any proposal distribution for it.

Rejection Sampling and proposal distribution

assume you have a distribution $$f(x)$$ which is not easy for you to sample. choose another distribution that is easy for you to sample wisely called $$g(x)$$ so that for some constant $$C$$ for all $$x$$ we have $$C.g(x) > f(x)$$.

we call this $$g(x)$$ the proposal distribution.

sample from $$g(x)$$ and name it $$X_i$$ as you chose $$g(x)$$ because it was easy to sample. accept this sample with a probability of $$p = f(X_i)/C.g(X_i)$$.

As I said before I cant find any $$g(x)$$ easy enough to sample and yet bigger than bivariate normal distribution for some $$C$$.

• Can you articulate a specific question? We are a question-and-answer site, so we require you to articulate a concrete question. I see only declarative sentences. Note that coding is off-topic here, but algorithms and methods are on-topic.
– D.W.
May 11 at 18:58

I came up with this answer which can approximately sample a bivariate normal distribution with accept reject method and I thought it might be useful for others in future.

we choose a 2D uniform distribution called $$F_{X,Y}(x,y) = F_X(x).F_Y(y)$$ where both $$X$$ and $$Y$$ are uniform distributions in range of $$(0, +a)$$ and they are independent of each other.

We choose a constant $$C$$. Both $$C$$ and $$a$$ are chosen based on our bivariate normal distribution so that:

1. for all $$x, y$$ we have $$C.F_{X,Y}(x,y) \geq BN(x,y)$$, Where $$BN$$ is our bivariate normal distribution.
2. $$x, y \in (-a, +a)$$ supports most of our $$BN$$ density.

The Accept Reject Method:

1. Now we sample from our $$F_{X,Y}(x,y)$$. Suppose it's $$X1 = (x1, y1)$$.

2. We uniformly choose from: $$X_{1.1} = (x1, y1),$$ $$X_{1.2}=(-x1, y1),$$ $$X_{1.3}=(x1, -y1),$$ $$X_{1.4} = (-x1, -y1)$$ and name that $$\hat{X_1}$$ so that we consider all four quadrants of $$xOy$$.

3. Now we accept $$\hat{X_1}$$ as a sample of $$BN$$ with a probability of $$p=BN(x1,y1)/C.f_{X,Y}(x,y)$$.

4. We come back to step 1 and do this cycle to collect as much sample from the bivariate normal distribution as we want.