0

I am trying to write a generic function which accepts a user-defined function, a list of priors(apart from other things) and the does something (irrelevant for this question)

for eg ( ... in the following code-snippets refers to irrelevant information )

generic_func(..., pred, [pymc.Uniform("a", 0, 5), pymc.Unform("b", 0, 1)], ...)

where user_fn is defined as

def pred(...,a, b, ...) : ...

I need to define the generic_func, I do it as follows :

def generic_func(..., user_fn, fittable_prior_list, optional_arguments_for_user_fn):
    h = {}
    for params in fittable_prior_list:
         h[params.name] = params
    user_fn(..., **h, ...)

I don't want to constrain the user to pass arguments in the same order as user_fn expects, that's why I am using a dictionary. I have assumed that the priors in the list will have same name as that of arguments of user_fn (I will be happy to know if this assumption can be done away with, but I am okay even if this assumption holds)

But I get the following error :

AttributeError: 'Uniform' object has no attribute 'name'

I went on these links How can I read a function's signature including default argument values? , also Getting method parameter names in python

Then I tried

tau = pm.Uniform(name = "tau", lower=0, upper=5)
argspec = inspect.getargspec(tau).args

and I get the following error

TypeError: <pymc.distributions.Uniform 'tau' at 0x9a3210c> is not a Python function

Is there a way I can access the name of these pymc objects ?

Though this is not the main question, I will also be happy to know if there is a better way to solve this problem than the one I am using.

Community
  • 1
  • 1
turing
  • 577
  • 1
  • 4
  • 12

1 Answers1

0

The objects in question store their names in the __name__ attribute. They can be accessed like this:

import pymc
obj = pymc.Uniform("a", 0, 5)
print obj.__name__
jcrudy
  • 3,921
  • 1
  • 24
  • 31