Grid sampling is a simple way to obtain samples of some random variable from a distribution . The main idea is to discretize by evaluating it along a grid of values, then sampling from the values proportionally.

The procedure is as follows:

  1. Select a grid of values for .
  2. For each grid value, calculate .
  3. Sample a grid value with probability .

Finding an appropriate grid can often be trial-and-error, and ideally, the grid should cover all values of with non-zero probability, and it shouldnโ€™t contain many values with zero probability.

Multi-Dimensional Sampling

If we have multiple variables, we can select a grid of values for each and loop over all joint probabilities. For example, with two parameters and :

  1. Select a grid of values for and another grid for .
  2. For each pair, compute .
  3. Calculate marginal probabilities .
  4. Calculate conditional probabilities .
  5. Sample using .
  6. Sample using .