Dear all,
I have the following model:
exp_rewards = np.random.rand(300) < 0.75
T = 10
with pm.Model() as model:
k = pm.Normal("k", -2.3, 0.1)
K = pm.Deterministic("K", pt.exp(k))
vi = pm.Normal.dist(mu=-2.7, sigma=K)
ri = pm.Normal.dist(mu=0, sigma=np.exp(vi))
v = pm.GaussianRandomWalk('v', init_dist=vi, mu=0, sigma=K, steps=T-1)
V = pm.Deterministic("V", np.exp(-v))
rw = pm.GaussianRandomWalk('rw', init_dist=ri, mu=0, sigma=V[:-1], steps=T-1, shape=T)
r = pm.Deterministic("r", pt.math.sigmoid(rw))
y = pm.Bernoulli(f"y", r, observed=exp_rewards[:T])
trace = pm.sample(chains=4)
(The goal is actually to reproduce this model, but it would require a “BetaRandomWalk” for rw)
But it is giving me the following error:
ValueError: Random variables detected in the logp graph: {normal_rv{0, (0, 0), floatX, False}.out}.
This can happen when DensityDist logp or Interval transform functions reference nonlocal variables,
or when not all rvs have a corresponding value variable.
By commenting/uncommeting lines, it seems rw declaration is intrudocing the problem, but I don’t understand what the error actually means.
What is problem?
By reading similar threads, such as:
I guess the problem is something like “GaussianRandomWalk of rw requires init_dist (ri) to be an unregistered (unnamed) distribution but this in turn depends on some named variable” (like k, which must be named as it is a variable we want to keep track of in the model) - so in the end there is an unnamed distribution between two named variables and pymc doesn’t like it.
On the other hand, if I comment the line after V, the model runs just fine, so the GaussianRandomWalk of v doesn’t give the same problem…
I am confused…