Skip to content

Commit

Permalink
Merge pull request #789 from jsocolar/master
Browse files Browse the repository at this point in the history
replace \ with function
  • Loading branch information
rok-cesnovar authored Jul 20, 2023
2 parents dbf41cd + 2a002e5 commit e8713b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- {os: ubuntu-20.04, r: 'devel', rtools: ''}
- {os: ubuntu-20.04, r: 'release', rtools: ''}
- {os: ubuntu-20.04, r: 'oldrel', rtools: ''}
- {os: ubuntu-20.04, r: '3.6', rtools: ''}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
12 changes: 6 additions & 6 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,10 @@ unconstrain_draws <- function(files = NULL, draws = NULL) {
generated_quantities = FALSE)
par_columns <- !(names(draws) %in% c(".chain", ".iteration", ".draw"))
unconstrained <- lapply(split(draws, f = draws$.chain), function(chain) {
apply(chain, 1, function(draw) {
lapply(asplit(chain, 1), function(draw) {
par_list <- utils::relist(as.numeric(draw[par_columns]), skeleton)
self$unconstrain_variables(variables = par_list)
}, simplify = FALSE)
})
})
}
CmdStanFit$set("public", name = "unconstrain_draws", value = unconstrain_draws)
Expand Down Expand Up @@ -1447,16 +1447,16 @@ loo <- function(variables = "log_lik", r_eff = TRUE, moment_match = FALSE, ...)
}

log_lik_i_upars <- function(x, upars, i, parameter_name = "log_lik", ...) {
apply(upars, 1, \(up_i) { x$constrain_variables(up_i)[[parameter_name]][i] })
apply(upars, 1, function(up_i) { x$constrain_variables(up_i)[[parameter_name]][i] })
}

loo::loo_moment_match.default(
x = self,
loo = loo_result,
post_draws = \(x, ...) { x$draws(format = "draws_matrix") },
post_draws = function(x, ...) { x$draws(format = "draws_matrix") },
log_lik_i = log_lik_i,
unconstrain_pars = \(x, pars, ...) { do.call(rbind, lapply(x$unconstrain_draws(), \(chain) { do.call(rbind, chain) })) },
log_prob_upars = \(x, upars, ...) { apply(upars, 1, x$log_prob) },
unconstrain_pars = function(x, pars, ...) { do.call(rbind, lapply(x$unconstrain_draws(), function(chain) { do.call(rbind, chain) })) },
log_prob_upars = function(x, upars, ...) { apply(upars, 1, x$log_prob) },
log_lik_i_upars = log_lik_i_upars,
...
)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/posterior.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fit$summary(
"median",
my_sd,
~quantile(.x, probs = c(0.1, 0.9)),
Minimum = \(x) min(x)
Minimum = function(x) min(x)
)
```

Expand Down

0 comments on commit e8713b4

Please sign in to comment.