0

I have looked at the following links but none of them provide the solution I am looking for

https://github.com/pymc-devs/pymc/issues/125

PyMC error : hasattr(): attribute name must be string

I have to write a function which given the priors (and other stuff like data etc) returns a pymc model. eg

 m = pym.Model([fittable_params.values(), rv])
 return m

and the in the calling function, when I do mcmc = pymc.MCMC(model) It gives a long error

  Traceback (most recent call last):
  File "model_constructor.py", line 81, in <module>
  mcmc = pm.MCMC(model)
  File "/usr/local/lib/python2.7/dist-packages/pymc-2.3.2-py2.7-linux-i686.egg/pymc/MCMC.py",    line 81, in __init__
   **kwds)
  File "/usr/local/lib/python2.7/dist-packages/pymc-2.3.2-py2.7-linux-i686.egg/pymc/Model.py", line 195, in __init__
  Model.__init__(self, input, name, verbose)
  File "/usr/local/lib/python2.7/dist-packages/pymc-2.3.2-py2.7-linux-i686.egg/pymc/Model.py", line 98, in __init__
  ObjectContainer.__init__(self, input)
  File "/usr/local/lib/python2.7/dist-packages/pymc-2.3.2-py2.7-linux-i686.egg/pymc/Container.py", line 605, in __init__
conservative_update(self, input_to_file)
  File "/usr/local/lib/python2.7/dist-packages/pymc-2.3.2-py2.7-linux-i686.egg/pymc/Container.py", line 548, in conservative_update
if not hasattr(obj, k):
 TypeError: hasattr(): attribute name must be string

On the other hand , if in the function (which returns a model), if I do

m = pm.MCMC([fittable_params.values(), rv])

it is running fine, but the function should return a model so that the user can do whatever he wants with the model in other parts of code.

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

1 Answers1

1

If the linked solutions don't work for you then as a last resort you can just delete the non-string attributes from the model, since they don't seem to be used anyway.

for key in m.__dict__.keys():
    if not isinstance(key, basestring):
        del m.__dict__[key]
Tom Minka
  • 794
  • 6
  • 10