Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ vignettes/loo2-non-factorized_cache/*
^release-prep\.R$
^_pkgdown\.yml$
^pkgdown$
^touchstone$
25 changes: 25 additions & 0 deletions .github/workflows/touchstone-comment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Continuous Benchmarks (Comment)

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

on:
workflow_run:
workflows: ["Continuous Benchmarks (Receive)"]
types:
- completed

jobs:
upload:
runs-on: ubuntu-latest
permissions:
actions: read
pull-requests: write
statuses: write
if: >
${{ github.event.workflow_run.event == 'pull_request' }}
steps:
- uses: lorenzwalthert/touchstone/actions/comment@main
with:
GITHUB_TOKEN: ${{ github.token }}
43 changes: 43 additions & 0 deletions .github/workflows/touchstone-receive.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Continuous Benchmarks (Receive)

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

on:
pull_request:

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
config: ${{ steps.read_touchstone_config.outputs.config }}
steps:
- name: Checkout repo
uses: actions/checkout@v6
with:
fetch-depth: 0

- id: read_touchstone_config
run: |
echo "config=$(jq -c . ./touchstone/config.json)" >> $GITHUB_OUTPUT

build:
needs: prepare
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- ${{ fromJson(needs.prepare.outputs.config) }}
steps:
- name: Checkout repo
uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: lorenzwalthert/touchstone/actions/receive@main
with:
r-version: ${{ matrix.config.r }}
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ S3method(print,compare.loo)
S3method(print,compare.loo_ss)
S3method(print,importance_sampling)
S3method(print,importance_sampling_loo)
S3method(print,kfold)
S3method(print,loo)
S3method(print,pareto_k_table)
S3method(print,pseudobma_bb_weights)
Expand Down
5 changes: 1 addition & 4 deletions R/loo-package.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#' Efficient LOO-CV and WAIC for Bayesian models
#'
#' @docType package
#' @name loo-package
#'
#' @importFrom stats sd var quantile setNames weights rnorm qnorm
#' @importFrom matrixStats logSumExp colLogSumExps colSums2 colVars colMaxs
#'
Expand Down Expand Up @@ -89,4 +86,4 @@
#' for the generalized Pareto distribution. *Technometrics* **51**,
#' 316-325.
#'
NULL
"_PACKAGE"
22 changes: 22 additions & 0 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ print.importance_sampling <- function(x, digits = 1, plot_k = FALSE, ...) {
invisible(x)
}

#' @export
#' @rdname print.loo
print.kfold <- function(x, digits = 1, plot_k = FALSE, ...) {
print.loo(x, digits = digits, ...)

if ("diagnostics" %in% names(x)) {
cat("------\n")
S <- dim(x)[1]
k_threshold <- ps_khat_threshold(S)
if (length(pareto_k_ids(x, threshold = k_threshold))) {
cat("\n")
}
print(pareto_k_table(x), digits = digits)
cat(.k_help())

if (plot_k) {
graphics::plot(x, ...)
}
}
return(invisible(x))
}

# internal ----------------------------------------------------------------

#' Print dimensions of log-likelihood or log-weights matrix
Expand Down
20 changes: 20 additions & 0 deletions data-raw/wine_loglik.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
library(brms)
library(loo)
options(brms.backend = "cmdstanr")
options(mc.cores = 4)

fitos <- read.delim("data-raw/winequality-red.csv", sep = ";") |>
unique() |>
scale() |>
as.data.frame() |>
brm(
ordered(quality) ~ .,
family = cumulative("logit"),
prior = prior(R2D2(mean_R2 = 1 / 3, prec_R2 = 3)),
data = _,
seed = 1,
silent = 2,
refresh = 0
)

saveRDS(log_lik(fitos), "touchstone/wine.rds")
Loading
Loading