Skip to content

Commit fd6c563

Browse files
committed
Merge branch 'master' into pr/1138
2 parents fa4ad10 + f34e00f commit fd6c563

18 files changed

Lines changed: 298 additions & 71 deletions

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto eol=lf
2+
*.rda binary

.github/workflows/R-CMD-check-wsl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181

8282
- name: Upload check results
8383
if: failure()
84-
uses: actions/upload-artifact@v6
84+
uses: actions/upload-artifact@v7
8585
with:
8686
name: wsl-backend-results
8787
path: check

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122

123123
- name: Upload check results
124124
if: failure()
125-
uses: actions/upload-artifact@v6
125+
uses: actions/upload-artifact@v7
126126
with:
127127
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
128128
path: check

.github/workflows/Test-coverage.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ on:
1010

1111
name: Test coverage
1212

13-
permissions: read-all
13+
permissions:
14+
contents: read
15+
id-token: write
1416

1517
jobs:
1618
test-coverage:
@@ -69,8 +71,6 @@ jobs:
6971
print(cov)
7072
covr::to_cobertura(cov)
7173
shell: Rscript {0}
72-
env:
73-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
7474

7575
- name: Test coverage (Windows)
7676
if: runner.os == 'Windows'
@@ -86,8 +86,6 @@ jobs:
8686
print(cov)
8787
covr::to_cobertura(cov)
8888
shell: Rscript {0}
89-
env:
90-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
9189

9290
- uses: codecov/codecov-action@v5
9391
with:
@@ -96,7 +94,7 @@ jobs:
9694
files: ./cobertura.xml
9795
plugins: noop
9896
disable_search: true
99-
token: ${{ secrets.CODECOV_TOKEN }}
97+
use_oidc: true
10098

10199
- name: Show testthat output
102100
if: always()
@@ -107,7 +105,7 @@ jobs:
107105

108106
- name: Upload test results
109107
if: failure()
110-
uses: actions/upload-artifact@v6
108+
uses: actions/upload-artifact@v7
111109
with:
112110
name: coverage-test-failures
113111
path: ${{ runner.temp }}/package

NEWS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Removed deprecated items (replacements in parentheses):
44
- `read_sample_csv()` (`read_cmdstan_csv()`)
55
- `write_stan_tempfile()` (`write_stan_file()`)
6-
- `model_params` element of `fit$metadata()` list (`variables` element)
76
- `jacobian_adjustment` argument to `fit$log_prob()` and similar methods (`jacobian` argument)
87
- `output_samples` argument to `model$variational()` (`draws` argument)
98
- `hessian` argument to `fit$init_model_methods()` (`hessian` method always compiled now)

