Hi all,
I have some code that has continuous priors and a multinomial likelihood which is throwing the error:
TypeError: Elemwise{abs,no_inplace}.grad illegally returned an integer-valued variable. (Input index 0, dtype complex128)
The only thing that i think could be causing this error is the multinomial function but both n,p and ‘data’ which I use for the observed argument are all float64. I came across past posts that indicate this error pops up because theano (so now pytensor?) can’t handle complex gradients and in part of the calculation to determine ‘p’, complex values do come up although the calculation is all in a single deterministic node where the absolute is then taken and thus I would think shouldn’t be an issue!
The relevant (tidied up) code block is:
with pm.Model() as model_multinomial:
#frac = pm.Dirichlet("frac", a=np.ones(M))
# Define priors
eta = pm.Normal("eta", mu=0.5, sigma=0.05,initval=0.5)
#a= pm.Uniform("a", lower=-np.pi, upper=np.pi,initval=0)
a= pm.Normal("a", mu=0, sigma=np.pi/200,initval=0)
b= pm.Normal("b", mu=0.7, sigma=0.07,initval=0.5)
Volt=pm.Deterministic("Volt",pt.as_tensor(V_dist))
phi=pm.Deterministic("phi",(a+b*pm.math.sqr(Volt)))
p=pm.Deterministic("p", pm.math.sqr(pm.math.abs(pm.math.sqrt(eta)*pm.math.exp(1j*phi/2))))
pinv=pm.Deterministic("pinv",1-p)
P=pm.Deterministic("P",pm.math.stack([p,pinv],axis=-1))
#C=pm.Deterministic("C",1000*pm.math.ones_like(N,dtype=np.float64))
#need to make joint multinomial (adding log probs across 'experiments')
likelihood=pm.Multinomial("likelihood",n=C,p=P,shape=(N,M),observed=data)
The full code is:
Neville_MZI.py (5.3 KB)
Any help would be immensely appreciated!