New to Bayesian modeling, tried to find an answer from previous posts but failed.
Each point of my observed data has two entries: years of work experience, and a boolean about whether they moved to a different state since they got their first job(0 if they did, 1 if they did not). For the people who stayed in the same state, the likelihood function is:
The likelihood function of people who have moved is obviously 1 minus this. My code is:
import pymc3 as pm
import theano.tensor as tt
yr = [20, 34, 8, 15, 38] #years of work experience
ss = [1, 1, 1, 1, 0] #0: didn't move states, 1: moved states
def likelihood(a, b, t, ss):
f1 = -b/(a**2)
f2 = (b*tt.exp(-a*t)*(1+a*t))/(a**2)
return ss*(f1+f2)+(1-ss)*(tt.log(1-tt.exp(f1+f2))) #logp
with pm.Model() as model:
a = pm.Gamma('a', alpha=1, beta=1)
b = pm.Gamma('b', alpha=1, beta=1)
like = pm.DensityDist('like', likelihood, observed={'a':a,'b':b,'t':yr,'ss':ss})
trace = pm.sample()
MissingInputError: Input 0 of the graph (indices start from 0),
used to compute Elemwise{exp,no_inplace}(a_log__),
was not provided and not given a value. Use the Theano flag
exception_verbosity='high', for more information on this error.
Try updating to latest arviz version and use idata_kwargs={"density_dist_obs": False} in pm.sample.
Note: I also recommend using return_inferencedata=True. Otherwise, this same error will be triggered any time you call plotting functions such as plot_trace or stats functions such as summary with this trace object.
All plotting and stats functions do this conversion under the hood before doing the actual calculations or plots and do not allow to use extra arguments in the conversion step. Converting to inferencedata and calling plots and stats functions with an inferencedata object avoids first the conversion overhead and possible errors such as this.