Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #427 +/- ##
==========================================
- Coverage 92.88% 92.78% -0.11%
==========================================
Files 31 31
Lines 3289 3117 -172
==========================================
- Hits 3055 2892 -163
+ Misses 234 225 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 8aa7aff is merged into master:
Further explanation regarding interpretation and methodology can be found in the documentation. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
loo.matrix()andloo.array()get a new argumentpsis_object. With it,loo()uses the weights of a givenpsis,sisortisobject and does not compute the importance ratios from-x. The result has the same structure and classes as the result ofloo()withoutpsis_object.Motivation
Some downstream code computes LOO for a log-likelihood
xwith importance ratios that are not-x. An example is the new brms functionas_brmsfit()for projpred projections. There,xis the log-likelihood of the projected draws. The importance ratios are-ll_ref, the negative log-likelihood of the reference model draws from which the projected draws come. To get apsis_looobject, the brms branch now calls three loo internals:pointwise_loo_calcs(),importance_sampling_loo_object()andpsis_n_eff(). With this PR, the same object can come from one exported call:The argument name and its meaning are the same as in
E_loo()and inloo_pred_measure()of #363 (for v3.0.0).Behavior
psis_objectmust have the same number of draws and observations asx. For an arrayx, the draw order is that ofpsis()for an array of the same shape (chains stacked).is_methodcomes frompsis_object. An error occurs if the user gives a differentis_method. A wrapper method that forwards the full default vectorc("psis", "tis", "sis")does not cause an error.loo()ignorescores.r_eff: if it isNULLor not given,loo()uses ther_effofpsis_object(1 if the object has none). Otherwiser_effreplaces ther_effofpsis_objectforn_effand the MCSE ofelpd_loo.NAvalues inr_effbecome 1, as inpsis().loo()does not repeat the Pareto smoothing, so the tail length and the Pareto k values stay those ofpsis_object. You can therefore combine a tail length forr_eff = 1with an MCSE that uses ther_effof the chains, as in brmsas_brmsfit().posterior::ps_tail_length()also ignoresr_eff.save_psis = TRUE, the result storespsis_object, with ther_effandn_effthatloo()used. For asisortisobject, the stored element issis_objectortis_object, as before this PR.loo.function()stops with an error if it getspsis_object. Before this PR, the argument went through...to the log-likelihood function.loo()does not repeat the Pareto k warnings ofpsis().Note for downstream packages: loo 2.10.1 accepts
psis_objectthrough...and ignores it without an error or warning. A package that uses the argument must require the first loo version that contains this PR.Tests
New file
tests/testthat/test_loo_psis_object.R(9test_that()blocks, 48 expectations). It checks that:loo(x, psis_object = psis(-x, r_eff = r))is identical toloo(x, r_eff = r, save_psis = TRUE), for the matrix and the array method;elpd_loo,p_looandmcse_elpd_looequal direct computations, alsolog(E_loo(exp(x), psis_object, log_ratios = ...)$value);r_effchangesn_effand the MCSE but notpareto_k, the log weights or the tail length;NULL,NAand scalarr_effwork as documented;sisandtisobjects givesis_looandtis_looobjects;loo_compare()andprint()work;loo.function()).NEWS item (proposal)
loo()matrix and array methods get the argumentpsis_objectto use given importance weights.This PR was assisted by Claude