Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using pm.Data to supply mu parameter to Normal #3842

Closed
rpgoldman opened this issue Mar 19, 2020 · 2 comments · Fixed by #3925
Closed

Error using pm.Data to supply mu parameter to Normal #3842

rpgoldman opened this issue Mar 19, 2020 · 2 comments · Fixed by #3925

Comments

@rpgoldman
Copy link
Contributor

rpgoldman commented Mar 19, 2020

Description of your problem

When I create a pm.Data with a vector of values for the mean of a Normal, I get a type error. When I supply the same vector of values without packaging into pm.Data, this works fine.

Please provide a minimal, self-contained, and reproducible example.

import numpy as np
import pymc3 as pm

# the following gives: TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
with pm.Model():
    x = pm.Data("x", [1.0, 2.0, 3.0])
    y = pm.Normal("y", mu=x, shape=3)

# same type error
with pm.Model():
    x = pm.Data("x", np.array([1.0, 2.0, 3.0]))
    y = pm.Normal("y", mu=x, shape=3)

# works fine
with pm.Model():
    x = np.array([1.0, 2.0, 3.0])
    y = pm.Normal("y", mu=x, shape=3)

Please provide the full traceback.

>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/data_mu_bug.py", line 11, in <module>
  File "/Users/rpg/src/pymc3/pymc3/distributions/distribution.py", line 66, in __new__
    return model.Var(name, dist, data, total_size)
  File "/Users/rpg/src/pymc3/pymc3/model.py", line 998, in Var
    total_size=total_size, model=self)
  File "/Users/rpg/src/pymc3/pymc3/model.py", line 1450, in __init__
    distribution.shape, distribution.dtype) * distribution.default()
  File "/Users/rpg/src/pymc3/pymc3/distributions/distribution.py", line 91, in default
    return np.asarray(self.get_test_val(self.testval, self.defaults), self.dtype)
  File "/Users/rpg/src/pymc3/pymc3/distributions/distribution.py", line 96, in get_test_val
    if hasattr(self, v) and np.all(np.isfinite(self.getattr_value(v))):
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Please provide any additional information below.

Versions and main components

  • PyMC3 Version: master
  • Theano Version: 1.0.4
  • Python Version: 3.6.8
  • Operating system: MacOS
  • How did you install PyMC3: pip, editable
@AlexAndorra
Copy link
Contributor

@rpgoldman, do you have some ideas of how to fix this? Maybe I can include it in the pm.Data integer PR (#3816) that I'm gonna take over.

@AlexAndorra
Copy link
Contributor

AlexAndorra commented May 17, 2020

I think I found a fix 🎉 I'll include it in my upcoming PR that enables pm.Data to be used with integer variables.

@AlexAndorra AlexAndorra linked a pull request May 17, 2020 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants