Closed
Description
Consider the following:
with pm.Model() as model:
a = pm.Uniform('a', lower=0, upper=1, shape=10)
b = pm.Binomial('b', n=1, p=a, shape=10)
b.random(size=10000).mean(axis=0)
# array([0.7022, 0.0073, 0.9857, 0.5378, 0.9821, 0.7176, 0.0905, 0.2513, 0.5835, 0.0521])
I would have expected this mean to be close to 0.5 for each element.
This is happening because the implementation for .random
methods all follow this pattern:
def random(self, point=None, size=None):
n, p = draw_values([self.n, self.p], point=point)
return generate_samples(stats.binom.rvs, n=n, p=p,
dist_shape=self.shape,
size=size)
Note that a single value is drawn for p
, and used in all draws for the random variable. Indeed, in the above example, the value drawn for p
was quite close to the mean of the draws!
This is causing strange behavior in sample_prior
(#2876). If this is considered a bug, I can fix it by allowing draw_values
to have a size
argument. Otherwise I can change #2876 to work around the behavior.
(NB: I think this does not effect any of the sampling procedures)
Metadata
Metadata
Assignees
Labels
No labels