I would like to specify a K-dimensional flat Dirichlet distribution such that each dimension is effectively sampled uniformly, and such that each K-dimensional sample sums to 1.
Based on Wikipedia’s Dirichlet distribution article, I was expecting that if all K concentration parameters were set to 1, each dimension would be uniformly sampled. That is, if I drew many samples from pm.Dirichlet.dist(a=np.ones(K))
then the K marginal distributions would all be approximately uniform or flat. The following snippet attempts to test this.
import numpy as np
import matplotlib.pyplot as plt
import pymc as pm
import arviz as az
n_params = 4
samples = pm.draw(pm.Dirichlet.dist(a=np.ones(n_params)), draws=2048)
print(samples.shape)
print(np.all(np.isclose(1, samples.sum(axis=-1))))
fig, ax = plt.subplots(nrows=n_params, sharex=True)
for i_param, _ax in enumerate(ax):
az.plot_dist(samples[...,i_param], rug=False, ax=_ax)
>> (2048, 4)
>> True
However, when I run the above snippet, the marginal distributions do not appear flat, but rather are skewed right. Below is the plot of the marginal distributions from the above snippet.
The “Create an array of standard uniform distributions” thread poses essentially the same question (see item 2 from that thread below), and the proposed solution is similar to the above snippet. Likewise, that proposed solution yields the same results as I’ve observed above.
- An square array X of independent random variables. Each element of the array follows the standard uniform distribution
- Same as X, except each column is constrained to sum to one. To sample from this distribution, I can use
y = np.random.uniform(0, 1, size=(5, 5)); y /= np.sum(y, axis=0)
Am I misunderstanding how to specify a flat Dirichlet distribution? Is it possible to specify a Dirichlet distribution that is uniform over all points in its support? Perhaps I’m misunderstanding how the marginal distributions should look for a flat Dirichlet distribution?
Version info:
python 3.12.2
pytensor 2.25.2
pytensor-base 2.25.2
pymc 5.16.2
pymc-base 5.16.2
macOS 14.5
Apple M3 Max