R.V. is forgotten after the def

Dear all,

I am a bit confused, but I am probably wrong. If I run the following code:

def getΔ(m):
    with m:
        Δ = pm.Laplace('Δ', 0, 10, shape = [4, 5])
        tt.printing.Print('Δ')(Δ.shape)
    return True

model = pm.Model()
with model:
    getΔ(model)
    tt.printing.Print('Δ')(Δ.shape)
    pm.sample(100)

I get the output:

Δ __str__ = [4 5]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-10-e0419021930f> in <module>
      8 with model:
      9     getΔ(model)
---> 10     tt.printing.Print('Δ')(Δ.shape)
     11     pm.sample(100)

NameError: name 'Δ' is not defined

Was it correct to assume that Δ should still be present even if I don’t return it with the def?

It is added to the model, so it would show up in the trace. You still have to explicitly return the reference using the normal python rules to access them within the model.

2 Likes