Hi all,
I’ve got some code running where I am hoping to improve the sampling by doing a custom sampling method but have run into a bit of a wall with it.
The relevant block of code is:
with pm.Model() as model_multinomial1:
#M=2
# Define priors
#sd=0.05
eta_sep=pm.TruncatedNormal("eta_sep",mu=0,sigma=1,lower=0.0,upper=1.0,shape=2) #array of
eta=pm.Deterministic("eta",[0.5,0.5]+eta_sep*0.05)
theta=pm.Deterministic("theta",2*pt.arccos(pt.sqrt(eta)))
#priors for conciseness
#sd=a_dev
a_sep=pm.TruncatedNormal("a_sep", mu=0, sigma=1,lower=-np.pi,upper=np.pi, shape=2) #array of priors for conciseness
a=pm.Deterministic("a",[0,0]+a_sep*a_dev)
sd=0.7
b_sep=pm.Normal("b_sep", mu=0, sigma=1,shape=2) #array of priors for conciseness
b=pm.Deterministic("b",[0.7,0.7]+b_sep*sd)
#Have decided to open the Volt variable to allow additional freedom
Volt=pm.Normal("Volt",mu=V_2_dist,sigma=0.1)
#Volt=pm.Deterministic("Volt",pt.as_tensor(V_2_dist))
phi=pm.Deterministic("phi",a[:,None]+b[:,None]*pm.math.sqr(Volt))
#phi1 vanishes from p expression under simplification
p1=pm.Deterministic("p1",-pm.math.sin(theta[0])*pm.math.sin(theta[1])*pm.math.cos(phi[0])/2 + pm.math.cos(theta[0])*pm.math.cos(theta[1])/2 + 1/2)
p2=pm.Deterministic("p2",-pm.math.cos(theta[0] - theta[1])/4 - pm.math.cos(theta[0] + theta[1])/4 - pm.math.cos(-phi[0] + theta[0] + theta[1])/8 + pm.math.cos(phi[0] - theta[0] + theta[1])/8 + pm.math.cos(phi[0] + theta[0] - theta[1])/8 - pm.math.cos(phi[0] + theta[0] + theta[1])/8 + 1/2)
P=pm.Deterministic("P",pm.math.stack([p1,p2],axis=-1))
likelihood=pm.Multinomial("likelihood",n=1000,p=P[0],shape=(N,2),observed=data_2)
print(model_multinomial1.free_RVs)
with model_multinomial1:
#stepmethod=[pm.NUTS([a_sep]),pm.NUTS([a_sep,b_sep]),pm.NUTS([a_sep,b_sep,eta_sep])]
trace_multinomial_2_HMC = pm.sample(draws=int(1e3), chains=4, cores=cpucount,step=pm.Metropolis(vars=["a_sep"]), return_inferencedata=True)
But when I try to run this in my clean anaconda environment, the printing free random variables line gives me what I expect but then throws the following error:
If I don’t give any arguments (so no vars=…) in the custom step method then it runs fine but then that defeats the purpose of me trying to do some custom sampling! Could this be a genuine bug or am I misusing the step method argument of pm.sample()?