Export srs_diff_est()#340
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #340 +/- ##
==========================================
+ Coverage 92.78% 92.80% +0.02%
==========================================
Files 31 31
Lines 2992 3004 +12
==========================================
+ Hits 2776 2788 +12
Misses 216 216 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The example should be based on flexible enough model so that After we have useful loglik matrix, the example code would be something like This matches what someone was asking |
Either is fine by me. Also if we're only using it for this example, we could also just generate an example loglik matrix in the example code instead of storing it. |
|
I think the interesting examples can be slow to run. I'll test subsampling with few interesting real models this week |
|
Thus would be a good example with data from https://archive.ics.uci.edu/ml/datasets/wine+quality library(dplyr)
library(brms)
options(brms.backend = "cmdstanr")
options(mc.cores = 4)
library(loo)
wine <- read.delim(root("winequality-red", "winequality-red.csv"), sep = ";") |>
distinct()
wine_scaled <- as.data.frame(scale(wine))
fitos <- brm(ordered(quality) ~ .,
family = cumulative("logit"),
prior = prior(R2D2(mean_R2 = 1/3, prec_R2 = 3)),
data = wine_scaled,
seed = 1,
silent = 2,
refresh = 0)
log_lik_matrix <- log_lik(fitos)
N <- nrow(wine_scaled)
Nsub <- 100
# posterior log-score
lpd <- elpd(log_lik_matrix)
sum(lpd$pointwise[,"elpd"])
# Use PSIS-LOO for subsample of Nsub randomly selected observations
set.seed(1)
idx <- sample(1:N, Nsub)
elpd_loo_sub <- loo(log_lik_matrix[,idx])
sum(elpd_loo_sub$pointwise[,"elpd_loo"]) / Nsub * N
# Use difference estimator to combine fast result and subsampled accurate result
loo:::srs_diff_est(lpd$pointwise[,"elpd"], elpd_loo_sub$pointwise[,"elpd_loo"], idx)
# Comparison to using PSIS-LOO for all observations
loo(log_lik_matrix)
As compiling and sampling the brms model takes some time, I would store only the |
|
Interesting, do I understand it correctly that the |
|
We've been using the https://github.com/stan-dev/loo/blob/master/data-raw/generate-example_loglik_array.R |
|
Instead of generating log_lik on the fly, we could use the stored wine log_lik which was added in #352. This would make the example to run much faster. Need to check whether wine log_lik was added only for touchstone and was it too big for CRAN, @jgabry , @VisruthSK |
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 30cc34e is merged into master:
|
|
The tests are failing so I will give a short summary of what I did. Second, I renamed Third, I added the example by @avehtari to Fourth, I did So I hope that I shouldnt be too far from getting the tests to pass. Do you have an idea why they might fail?
Of course also an option! I just wanted give the |
Yes to both. Clocks in at about 40MB, and is currently only in the touchstone directory. |
|
Hi @vinniott! Thanks for working on this.
I think we should figure out how we're storing/using the wine data before we fix the tests. Apologize if you already know this, but if you click on the failed runs, you'll be able to scroll down till you see R CMD check output. Locally, you can run
I think the problem here might be that you ran some code locally before that to make Hope that slightly clears up why the tests are failing, and how to (hopefully) reproduce those failures locally. |
|
HI @VisruthSK, If it's currently too big for CRAN as is, does this mean that neither touchstone nor sysdata.rda (as suggested above by @jgabry) are possible and that an alternative (data set or data storage method) is needed? |
|
as proposed by @avehtari in issue stan-dev#333
|
Okay. There are now a lot of confusing commits. Here is what I did: As suggested by @avehtari I have now simply added a commented out example. I have two ettiquette questions:
|
6863c50 to
30cc34e
Compare
|
@vinniott Thanks for making that new, clean branch! I just moved this PR to use that branch, sorry for not asking or anything but I hope you don't mind.
Can't speak in general, but personally I didn't want to lose any discussion from this PR. Making a new, clean PR and linking to this one is also okay I guess, but since cleaning this PR up wasn't too hard (with the help of a LLM), I think updating a PR is cleaner.
This is one of the reasons I don't like working on forks :) I think usually you should reabse feature branches to origin master, and keep fork's master clean and up to date with origin. You can do a merge commit too, but rebasing is cleaner IMO. I glanced through this forum post, and it seems good. I would also suggest using the GitHub UI if possible, then the Hope this helps! |
|
Separately, I think the example should be in a dontrun block instead of commented out. |

Fixes #333
Note:
@exampleyet because I did not have time yet to get fully familiar with the whole package.