Skip to contents

Prepares an object for nested sampling by validating and (re)generating its set of live points. This ensures the sampler is viable before new live points are generated during the nested sampling algorithm.

Usage

# S3 method for class 'ernest_sampler'
compile(object, ..., seed = NA)

# S3 method for class 'ernest_run'
compile(object, ..., seed = NA, clear = FALSE)

Arguments

object

An ernest_sampler or ernest_run object.

  • For ernest_sampler: Prepares a new sampler with a fresh set of live points.

  • For ernest_run: Regenerates live points from previous results, unless clear = TRUE.

...

These dots are for future extensions and must be empty.

seed

An integer, NULL, or NA. Controls the random number generator:

  • Integer or NULL: Passed to set.seed(). If NULL, reinitializes the generator as if no seed has yet been set.

  • NA: Makes no changes to the current seed. If compile() has been called on object before, NA ensures the seed remains identical between runs.

clear

Logical. If TRUE, clears results from previous runs before compiling. If FALSE, retains previous results and validates live points.

Value

A validated object, with a valid set of live points stored in its run_env environment.

Details

compile() validates the set of live points in the sampler or run, ensuring:

  • Each live point is within the unit hypercube.

  • The likelihood function returns valid values (finite double or -Inf) for each point.

  • The set of live points is not a perfect plateau (all points sharing the same likelihood). A warning is issued if more than 25% of points share the same likelihood value.

If validation fails, the set of live points is removed, preventing further sampling until the issue is resolved.

See also

  • ernest_sampler() for creating an ernest_sampler object.

  • generate() for running nested sampling and details on the ernest_run object.

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)

# Compile the sampler to add live points
compile(sampler)
#>  Creating new live points.
#> 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
head(sampler$run_env$unit)
#>           [,1]       [,2]
#> [1,] 0.9947288 0.98949724
#> [2,] 0.9889581 0.09055999
#> [3,] 0.9465411 0.91811271
#> [4,] 0.9413467 0.08311054
#> [5,] 0.0780184 0.92671498
#> [6,] 0.9569834 0.11210960

# Continue a previous run
# run <- data(example_run)
# sampler_2 <- compile(example_run)
# sampler_2

# Make a new sampler from a previous run
sampler_3 <- compile(example_run, clear = TRUE)
#>  Creating new live points.
sampler_3
#> Nested sampling specification <ernest_sampler>
#> No. Points: 500
#> 
#> ── Sampling Method 
#> • Random Walk in Unit Cube LRPS <rwmh_cube/ernest_lrps>
#> • No. Dimensions: 3
#> • No. Calls Since Update: 0
#> • No. Accepted Since Update: 0
#> • Current Step Size: 0.0223