Skip to content

prior predictive mvnornal, use cholesky-based random sampling #3766

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

Closed
wants to merge 2 commits into from

Conversation

aloctavodia
Copy link
Member

This should fix #3758

@codecov
Copy link

codecov bot commented Jan 8, 2020

Codecov Report

Merging #3766 into master will increase coverage by 0.01%.
The diff coverage is 64.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3766      +/-   ##
==========================================
+ Coverage   90.63%   90.64%   +0.01%     
==========================================
  Files         133      133              
  Lines       20328    20318      -10     
==========================================
- Hits        18424    18418       -6     
+ Misses       1904     1900       -4
Impacted Files Coverage Δ
pymc3/distributions/multivariate.py 79.19% <64.45%> (+0.26%) ⬆️

Copy link
Member

@lucianopaz lucianopaz left a comment

Choose a reason for hiding this comment

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

It was really hard to find the actual changes in the middle of all the style things that black did. However, from what I saw, this doesn't seem to address the problems when chol is passed to MvNormal. At least a test for both parameterizations should be added.

One other thing is that multivariate distributions are not well implemented for sample_prior_predictive and shape issues will pop out when you start making the distribution parameters' RVs themselves. With this change, you avoid problems when mu is an RV but once we make cov an RV, things will blow up. What's worse is that any exceptions raised there will be silenced and an array full of nans will be returned.

mu, cov = draw_values([self.mu, self.cov], point=point, size=size)
if mu.shape[-1] != cov.shape[-1]:
raise ValueError("Shapes for mu and cov don't match")

try:
dist = stats.multivariate_normal(
mean=mu, cov=cov, allow_singular=True)
dist = stats.multivariate_normal(mean=None, cov=cov, allow_singular=True)
Copy link
Member

Choose a reason for hiding this comment

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

This may fix the nans seen in #3758 but once someone makes cov an RV, the same shape issues will pop up again. The exception will be silenced here and the user will only get back nans (which I think is wrong).

@aloctavodia
Copy link
Member Author

Sorry for not pointing to the actual changes In the example #3758, there is not problem if chol is passed, only when cov is passed. I am aware this is not a fix to all the current problems with MVnormal, just to the one in the opened issue. Regarding the exception you mentioned, that what exactly was it was going on before this change, the error was silenced and the only indication of problems was the nan returned. I agree is not the best scenario, maybe it is better to remove the try-except.

What do you thing we should do, close this PR and work in a more complete solution? accept this in the meantime?

@aloctavodia aloctavodia changed the title prior predictive mvnornal, sample zero-centered distribution and then shift it prior predictive mvnornal, use cholesky-based random sampling Jan 8, 2020
@aloctavodia
Copy link
Member Author

I see now that this will only fix the nan problem in #3758, but there is still a problem with draw_values not getting the proper mu values. And thus c and a are completely uncorrelated resulting in a huge standard deviation instead of a value around 1 as expected.

@aloctavodia aloctavodia deleted the mvnormal branch May 29, 2020 19:16
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.

Issue with prior_predictive_sample and MvNormal
2 participants