Hello all! I took the semester off of school in order to work through Bayesian Modeling and Computation in Python book, which is much more interesting than anything my school teaches
I hit my first snag while working through practice problem 1M21 in the first chapter. It’s a multi-layer problem, asking to run various combinations of options. I first simplified and chose just one scenario:
“A store is visted by n customers ona given day. The number of customers that make a purchase Y is distributed as Bin(n,theta), where theta is the probability that a customer makes a purchase. Assume we know theta and the prior for n is Pois(4.5). Use PyMC3 to compute the posterior distribution of n for Y=5 and theta=0.5”.
I simplified the last sentence and chose just one scenario, for purposes of this post.
My code is:
import numpy as np
import pymc3 as pm
# We observe 5 purchases.
Y = 5
# Model.
with pm.Model() as model:
# Specify the prior distribution of unknown parameter n.
n = pm.Poisson("n", mu=4.5)
# Specify known value of theta.
theta = 0.5
# Specify the likelihood distribution while also conditioning on the observed data.
y_obs = pm.Binomial("y_obs", n=n, p=theta, observed=Y)
# Sample from the posterior distribution
idata = pm.sample(1000, return_inferencedata=True)
I expect the above code to estimate the posterior distribution of n. Instead, I get this error:
SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{'n': array(4)}
Initial evaluation results:
n -1.66
y_obs -inf
Name: Log-probability of test_point, dtype: float64
I am feeling a hint that -1.66 customers is impossible (-inf likelihood), but I don’t see why that should even be happening since the prior distribution on n is Pois(4.5).