Initializes an ernest_sampler
object containing the components required to
perform nested sampling. This object can then be used to build sequences of
nested samples with generate()
.
Usage
ernest_sampler(
log_lik,
prior,
sampler = rwmh_cube(),
n_points = 500,
first_update = NULL,
update_interval = NULL
)
Arguments
- log_lik
A function which takes a vector of parameters as a vector and returns the log-likelihood of a given model. Wrapped using
create_likelihood()
unless it is already of classernest_likelihood
.- prior
An object with class ernest_prior. Describes the prior space within which to generate sample parameters for
log_lik
.- sampler
An object of class ernest_lrps. Describes the likelihood-restricted prior sampling technique to adopt during the run.
- n_points
A strictly positive integer. The number of live points to use in the nested sampling run.
- first_update
An optional positive integer. The number of likelihood calls to make with the default uniform LRPS method before swapping to the technique described by
sampler
. If leftNULL
, this is set ton_points * 2.5
.- update_interval
An optional positive integer. The number of likelihood calls between updates to the
sampler
object. IfNULL
, this is set ton_points * 1.5
.
Value
An object of class ernest_sampler
, which is a list containing the
inputs used as arguments to this function, along with an environment
run_env
which is used to store the n_points
live particles throughout
a nested sampling run.
Details
The ernest_sampler
object is tested with compile()
before it is
returned. This helps to catch errors with the likelihood and prior
specifications. If this compilation step fails, review your log_lik_fn
and
prior
objects for their compliance.
Verbosity
Messages from ernest can be silenced with the global options
rlib_message_verbosity
and rlib_warning_verbosity
. These options take the
values:
"default": Verbose unless the
.frequency
argument is supplied."verbose": Always verbose.
"quiet": Always quiet.
When set to quiet, message are not displayed and the condition is not
signaled. See rlang::abort()
for more information.
See also
create_likelihood()
describes the requirements of thelog_lik_fn
parameter.create_prior()
describes the requriements of theprior
parameter.ernest_lrps describes the general requirements of likelihood-restricted
prior samplers.
Examples
prior <- create_uniform_prior(n_dim = 2, lower = -1, upper = 1)
#> New names:
#> • `Uniform` -> `Uniform...1`
#> • `Uniform` -> `Uniform...2`
ll_fn <- function(x) -sum(x^2)
sampler <- ernest_sampler(ll_fn, prior, n_points = 100)
sampler
#> Nested sampling specification <ernest_sampler>
#> No. Points: 100
#>
#> ── Sampling Method
#> • Random Walk in Unit Cube LRPS <rwmh_cube/ernest_lrps>
#> • No. Dimensions: 2
#> • No. Calls Since Update: 0
#> • No. Accepted Since Update: 0
#> • Current Step Size: 1
# Use a unit-cube LRPS (not recommended in practice)
unit_sampler <- ernest_sampler(
ll_fn,
prior,
n_points = 100,
sampler = unif_cube()
)
unit_sampler
#> Nested sampling specification <ernest_sampler>
#> No. Points: 100
#>
#> ── Sampling Method
#> • ! An abstract LRPS sampler <ernest_lrps>