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.
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, unlessclear = TRUE.
- ...
These dots are for future extensions and must be empty.
- seed
seedis no longer supported; set RNG with theseedargument ofernest_sampler().- clear
Logical. If
TRUE, clears results from previous runs before compiling. IfFALSE, retains previous results and validates live points.
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 anernest_samplerobject.generate()for running nested sampling and details on theernest_runobject.
Examples
prior <- create_uniform_prior(lower = c(-1, -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)
#> ℹ Created 100 live points.
#> nested sampling specification <ernest_sampler>
#> • No. Points: 100
#> • LRPS Method: rwmh_cube
#>
#> ernest LRPS method <rwmh_cube/ernest_lrps>
#> • Dimensions: 2
#> • No. Log-Lik Calls: 0
#> • No. Accepted Proposals: 0
#> • No. Steps: 25
#> • Target Acceptance: 0.5
#> • Step Size: 1.000
head(sampler$run_env$unit)
#> [,1] [,2]
#> [1,] 0.037165101 0.03127357
#> [2,] 0.005290188 0.08897904
#> [3,] 0.948443339 0.08655595
#> [4,] 0.034720153 0.87254556
#> [5,] 0.089464300 0.07427147
#> [6,] 0.115157053 0.94388988
# 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)
#> ℹ Created 1000 live points.
sampler_3
#> nested sampling specification <ernest_sampler>
#> • No. Points: 1000
#> • LRPS Method: rwmh_cube
#>
#> ernest LRPS method <rwmh_cube/ernest_lrps>
#> • Dimensions: 3
#> • No. Log-Lik Calls: 0
#> • No. Accepted Proposals: 0
#> • No. Steps: 25
#> • Target Acceptance: 0.5
#> • Step Size: 1.000