Reputation: 767
I am trying to create a PYMC Deterministic variable that looks like the following.
@pymc.deterministic
def tau(s = sigma):
return 1.0/(s**2)
However, in my case, the model parameters (PYMC Stochastic variables) are defined as class attributes. As a result, sigma
is accessible only to class methods (through self.sigma
). Trying to make this a class method like the following
@pymc.deterministic
def tau(self, s = None):
sigma = self.sigma
return 1.0/(sigma**2)
throws an error (obviously).
ValueError: Deterministic tau: no parent provided for the following label: self
How can I create a PYMC Deterministic variable whose parent is an attribute of a class?
P.S. Not sure if it matters, but I am using PYMC 2.x
Upvotes: 0
Views: 385
Reputation: 767
Thanks to this mildly related question, I was able to figure out a way to capture class attributes as parents to a PYMC Deterministic variable. The solution is to use PYMC's Lambda class which converts a Python lambda
function into a Deterministic instance. This seems to be a rather clean way.
self.tau = pymc.Lambda('tau', lambda s = self.sigma: 1.0/(s**2))
Upvotes: 1