Custom Deterministic Function

I’m trying to create a third variable based on two prior distributions. Say that I’m trying to apply this function

def f(x1,x2):
    p = np.zeros(3,3)
    for i in range(3):
        for j in range(3):
            p[i,j] += x1+x2-i-j
    return p

where x1,x2 both come from pm.Normal() with shape 5. I should be expecting the returning variable to be 5 3X3 matrices.

Is there a way of doing so? I’m aware of pymc.Deterministic() but it doesn’t seem to take in functions.

The easiest way is to create the constant numpy array of ij= i + j and then simply do x1 + x2 - ij with PyMC variables x1 and x2. You don’t need to use Deterministic or wrap things in a function. You can operate directly on x1 and x2.

Deterministic is used only if you want to save the output of that operation during sampling.

1 Like