Skip to content

Multivariate floating point precision fix#2470

Merged
ColCarroll merged 14 commits intopymc-devs:masterfrom
ericmjl:multivariate_fix
Aug 3, 2017
Merged

Multivariate floating point precision fix#2470
ColCarroll merged 14 commits intopymc-devs:masterfrom
ericmjl:multivariate_fix

Conversation

@ericmjl
Copy link
Member

@ericmjl ericmjl commented Aug 2, 2017

This is a bug fix for distributions.multivariate's Multinomial errors related to floating point precision. This will very likely be helpful for computation runs that involve the GPU, and involve many classes with small floating point numbers.

More information can be found here: #2469

@ericmjl
Copy link
Member Author

ericmjl commented Aug 2, 2017

Just saw a test fail, I think I know what's going on. Let me fix that.

@ericmjl
Copy link
Member Author

ericmjl commented Aug 2, 2017

Okay, locally tests seem like they're passing.

$  py.test pymc3/tests/test_distributions_random.py
============================ test session starts ============================
platform linux -- Python 3.6.0, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /home/ericmjl/github/software/pymc3, inifile: setup.cfg
collected 214 items

pymc3/tests/test_distributions_random.py ....................................
.............................................................................
.............................................................................
.....................xss

============ 211 passed, 2 skipped, 1 xfailed in 253.00 seconds =============

$ py.test pymc3/tests/test_distributions.py
============================ test session starts ============================
platform linux -- Python 3.6.0, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /home/ericmjl/github/software/pymc3, inifile: setup.cfg
collected 95 items

pymc3/tests/test_distributions.py ....................................x...x..
...xxx...x.....................................x....

=================== 88 passed, 7 xfailed in 55.32 seconds ===================

I'm feeling a bit more confident now that the tests on Travis should pass.

@ericmjl
Copy link
Member Author

ericmjl commented Aug 2, 2017

@ColCarroll @junpenglao all tests pass!!!!!!

Copy link
Member

@ColCarroll ColCarroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to merge now -- had a few small comments if you have a second. excited to try this out and see if it fixes my problems!

self.mode = tt.cast(tround(self.mean), 'int32')

def _random(self, n, p, size=None):
# Set float type to float64 for numpy.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment with a link to the numpy issue -- that'll make it clearer why this cast exists, and if/when we can remove it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, @ColCarroll!

raise ValueError('Outcome probabilities must be 1- or 2-dimensional '
'(supplied `p` has {} dimensions)'.format(p.ndim))

return randnum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the return value get cast back to the original data type? honest question -- maybe @kyleabeauchamp has an opinion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea. But X is discrete while p is continuous, so presumably if it worked previously so it should continue working with the current patch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good idea. I will implement that fix.

size = None

if p.ndim == 1:
p = p / (p.sum())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit -- extra parens around p.sum(...), both here and below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, going to push up.

@ericmjl
Copy link
Member Author

ericmjl commented Aug 2, 2017

@ColCarroll I ran the two relevant tests locally and found that they pass. I'm confident it'll pass on Travis, but as usual, let's wait it out.

@ericmjl
Copy link
Member Author

ericmjl commented Aug 2, 2017

@ColCarroll @junpenglao @kyleabeauchamp I think one of the tests timed out, is that correct? Otherwise, everything else has passed.

@ColCarroll
Copy link
Member

Yeah, one is a flaky test, one looks like coveralls threw a 5xx error. I restarted both.

@ColCarroll ColCarroll merged commit 259613f into pymc-devs:master Aug 3, 2017
@ColCarroll
Copy link
Member

Thanks for fixing this!

@ericmjl
Copy link
Member Author

ericmjl commented Aug 3, 2017

Yay!!!! Thanks @ColCarroll!

@ericmjl ericmjl deleted the multivariate_fix branch August 3, 2017 02:07
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 this pull request may close these issues.

3 participants