Thanks for the response.
Following your suggestion to dynamically assign zeros I have this attempt:
with pm.Model() as model:
k = 5
arr = []
for j in range(k):
arr.append(pm.Uniform('a'+str(j),lower=0,upper=0.99))
w = pm.Dirichlet('w', a=tt.stack([arr[i] for i in range(k)]), shape=k)
du = pm.DiscreteUniform('du',lower=0, upper=1,shape=k)
mu = pm.Normal('mu', 0., 10., shape=k)
tau = pm.Gamma('tau', 1., 1., shape=k)
x_obs = pm.NormalMixture('x_obs', w, np.multiply(mu,du), tau=np.multiply(tau,du), observed=x)
Basically what I’m doing is to multiply by 0
or 1
the elements of w
, mu
, and tau
. the 0
's and 1
's are those of the DiscreteUniform
It’s not working. The error is (only showing last fragment):
...........................................................................
/usr/local/lib/python2.7/dist-packages/pymc3/step_methods/hmc/base_hmc.py in astep(self=<pymc3.step_methods.hmc.nuts.NUTS object>, q0=array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0.]))
144 self.iter_count,
145 None,
146 None,
147 )
148 self._warnings.append(warning)
--> 149 raise SamplingError("Bad initial energy")
150
151 adapt_step = self.tune and self.adapt_step_size
152 step_size = self.step_adapt.current(adapt_step)
153 self.step_size = step_size
SamplingError: Bad initial energy
I think the DiscreteUniform
in particular lower=0
is generating the error.
If I change the bounds to something bigger than 0
it doesn’t throw the error but after sampling all du
's are 1
, defeating the purpose.
How can I implement the idea correctly?
Thanks