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

Update Loo, implement improved algorithm #2730

Merged
merged 7 commits into from
Nov 24, 2017

Conversation

aloctavodia
Copy link
Member

@aloctavodia aloctavodia commented Nov 23, 2017

closes #2697

I adapted the code from https://github.com/avehtari/PSIS, the following list summarizes the changes with respect to that code:

  • I replaced sumlogs with scipy.special.logsumexp
  • I could have changed _gpinv with scipy.stats.genpareto.ppf but the former seems to be 5x faster, so I kept it.
  • Reduce the number of intermediate variables
  • Try to be more Pythonic

Regarding the changes from the user point of view:

  • I am keeping only one warning (k > 0.7), as suggested in the original paper https://arxiv.org/abs/1507.02646
  • Warnings seems to be much less frequent now!
  • I am seeing a 20x-50x speed-up factor compared to previous version
  • New optional argument (reff)

Copy link
Member

@junpenglao junpenglao left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -248,6 +247,9 @@ def loo(trace, model=None, pointwise=False, progressbar=False):
pointwise: bool
if True the pointwise predictive accuracy will be returned.
Default False
reff : float
Copy link
Member

Choose a reason for hiding this comment

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

Could this be computed within the function if not provided?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, we can compute it by default.

pymc3/stats.py Outdated
reff = 1.
else:
eff = pm.effective_n(trace)
eff_ave = sum(eff[v] for v in eff) / len(eff)
Copy link
Member

Choose a reason for hiding this comment

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

This wont work with multivariate RVs. I suggest
pm.stats.dict2pd(eff,'eff').mean()

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@junpenglao junpenglao merged commit a222c86 into pymc-devs:master Nov 24, 2017
@junpenglao
Copy link
Member

Thanks @aloctavodia!

@aloctavodia aloctavodia deleted the new_loo branch November 24, 2017 19:18
jordan-melendez pushed a commit to jordan-melendez/pymc3 that referenced this pull request Feb 6, 2018
* update loo

* small fixes

* remove print

* remove unused import

* add to release-notes

* automatic reff calculation

* fix eff_ave
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.

Update loo function
2 participants