Nested sampler base class¶
- class pints.NestedSampler(log_prior)[source]¶
Abstract base class for nested samplers.
- Parameters:
log_prior (pints.LogPrior) – A logprior to draw proposal samples from.
- in_initial_phase()[source]¶
For methods that need an initial phase (see
needs_initial_phase()
), this method returnsTrue
if the method is currently configured to be in its initial phase. For other methods aNotImplementedError
is returned.
- needs_initial_phase()[source]¶
Returns
True
if this method needs an initial phase, for example ellipsoidal nested sampling has a period of running rejection sampling before it starts to fit ellipsoids to points.
- set_initial_phase(in_initial_phase)[source]¶
For methods that need an initial phase (see
needs_initial_phase()
), this method toggles the initial phase algorithm. For other methods aNotImplementedError
is returned.
- tell(fx)[source]¶
If a single evaluation is provided as arguments, a single point is accepted and returned if its likelihood exceeds the current threshold; otherwise None is returned.
If multiple evaluations are provided as arguments (for example, if running the algorithm in parallel), None is returned if no points have likelihood exceeding threshold; if a single point passes the threshold, it is returned; if multiple points pass, one is selected uniformly at random and returned and the others are stored for later use.
In all cases, two objects are returned: the proposed point (which may be None) and an array of other points that also pass the threshold (which is empty for single evaluation mode but may be non-empty for multiple evaluation mode).
- class pints.NestedController(log_likelihood, log_prior, method=None)[source]¶
Uses nested sampling to sample from a posterior distribution.
- Parameters:
log_likelihood (pints.LogPDF) – A
LogPDF
function that evaluates points in the parameter space.log_prior (pints.LogPrior) – A
LogPrior
function on the same parameter space.
References
- effective_sample_size()[source]¶
Calculates the effective sample size of posterior samples from a nested sampling run using the formula:
\[ESS = exp(-sum_{i=1}^{m} p_i log p_i),\]in other words, the information. Given by eqn. (39) in [1].
- iterations()[source]¶
Returns the total number of iterations that will be performed in the next run.
- log_likelihood_vector()[source]¶
Returns vector of log likelihoods for each of the stacked
[m_active, m_inactive]
points.
- marginal_log_likelihood_standard_deviation()[source]¶
Calculates standard deviation in marginal log likelihood as in [2].
- marginal_log_likelihood_threshold()[source]¶
Returns threshold for determining convergence in estimate of marginal log likelihood which leads to early termination of the algorithm.
- n_posterior_samples()[source]¶
Returns the number of posterior samples that will be returned (see
set_n_posterior_samples()
).
- parallel()[source]¶
Returns the number of parallel worker processes this routine will be run on, or
False
if parallelisation is disabled.
- posterior_samples()[source]¶
Returns posterior samples generated during run of nested sampling object.
- prior_space()[source]¶
Returns a vector of X samples which approximates the proportion of prior space compressed.
- run()[source]¶
Runs the nested sampling routine and returns a tuple of the posterior samples and an estimate of the marginal likelihood.
- sample_from_posterior(posterior_samples)[source]¶
Draws posterior samples based on nested sampling run using importance sampling. This function is automatically called in
NestedController.run()
but can also be called afterwards to obtain new posterior samples.
- set_iterations(iterations)[source]¶
Sets the total number of iterations to be performed in the next run.
- set_log_to_file(filename=None, csv=False)[source]¶
Enables logging to file when a filename is passed in, disables it if
filename
isFalse
orNone
.The argument
csv
can be set toTrue
to write the file in comma separated value (CSV) format. By default, the file contents will be similar to the output on screen.
- set_marginal_log_likelihood_threshold(threshold)[source]¶
Sets threshold for determining convergence in estimate of marginal log likelihood which leads to early termination of the algorithm.
- set_n_posterior_samples(posterior_samples)[source]¶
Sets the number of posterior samples to generate from points proposed by the nested sampling algorithm.
- set_parallel(parallel=False)[source]¶
Enables/disables parallel evaluation.
If
parallel=True
, the method will run using a number of worker processes equal to the detected cpu core count. The number of workers can be set explicitly by settingparallel
to an integer greater than 0. Parallelisation can be disabled by settingparallel
to0
orFalse
.