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

Marginalapprox fix #6076

Merged
merged 6 commits into from
Sep 1, 2022
Merged

Marginalapprox fix #6076

merged 6 commits into from
Sep 1, 2022

Conversation

bwengals
Copy link
Contributor

@bwengals bwengals commented Aug 27, 2022

This PR is meant to fix #5922 and possibly also #6069, but not 100% sure about the last one.

Ended up having to use pm.Potential instead of pm.DenisityDist to get pm.MarginalApprox.marginal_likelihood working properly. Using pm.DensityDist it seems would involve introspecting the lazily evaluated covariance and mean functions for any random variables and their dims.

I also tried to clean up the tests a bit for MarginalApprox, because the reason #5922 took a while to be caught was because find_MAP or other any other methods weren't tested. #6069 does look to just be due to tolerances -- the results still look correct so I increased those a bit.

Hopefully this PR can close #6069 and close #5922.

pymc/gp/gp.py Outdated Show resolved Hide resolved
pymc/gp/gp.py Outdated Show resolved Hide resolved
pymc/tests/test_gp.py Outdated Show resolved Hide resolved
pymc/tests/test_gp.py Show resolved Hide resolved
pymc/tests/test_gp.py Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 27, 2022

Codecov Report

Merging #6076 (426b5c6) into main (a90c420) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6076      +/-   ##
==========================================
+ Coverage   89.52%   89.53%   +0.01%     
==========================================
  Files          72       72              
  Lines       12950    12948       -2     
==========================================
  Hits        11593    11593              
+ Misses       1357     1355       -2     
Impacted Files Coverage Δ
pymc/gp/gp.py 93.19% <100.00%> (+0.46%) ⬆️

@bwengals
Copy link
Contributor Author

thanks @canyon289!

@ricardoV94
Copy link
Member

@bwengals does this address #5024 as well?

Copy link
Member

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

does this address #5024 as well?

Looks like it does 💯

pymc/gp/gp.py Outdated
**kwargs,
)
approx_logp = self._build_marginal_likelihood_logp(y, X, Xu, noise, JITTER_DEFAULT)
pm.Potential(f"marginalapprox_logp_{name}", approx_logp)
Copy link
Member

Choose a reason for hiding this comment

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

This is the f"{name}_loglikelihood", right?

Just trying to find something more instructuve than "logp"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch! yeah thanks it's not even correct because it is the log likelihood and not logp... fixed

self.gp = gp
self.sigma = 0.1
self.x = np.linspace(-5, 5, 30)
self.y = 0.25 * self.x + self.sigma * np.random.randn(len(self.x))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.y = 0.25 * self.x + self.sigma * np.random.randn(len(self.x))
self.y = np.random.normal(0.25 * self.x, self.sigma)

@bwengals
Copy link
Contributor Author

It does address #5024, but I left it off since "ideally" you wouldn't use a potential here. If I could get something like DensityDist working, you would then include a random method so sample_posterior_predictive would do the right thing. You can get around it by adding .conditional over the same X you trained on and get that result, so it's not a huge deal I guess. I'll make sure to show this when I update the example nbs.

@bwengals bwengals marked this pull request as ready for review August 28, 2022 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants