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.

active_points()[source]

Returns the active points from nested sampling run.

ask()[source]

Proposes new point at which to evaluate log-likelihood.

in_initial_phase()[source]

For methods that need an initial phase (see needs_initial_phase()), this method returns True if the method is currently configured to be in its initial phase. For other methods a NotImplementedError is returned.

min_index()[source]

Returns index of sample with lowest log-likelihood.

n_active_points()[source]

Returns the number of active points that will be used in next run.

n_hyper_parameters()[source]

See TunableMethod.n_hyper_parameters().

name()[source]

Name of sampler

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.

needs_sensitivities()[source]

Determines whether sampler uses sensitivities of the solution.

running_log_likelihood()[source]

Returns current value of the threshold log-likelihood value.

set_hyper_parameters(x)[source]

See TunableMethod.set_hyper_parameters().

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 a NotImplementedError is returned.

set_n_active_points(active_points)[source]

Sets the number of active points for the next run.

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:

References

active_points()[source]

Returns the active points from nested sampling.

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].

inactive_points()[source]

Returns the inactive points from nested sampling.

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()[source]

Calculates the marginal log likelihood of nested sampling run.

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 is False or None.

The argument csv can be set to True to write the file in comma separated value (CSV) format. By default, the file contents will be similar to the output on screen.

set_log_to_screen(enabled)[source]

Enables or disables logging to 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 setting parallel to an integer greater than 0. Parallelisation can be disabled by setting parallel to 0 or False.

time()[source]

Returns the time needed for the last run, in seconds, or None if the controller hasn’t run yet.