**NotImplementedError** : Cannot convert RV to a tensor variable inside pm.deterministic()

[reposted from frequently asked as I am not sure if that was the right place to ask]

Hi, i’m following the Statistical Rethinking textbook with the PYMC code examples here.

I followed the example and used aesara’s shared to manipulate a predictor variable but was met with the following error during pm.Model() on the pm.Deterministic line 7:

----> 7 mu = pm.Deterministic(‘mu’, a + ba * age_shared + bm * marriage_shared)
NotImplementedError : Cannot convert ba to a tensor variable.

Code:

marriage_shared = shared(data["Marriage_std"].values)
age_shared = shared(data["MedianAgeMarriage_std"].values)

with pm.Model() as m5_3a:
      # A -> D <- M
      sigma = pm.Exponential('sigma', 1)
      a = pm.Normal('a', 0, 0.2)
      ba = pm.Normal('ba', 0, 0.5)
      bm = pm.Normal('bm', 0, 0.5)
      mu = pm.Deterministic('mu', a + ba * age_shared + bm * marriage_shared)
      divorce = pm.Normal('divorce', mu, sigma, observed= d['divorce_std'])
     # A -> M
      sigma_m = pm.Exponential('sigma_m', 1)
      am = pm.Normal('am', 0, 0.2)
      bam = pm.Normal('bam', 0 , 0.5)
      mu_m = pm.Deterministic('mu_m', am + bam * age_shared)
      marriage = pm.Normal('marriage', mu_m, sigma_m, observed= d['marriage_std'])
  
      trace5_3a = pm.sample()

Versions:
pymc = 5.0.1
aesara = 2.8.10

Any idea what went wrong?

PyMC 5 requires PyTensor, not Aesara. You should therefore use pytensor.shared instead of aesara.shared

1 Like

Hey newbie here. Perhaps make this step more explicit in a place where newbies can definitely get to. Was browsing through your docs about using shared variables, ended up looking at v3 docs calling theano.shared; then got to some random place (not on your official websites) and ended up looking at people calling aesara.shared. Now finally…

Yeah that’s definitely suboptimal. Our official docs are versioned now so you can always check the version on the bottom right. The official notebook examples have a footer that indicates what version it was ran on.

Google is sometimes too slow to update search results and discourse issues can also become stale :confused: