This packages allows users to define a piecewise uniform density over a hypergrid and draw samples from it.
The figure below shows an example defined on a two-dimensional grid. The left half of the figure shows a plot of the probability density function (pdf) and the right half of the figure shows a two-dimensional histogram of 1,000,000 samples. Darker colors indicate higher values.
Start Julia and run the following command:
Pkg.add("GridDensities")To use the GridDensities module, begin your code with
using GridDensitiesA grid density is defined by calling d = GridDensity(data, lo, hi, bins) where data is the relative density within each grid cell (does not need to be normalized), lo is a vector of lower bounds for each dimension, hi is a vector of upper bounds for each dimension, and bins is a vector containing the number of bins for each dimension. The following line will create the density shown in the figure above.
d = GridDensity(collect(1:8), [0.0, 0.0], [2.0, 4.0], [2, 4])To evaluate the probability density function of grid density d and at point x, run:
prob_density = pdf(d, x)To draw a sample from the distribution for grid density d, run:
sample = rand(d)To draw n samples from the distribution for grid density d, run:
samples = rand(d, n)Contributors to this package include Mykel Kochenderfer and Sydney Katz.