R/csv.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ read_cmdstan_csv <- function(files,
328328
model_param_dims <- variable_dims(metadata$variables)
329329
metadata$stan_variable_sizes <- model_param_dims
330330
metadata$stan_variables <- names(model_param_dims)
331-
331+
metadata$model_params <- metadata$variables # for backwards compatibility
332332
if (metadata$method == "sample") {
333333
if (is.null(format)) {
334334
format <- "draws_array"

R/fit.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,15 @@ lp_approx <- function() {
768768
#' The `$print()` method returns the fitted model object itself (invisibly),
769769
#' which is the standard behavior for print methods in \R.
770770
#'
771+
#' @references
772+
#' * Vehtari, A., Gelman, A., Simpson, D., Carpenter, B., and Buerkner, P.-C.
773+
#' (2021). Rank-normalization, folding, and localization: An improved R-hat
774+
#' for assessing convergence of MCMC (with discussion).
775+
#' *Bayesian Analysis*, 16(2), 667-718. doi:10.1214/20-BA1221.
776+
#' * Vehtari, A. (2021). Comparison of MCMC effective sample size estimators.
777+
#' https://avehtari.github.io/rhat_ess/ess_comparison.html
778+
#' (for ESS diagnostics such as `ess_bulk` and `ess_tail`).
779+
#'
771780
#' @seealso [`CmdStanMCMC`], [`CmdStanMLE`], [`CmdStanLaplace`], [`CmdStanVB`], [`CmdStanGQ`]
772781
#'
773782
#' @examples
@@ -1524,6 +1533,19 @@ CmdStanMCMC <- R6::R6Class(
15241533
#' @return The object returned by [loo::loo.array()] or
15251534
#' [loo::loo_moment_match.default()].
15261535
#'
1536+
#' @references
1537+
#' * Vehtari, A., Gelman, A., and Gabry, J. (2017). Practical Bayesian model
1538+
#' evaluation using leave-one-out cross-validation and WAIC.
1539+
#' *Statistics and Computing*, 27(5), 1413-1432.
1540+
#' doi:10.1007/s11222-016-9696-4.
1541+
#' * Vehtari, A., Simpson, D., Gelman, A., Yao, Y., and Gabry, J. (2024).
1542+
#' Pareto smoothed importance sampling.
1543+
#' *Journal of Machine Learning Research*, 25(72), 1-58.
1544+
#' * Paananen, T., Piironen, J., Buerkner, P.-C., and Vehtari, A. (2021).
1545+
#' Implicitly adaptive importance sampling.
1546+
#' *Statistics and Computing*, 31, 16. doi:10.1007/s11222-020-09982-2
1547+
#' (for `moment_match = TRUE`).
1548+
#'
15271549
#' @seealso The \pkg{loo} package website with
15281550
#' [documentation](https://mc-stan.org/loo/reference/index.html) and
15291551
#' [vignettes](https://mc-stan.org/loo/articles/).

R/model.R

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,19 @@ CmdStanModel$set("public", name = "format", value = format)
11051105
#'
11061106
#' @return A [`CmdStanMCMC`] object.
11071107
#'
1108-
#' @template seealso-docs
1108+
#' @references
1109+
#' * Hoffman, M. D., and Gelman, A. (2014). The No-U-Turn sampler:
1110+
#' adaptively setting path lengths in Hamiltonian Monte Carlo.
1111+
#' *Journal of Machine Learning Research*, 15(47), 1593-1623.
1112+
#' * Betancourt, M. (2017). A conceptual introduction to Hamiltonian Monte Carlo.
1113+
#' arXiv:1701.02434. Appendix A describes Stan's dynamic HMC/NUTS implementation.
1114+
#' * Stan Development Team. Stan Reference Manual (Algorithms section):
1115+
#' https://mc-stan.org/docs/reference-manual/
1116+
#' * Stan Development Team. Stan documentation:
1117+
#' https://mc-stan.org/users/documentation/
1118+
#' * Stan Development Team. CmdStan User's Guide:
1119+
#' https://mc-stan.org/docs/cmdstan-guide/
1120+
#'
11091121
#' @inherit cmdstan_model examples
11101122
#'
11111123
sample <- function(data = NULL,
@@ -1280,7 +1292,19 @@ CmdStanModel$set("public", name = "sample", value = sample)
12801292
#'
12811293
#' @return A [`CmdStanMCMC`] object.
12821294
#'
1283-
#' @template seealso-docs
1295+
#' @references
1296+
#' * Hoffman, M. D., and Gelman, A. (2014). The No-U-Turn sampler:
1297+
#' adaptively setting path lengths in Hamiltonian Monte Carlo.
1298+
#' *Journal of Machine Learning Research*, 15(47), 1593-1623.
1299+
#' * Betancourt, M. (2017). A conceptual introduction to Hamiltonian Monte Carlo.
1300+
#' arXiv:1701.02434. Appendix A describes Stan's dynamic HMC/NUTS implementation.
1301+
#' * Stan Development Team. Stan Reference Manual (Algorithms section):
1302+
#' https://mc-stan.org/docs/reference-manual/
1303+
#' * Stan Development Team. Stan documentation:
1304+
#' https://mc-stan.org/users/documentation/
1305+
#' * Stan Development Team. CmdStan User's Guide:
1306+
#' https://mc-stan.org/docs/cmdstan-guide/
1307+
#'
12841308
#' @seealso The Stan Math Library's documentation
12851309
#' ([mc-stan.org/math](https://mc-stan.org/math/)) for more
12861310
#' details on MPI support in Stan.
@@ -1440,7 +1464,14 @@ CmdStanModel$set("public", name = "sample_mpi", value = sample_mpi)
14401464
#'
14411465
#' @return A [`CmdStanMLE`] object.
14421466
#'
1443-
#' @template seealso-docs
1467+
#' @references
1468+
#' * Stan Development Team. Stan Reference Manual (Algorithms section, optimization):
1469+
#' https://mc-stan.org/docs/reference-manual/
1470+
#' * Stan Development Team. Stan documentation:
1471+
#' https://mc-stan.org/users/documentation/
1472+
#' * Stan Development Team. CmdStan User's Guide:
1473+
#' https://mc-stan.org/docs/cmdstan-guide/
1474+
#'
14441475
#' @inherit cmdstan_model examples
14451476
#'
14461477
optimize <- function(data = NULL,
@@ -1562,7 +1593,14 @@ CmdStanModel$set("public", name = "optimize", value = optimize)
15621593
#'
15631594
#' @return A [`CmdStanLaplace`] object.
15641595
#'
1565-
#' @template seealso-docs
1596+
#' @references
1597+
#' * Stan Development Team. Stan Reference Manual (Algorithms section, Laplace approximation):
1598+
#' https://mc-stan.org/docs/reference-manual/
1599+
#' * Stan Development Team. Stan documentation:
1600+
#' https://mc-stan.org/users/documentation/
1601+
#' * Stan Development Team. CmdStan User's Guide:
1602+
#' https://mc-stan.org/docs/cmdstan-guide/
1603+
#'
15661604
#' @examples
15671605
#' \dontrun{
15681606
#' file <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.stan")
@@ -1727,7 +1765,17 @@ CmdStanModel$set("public", name = "laplace", value = laplace)
17271765
#'
17281766
#' @return A [`CmdStanVB`] object.
17291767
#'
1730-
#' @template seealso-docs
1768+
#' @references
1769+
#' * Kucukelbir, A., Tran, D., Ranganath, R., Gelman, A., and Blei, D. M.
1770+
#' (2017). Automatic differentiation variational inference.
1771+
#' *Journal of Machine Learning Research*, 18(14), 1-45.
1772+
#' * Stan Development Team. Stan Reference Manual (Algorithms section, variational inference):
1773+
#' https://mc-stan.org/docs/reference-manual/
1774+
#' * Stan Development Team. Stan documentation:
1775+
#' https://mc-stan.org/users/documentation/
1776+
#' * Stan Development Team. CmdStan User's Guide:
1777+
#' https://mc-stan.org/docs/cmdstan-guide/
1778+
#'
17311779
#' @inherit cmdstan_model examples
17321780
#'
17331781
variational <- function(data = NULL,
@@ -1867,7 +1915,17 @@ CmdStanModel$set("public", name = "variational", value = variational)
18671915
#' pathfinder runs in multi-pathfinder.
18681916
#' @return A [`CmdStanPathfinder`] object.
18691917
#'
1870-
#' @template seealso-docs
1918+
#' @references
1919+
#' * Zhang, L., Carpenter, B., Gelman, A., and Vehtari, A. (2022).
1920+
#' Pathfinder: parallel quasi-Newton variational inference.
1921+
#' *Journal of Machine Learning Research*, 23(306), 1-49.
1922+
#' * Stan Development Team. Stan Reference Manual (Algorithms section, Pathfinder):
1923+
#' https://mc-stan.org/docs/reference-manual/
1924+
#' * Stan Development Team. Stan documentation:
1925+
#' https://mc-stan.org/users/documentation/
1926+
#' * Stan Development Team. CmdStan User's Guide:
1927+
#' https://mc-stan.org/docs/cmdstan-guide/
1928+
#'
18711929
#' @inherit cmdstan_model examples
18721930
#'
18731931
pathfinder <- function(data = NULL,

R/utils.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,32 @@ compile_functions <- function(env, verbose = FALSE, global = FALSE) {
950950
prep_fun_cpp(funs[ind], fun_end, env$hpp_code)
951951
})
952952

953+
reserved_names <- unique(
954+
unlist(
955+
lapply(stan_funs, function(stan_fun) {
956+
regmatches(
957+
stan_fun,
958+
gregexpr("(?<=_stan_)[[:alnum:]_]+", stan_fun, perl = TRUE)
959+
)[[1]]
960+
}),
961+
use.names = FALSE
962+
)
963+
)
964+
965+
if (length(reserved_names) > 0) {
966+
stop(
967+
paste0(
968+
"expose_functions() can't expose this Stan function because the function ",
969+
"name and/or one or more argument names use a reserved keyword ",
970+
"(typically in the C++ toolchain used to compile Stan). Please rename ",
971+
"the function/arguments in your Stan functions block and try again. ",
972+
"Conflicting names: ",
973+
paste(reserved_names, collapse = ", ")
974+
),
975+
call. = FALSE
976+
)
977+
}
978+
953979
env$fun_names <- sapply(seq_len(length(funs) - 1), function(ind) {
954980
get_function_name(funs[ind], funs[ind + 1], env$hpp_code)
955981
})

man/fit-method-loo.Rd

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)