Skip to content

Commit b78d4ee

Browse files
authored
Merge pull request #2 from kylesnap/dev
2 parents 3b57be8 + dcbd1df commit b78d4ee

125 files changed

Lines changed: 13094 additions & 3714 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.Rbuildignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
^_pkgdown\.yml$
88
^docs$
99
^pkgdown$
10+
.lintr
11+
^doc$
12+
^Meta$

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ ernest.Rproj
77
/.vscode
88
inst/doc
99
docs
10+
.lintr
11+
/doc/
12+
/Meta/

DESCRIPTION

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: ernest
2-
Title: The Nested Sampling Toolkit
2+
Title: The R Nested Sampling Toolkit
33
Version: 0.0.0.9000
44
Authors@R:
55
person("Kyle", "Dewsnap", , "kyle.dewsnap@ubc.ca", role = c("aut", "cre"),
@@ -15,25 +15,31 @@ Imports:
1515
ggplot2,
1616
glue,
1717
lifecycle,
18+
matrixStats,
1819
posterior,
19-
prettyunits,
2020
R6,
21-
Rcpp,
2221
rlang (>= 1.1.0),
2322
tibble,
23+
tidyselect,
2424
utils,
2525
vctrs
2626
Suggests:
27+
ggdist,
2728
knitr,
28-
mvtnorm,
29+
LaplacesDemon,
2930
rmarkdown,
3031
testthat (>= 3.0.0),
31-
vdiffr
32+
vdiffr,
33+
xml2
3234
LinkingTo:
33-
Rcpp
35+
cpp11,
36+
testthat
3437
VignetteBuilder:
3538
knitr
3639
Config/testthat/edition: 3
3740
Encoding: UTF-8
3841
Roxygen: list(markdown = TRUE)
3942
RoxygenNote: 7.3.2
43+
Depends:
44+
R (>= 2.10)
45+
LazyData: true

NAMESPACE

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,75 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
S3method("variables<-",ernest_sampler)
4-
S3method(as_draws,ernest_sampler)
5-
S3method(as_draws_list,ernest_sampler)
6-
S3method(as_draws_matrix,ernest_sampler)
7-
S3method(autoplot,ernest_sampler)
8-
S3method(calculate,ernest_sampler)
3+
S3method(as_draws,ernest_run)
4+
S3method(as_draws_matrix,ernest_run)
5+
S3method(as_draws_rvars,ernest_run)
6+
S3method(autoplot,ernest_estimates)
7+
S3method(autoplot,ernest_run)
8+
S3method(calculate,ernest_run)
99
S3method(compile,ernest_sampler)
10-
S3method(format,ernest_lrps)
11-
S3method(format,summary.ernest_sampler)
10+
S3method(create_likelihood,"function")
11+
S3method(create_likelihood,ernest_likelihood)
12+
S3method(format,ernest_likelihood)
13+
S3method(format,ernest_prior)
14+
S3method(format,ernest_run)
15+
S3method(format,summary.ernest_run)
1216
S3method(generate,ernest_sampler)
13-
S3method(make_ptype,character)
14-
S3method(make_ptype,data.frame)
15-
S3method(make_ptype,numeric)
16-
S3method(nested_sampling,"function")
17-
S3method(nested_sampling,default)
18-
S3method(nvariables,ernest_sampler)
19-
S3method(plot,ernest_sampler)
20-
S3method(print,ernest_lrps)
21-
S3method(print,summary.ernest_sampler)
22-
S3method(propose_live,ernest_lrps)
23-
S3method(propose_live,rw_cube)
24-
S3method(propose_uniform,ernest_lrps)
25-
S3method(refresh_lrps,rw_cube)
26-
S3method(refresh_lrps,uniform_cube)
27-
S3method(set_variables,ernest_sampler)
28-
S3method(summary,ernest_sampler)
29-
S3method(update_sampler,ernest_lrps)
30-
S3method(update_sampler,rw_cube)
31-
S3method(variables,ernest_sampler)
17+
S3method(plot,ernest_estimates)
18+
S3method(plot,ernest_run)
19+
S3method(print,ernest_likelihood)
20+
S3method(print,ernest_prior)
21+
S3method(print,ernest_run)
22+
S3method(print,summary.ernest_run)
23+
S3method(summary,ernest_run)
24+
S3method(visualize,ernest_run)
25+
export(as_draws)
26+
export(as_draws_matrix)
27+
export(as_draws_rvars)
3228
export(calculate)
3329
export(compile)
30+
export(create_cauchy_prior)
31+
export(create_likelihood)
32+
export(create_normal_prior)
33+
export(create_prior)
34+
export(create_t_prior)
35+
export(create_uniform_prior)
3436
export(generate)
35-
export(glance)
3637
export(nested_sampling)
3738
export(rwmh_cube)
3839
export(unif_cube)
40+
export(visualize)
3941
import(rlang)
4042
importFrom(R6,R6Class)
41-
importFrom(Rcpp,sourceCpp)
43+
importFrom(cli,cli_progress_bar)
44+
importFrom(cli,cli_progress_done)
45+
importFrom(cli,cli_progress_update)
4246
importFrom(generics,calculate)
4347
importFrom(generics,compile)
4448
importFrom(generics,generate)
45-
importFrom(generics,glance)
49+
importFrom(generics,visualize)
4650
importFrom(ggplot2,aes)
4751
importFrom(ggplot2,autoplot)
4852
importFrom(ggplot2,facet_grid)
49-
importFrom(ggplot2,geom_hline)
53+
importFrom(ggplot2,geom_col)
5054
importFrom(ggplot2,geom_line)
5155
importFrom(ggplot2,geom_ribbon)
52-
importFrom(ggplot2,geom_vline)
5356
importFrom(ggplot2,ggplot)
57+
importFrom(ggplot2,scale_fill_viridis_d)
5458
importFrom(ggplot2,scale_x_continuous)
5559
importFrom(ggplot2,scale_y_continuous)
5660
importFrom(ggplot2,vars)
5761
importFrom(glue,glue)
58-
importFrom(graphics,plot)
5962
importFrom(lifecycle,deprecated)
60-
importFrom(posterior,"variables<-")
6163
importFrom(posterior,as_draws)
62-
importFrom(posterior,as_draws_list)
6364
importFrom(posterior,as_draws_matrix)
64-
importFrom(posterior,nvariables)
65-
importFrom(posterior,set_variables)
66-
importFrom(posterior,variables)
65+
importFrom(posterior,as_draws_rvars)
6766
importFrom(rlang,"%@%")
6867
importFrom(rlang,"%@%<-")
6968
importFrom(rlang,"%|%")
7069
importFrom(rlang,"%||%")
7170
importFrom(tibble,tibble)
7271
importFrom(utils,head)
7372
importFrom(utils,tail)
73+
importFrom(vctrs,vec_c)
74+
importFrom(vctrs,vec_size)
7475
useDynLib(ernest, .registration = TRUE)

R/RcppExports.R

Lines changed: 0 additions & 15 deletions
This file was deleted.

R/as_draws.R

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#' Transform nested sampling runs to `draws` objects
2+
#'
3+
#' Try to transform an [ernest_run-class] to a format supported by the
4+
#' [posterior][posterior::posterior-package] package.
5+
#'
6+
#' @param x An `ernest_run` object.
7+
#' @inheritParams rlang::args_dots_empty
8+
#' @param units Which units to express the sampled points. If `"original"`,
9+
#' points are expressed on the scale of the prior space. If `"unit_cube"`,
10+
#' points are expressed on the scale of the (0-1)-unit hypercube.
11+
#' @param radial Whether to return an additional column `.radial`, containing
12+
#' the radial coordinate (i.e., the squared sum of squares) for each sampled
13+
#' point.
14+
#'
15+
#' @returns
16+
#' A [draws][posterior::as_draws()] object, containing the posterior samples
17+
#' from the nested sampling run. Each samples are also bound to their importance
18+
#' weight (in log. units).
19+
#'
20+
#' The exact type of the returned object depends on the function used:
21+
#' * For `as_draws` and `as_draws_matrix`, a [posterior::draws_matrix()]
22+
#' object, which has classes `c("draws_matrix", "draws", "matrix")`.
23+
#' * For `as_draws_rvars`, a [posterior::draws_rvars()] object, which has
24+
#' classes `c("draws_rvars", "draws", "list")`.
25+
#'
26+
#' @examples
27+
#' # Load example run
28+
#' library(posterior)
29+
#' data(ernest_run_example)
30+
#'
31+
#' # View importance weights
32+
#' dm <- as_draws(ernest_run_example)
33+
#' weights(dm) |> head()
34+
#'
35+
#' # Summarize points after resampling
36+
#' dm |>
37+
#' resample_draws() |>
38+
#' summarize_draws()
39+
#'
40+
#' # View the radial coordinate in the unit-space over the run
41+
#' dm_rad <- as_draws_rvars(ernest_run_example, units = "unit_cube", radial = TRUE)
42+
#' plot(
43+
#' x = ernest_run_example$log_volume,
44+
#' y = draws_of(dm_rad$.radial),
45+
#' xlab = "Log volume",
46+
#' ylab = "Radial coordinate"
47+
#' )
48+
#' @rdname as_draws.ernest
49+
#' @method as_draws ernest_run
50+
#' @export
51+
as_draws.ernest_run <- function(x, ..., units = c("original", "unit_cube"), radial = FALSE) {
52+
as_draws_matrix.ernest_run(x, ..., units = units, radial = radial)
53+
}
54+
55+
#' @rdname as_draws.ernest
56+
#' @method as_draws_matrix ernest_run
57+
#' @export
58+
as_draws_matrix.ernest_run <- function(x, ..., units = c("original", "unit_cube"), radial = FALSE) {
59+
as_draws_matrix_(x, ..., units = units, radial = radial)
60+
}
61+
62+
#' @rdname as_draws.ernest
63+
#' @method as_draws_rvars ernest_run
64+
#' @export
65+
as_draws_rvars.ernest_run <- function(x, ..., units = c("original", "unit_cube"), radial = FALSE) {
66+
posterior::as_draws_rvars(
67+
as_draws_matrix(x, ..., units = units, radial = radial)
68+
)
69+
}
70+
71+
#' Internal function for `as_draws_matrix` conversion
72+
#' @noRd
73+
as_draws_matrix_ <- function(x, ..., units, radial, error_call = caller_env()) {
74+
check_dots_empty(call = error_call)
75+
units <- arg_match0(units, values = c("original", "unit_cube"), error_call)
76+
check_bool(radial, error_call = error_call)
77+
78+
points <- if (units == "original") x$samples else x$samples_unit
79+
if (radial) {
80+
radial_col <- sqrt(rowSums(points^2))
81+
points <- cbind(points, ".radial" = radial_col)
82+
}
83+
weights <- x$log_weight - max(x$log_evidence)
84+
85+
posterior::weight_draws(
86+
posterior::as_draws_matrix(points),
87+
weights,
88+
log = TRUE
89+
)
90+
}

0 commit comments

Comments
 (0)