I could be doing something stupid, or I could just not be understanding the math correctly between the two … but my understanding is that if you give the Categorical distribution two probabilities (p(x=0) = 1-p_success, p(x=1) = p_success), that should be exactly the same thing as the Bernoulli distribution. So why aren’t traces from two otherwise identical models (and same random_seed) not giving equal results??
obvs_ind5 = [1,1,1,1,1,1,1,0,0,0] # p_true_ind5 = 0.7
ind = 5
with pm.Model() as model1:
z = pm.Normal('z',mu=0,sd=1,shape=(10,))
p1 = pm.math.invlogit(z)
for i in range(len(obvs_ind5)):
pm.Bernoulli('y_%d'%(i),p=p1[ind],observed=obvs_ind5[i])
trace = pm.sample(progressbar=False,random_seed=123)
Z1 = trace['z']
with pm.Model() as model2:
z = pm.Normal('z',mu=0,sd=1,shape=(10,))
p2 = pm.math.invlogit(z)
for i in range(len(obvs_ind5)):
pm.Bernoulli('y_%d'%(i),p=p2[ind],observed=obvs_ind5[i]) # TRUE
# pm.Categorical('y_%d'%(i),p=[1-p2[ind],p2[ind]], observed=obvs_ind5[i]) # FALSE
# pm.Categorical('y_%d'%(i),p=[1-p2[ind],p2[ind]], observed=1-obvs_ind5[i]) # FALSE
# pm.Categorical('y_%d'%(i),p=[p2[ind],1-p2[ind]], observed=obvs_ind5[i]) # FALSE
# pm.Categorical('y_%d'%(i),p=[p2[ind],1-p2[ind]], observed=1-obvs_ind5[i]) # FALSE
trace = pm.sample(progressbar=False,random_seed=123)
Z2 = trace['z']
print((Z1 == Z2).all())
I tried all combinations I could think of for the parameters and observation, but it never works. Obviously setting both to Bernoulli gives the True result. Any help?