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

Register internal S3 methods #239

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ Suggests:
VignetteBuilder: knitr
Encoding: UTF-8
SystemRequirements: pandoc (>= 1.12.3), pandoc-citeproc
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
Roxygen: list(markdown = TRUE)
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ S3method("[",loo)
S3method("[[",loo)
S3method(E_loo,default)
S3method(E_loo,matrix)
S3method(E_loo_khat,default)
S3method(E_loo_khat,matrix)
S3method(ap_psis,array)
S3method(ap_psis,default)
S3method(ap_psis,matrix)
S3method(as.psis_loo,psis_loo)
S3method(as.psis_loo,psis_loo_ss)
S3method(as.psis_loo_ss,psis_loo)
S3method(as.psis_loo_ss,psis_loo_ss)
S3method(crps,matrix)
S3method(crps,numeric)
S3method(dim,importance_sampling)
Expand Down Expand Up @@ -50,6 +56,7 @@ S3method(print,psis_loo)
S3method(print,psis_loo_ap)
S3method(print,stacking_weights)
S3method(print,waic)
S3method(print_dims,elpd_generic)
S3method(print_dims,importance_sampling)
S3method(print_dims,importance_sampling_loo)
S3method(print_dims,kfold)
Expand All @@ -59,6 +66,8 @@ S3method(print_dims,waic)
S3method(psis,array)
S3method(psis,default)
S3method(psis,matrix)
S3method(psis_n_eff,default)
S3method(psis_n_eff,matrix)
S3method(relative_eff,"function")
S3method(relative_eff,array)
S3method(relative_eff,default)
Expand Down
4 changes: 2 additions & 2 deletions R/E_loo.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ E_loo.matrix <-
E_loo_khat <- function(x, psis_object, log_ratios, ...) {
UseMethod("E_loo_khat")
}

#' @export
E_loo_khat.default <- function(x, psis_object, log_ratios, ...) {
.E_loo_khat_i(x, log_ratios, attr(psis_object, "tail_len"))
}

#' @export
E_loo_khat.matrix <- function(x, psis_object, log_ratios, ...) {
tail_lengths <- attr(psis_object, "tail_len")
sapply(seq_len(ncol(x)), function(i) {
Expand Down
4 changes: 4 additions & 0 deletions R/effective_sample_sizes.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ relative_eff.importance_sampling <- function(x, ...) {
psis_n_eff <- function(w, ...) {
UseMethod("psis_n_eff")
}

#' @export
psis_n_eff.default <- function(w, r_eff = NULL, ...) {
ss <- sum(w^2)
if (is.null(r_eff)) {
Expand All @@ -179,6 +181,8 @@ psis_n_eff.default <- function(w, r_eff = NULL, ...) {
stopifnot(length(r_eff) == 1)
1 / ss * r_eff
}

#' @export
psis_n_eff.matrix <- function(w, r_eff = NULL, ...) {
ss <- colSums(w^2)
if (is.null(r_eff)) {
Expand Down
2 changes: 1 addition & 1 deletion R/elpd.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ elpd_object <- function(pointwise, dims) {
class = c("elpd_generic", "loo")
)
}

#' @export
print_dims.elpd_generic <- function(x, ...) {
cat(
"Computed from",
Expand Down
7 changes: 4 additions & 3 deletions R/loo_subsample.R
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,11 @@ psis_loo_ss_object <- function(x,
as.psis_loo_ss <- function(x) {
UseMethod("as.psis_loo_ss")
}

#' @export
as.psis_loo_ss.psis_loo_ss <- function(x) {
x
}

#' @export
as.psis_loo_ss.psis_loo <- function(x) {
class(x) <- c("psis_loo_ss", class(x))
x$estimates <- cbind(x$estimates, matrix(0, nrow = nrow(x$estimates)))
Expand All @@ -913,10 +913,11 @@ as.psis_loo <- function(x) {
UseMethod("as.psis_loo")
}

#' @export
as.psis_loo.psis_loo <- function(x) {
x
}

#' @export
as.psis_loo.psis_loo_ss <- function(x) {
if (x$loo_subsampling$data_dim[1] == nrow(x$pointwise)) {
x$estimates <- x$estimates[, 1:2]
Expand Down
37 changes: 35 additions & 2 deletions man/loo-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/loo_approximate_posterior.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions man/loo_compare.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions man/loo_subsample.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/update.psis_loo_ss.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.