Skip to content

Commit 498d0de

Browse files
authored
Merge pull request #355 from stan-dev/master
Update posterior pareto smooth tail branch
2 parents b16435a + a7337f8 commit 498d0de

30 files changed

Lines changed: 2241 additions & 103 deletions

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ vignettes/loo2-non-factorized_cache/*
2424
^release-prep\.R$
2525
^_pkgdown\.yml$
2626
^pkgdown$
27+
^touchstone$
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Continuous Benchmarks (Comment)
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.head_ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_run:
9+
workflows: ["Continuous Benchmarks (Receive)"]
10+
types:
11+
- completed
12+
13+
jobs:
14+
upload:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
actions: read
18+
pull-requests: write
19+
statuses: write
20+
if: >
21+
${{ github.event.workflow_run.event == 'pull_request' }}
22+
steps:
23+
- uses: lorenzwalthert/touchstone/actions/comment@main
24+
with:
25+
GITHUB_TOKEN: ${{ github.token }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Continuous Benchmarks (Receive)
2+
3+
permissions:
4+
contents: read
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.head_ref }}
8+
cancel-in-progress: true
9+
10+
on:
11+
pull_request:
12+
13+
jobs:
14+
prepare:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
config: ${{ steps.read_touchstone_config.outputs.config }}
18+
steps:
19+
- name: Checkout repo
20+
uses: actions/checkout@v6
21+
with:
22+
fetch-depth: 0
23+
24+
- id: read_touchstone_config
25+
run: |
26+
echo "config=$(jq -c . ./touchstone/config.json)" >> $GITHUB_OUTPUT
27+
28+
build:
29+
needs: prepare
30+
runs-on: ${{ matrix.config.os }}
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
config:
35+
- ${{ fromJson(needs.prepare.outputs.config) }}
36+
steps:
37+
- name: Checkout repo
38+
uses: actions/checkout@v6
39+
with:
40+
fetch-depth: 0
41+
- uses: lorenzwalthert/touchstone/actions/receive@main
42+
with:
43+
r-version: ${{ matrix.config.r }}

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ S3method(print,compare.loo)
5656
S3method(print,compare.loo_ss)
5757
S3method(print,importance_sampling)
5858
S3method(print,importance_sampling_loo)
59+
S3method(print,kfold)
5960
S3method(print,loo)
6061
S3method(print,pareto_k_table)
6162
S3method(print,pseudobma_bb_weights)

R/loo-package.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#' Efficient LOO-CV and WAIC for Bayesian models
22
#'
3-
#' @docType package
4-
#' @name loo-package
5-
#'
63
#' @importFrom stats sd var quantile setNames weights rnorm qnorm
74
#' @importFrom matrixStats logSumExp colLogSumExps colSums2 colVars colMaxs
85
#'
@@ -89,4 +86,4 @@
8986
#' for the generalized Pareto distribution. *Technometrics* **51**,
9087
#' 316-325.
9188
#'
92-
NULL
89+
"_PACKAGE"

R/print.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ print.importance_sampling <- function(x, digits = 1, plot_k = FALSE, ...) {
105105
invisible(x)
106106
}
107107

108+
#' @export
109+
#' @rdname print.loo
110+
print.kfold <- function(x, digits = 1, plot_k = FALSE, ...) {
111+
print.loo(x, digits = digits, ...)
112+
113+
if ("diagnostics" %in% names(x)) {
114+
cat("------\n")
115+
S <- dim(x)[1]
116+
k_threshold <- ps_khat_threshold(S)
117+
if (length(pareto_k_ids(x, threshold = k_threshold))) {
118+
cat("\n")
119+
}
120+
print(pareto_k_table(x), digits = digits)
121+
cat(.k_help())
122+
123+
if (plot_k) {
124+
graphics::plot(x, ...)
125+
}
126+
}
127+
return(invisible(x))
128+
}
129+
108130
# internal ----------------------------------------------------------------
109131

110132
#' Print dimensions of log-likelihood or log-weights matrix

data-raw/wine_loglik.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
library(brms)
2+
library(loo)
3+
options(brms.backend = "cmdstanr")
4+
options(mc.cores = 4)
5+
6+
fitos <- read.delim("data-raw/winequality-red.csv", sep = ";") |>
7+
unique() |>
8+
scale() |>
9+
as.data.frame() |>
10+
brm(
11+
ordered(quality) ~ .,
12+
family = cumulative("logit"),
13+
prior = prior(R2D2(mean_R2 = 1 / 3, prec_R2 = 3)),
14+
data = _,
15+
seed = 1,
16+
silent = 2,
17+
refresh = 0
18+
)
19+
20+
saveRDS(log_lik(fitos), "touchstone/wine.rds")

0 commit comments

Comments
 (0)