-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Theano error when only 1 value is masked #3122
Comments
Thanks. Oh the good old shape problem... |
I think I've found a fix to this (although it may be a bit of a hack) that works for me. In if isinstance(var.tag.test_value, np.ndarray):
if len(var.tag.test_value) == 1:
shared.type = theano.tensor.TensorType(var.dtype, (True,)) the problem is solved. I don't know if this could introduce any other issue, but I think it should be ok. @junpenglao should I make a PR with this change? |
- this patch fixes an issue highlighted in pymc-devs#3122 where imputation of a single missing observation fails. It implements the suggestion from the theano error message to manual force a TensorType change in cases where the variable has a length of one.
- this patch fixes an issue highlighted in pymc-devs#3122 where imputation of a single missing observation fails. It implements the suggestion from the theano error message to manual force a TensorType change in cases where the variable has a length of one.
@mattpitkin Sure, PRs are welcome. It does seem like a hack but maybe OK to get around a corner case. |
@mattpitkin, I think that what you propose is a bit dangerous because it applies a 1d |
@lucianopaz I'd done some playing around with setting things in |
I think I've figured out the cause of the problem. When the
whereas for a 1d array containing more than one value this sets the distributions TensorType to:
This is fine... until in the
So, the variable's distribution and its test value have incompatible Therefore, I don't think that this can be fixed in from .distributions import TensorType # have this at the start of the class
if hasattr(var.tag.test_value, 'shape'):
testtype = TensorType(var.dtype, var.tag.test_value.shape)
# fix the type
if testtype != shared.type:
shared.type = testtype @lucianopaz @twiecki what are your thoughts on this option? I can test this and update my PR #3335. |
A different option would be to make a change in
But, this means that single values will be set as a vector, which I assume pymc3's own |
- test the error described in pymc-devs#3122 and fixed in pymc-devs#3335.
* model.py: fix issue with length 1 shared variables - this patch fixes an issue highlighted in #3122 where imputation of a single missing observation fails. It implements the suggestion from the theano error message to manual force a TensorType change in cases where the variable has a length of one. * model.py: add a comment about the previous change * model.py: extra check to deal with test errors * model.py: changes to the length 1 fix * test_model.py: check shared tensor type conversion in ValueGradFunction - test the error described in #3122 and fixed in #3335. * RELEASE-NOTES.md: added mention of fix to #3122 * Update RELEASE-NOTES.md fix typo Co-Authored-By: mattpitkin <m@ttpitk.in>
Close by #3335 |
This issues follows the discussion on discourse. I encountered an error when I have a numpy masked array with only 1 observation missing. In this case, Theano raises the error:
Instead, if I have 2 obervations missing, everything works fine. I have attached a Jupyter notebook to recreate the problem (link). In the notebook change the variable
NUM_MISSING_DATAPOINTS
to 1 or 2 to investigate the issue.PyMC3 version 3.5
Theano version 1.0.2
The text was updated successfully, but these errors were encountered: