bilby.core.sampler.nessai.Nessai

class bilby.core.sampler.nessai.Nessai(likelihood, priors, outdir='outdir', label='label', use_ratio=False, plot=False, skip_import_verification=False, injection_parameters=None, meta_data=None, result_class=None, likelihood_benchmark=False, soft_init=False, exit_code=130, npool=1, **kwargs)[source]

Bases: NestedSampler

bilby wrapper of nessai (https://github.com/mj-will/nessai)

All positional and keyword arguments passed to run_sampler are propagated to nessai.flowsampler.FlowSampler

See the documentation for an explanation of the different kwargs.

Documentation: https://nessai.readthedocs.io/

__init__(likelihood, priors, outdir='outdir', label='label', use_ratio=False, plot=False, skip_import_verification=False, injection_parameters=None, meta_data=None, result_class=None, likelihood_benchmark=False, soft_init=False, exit_code=130, npool=1, **kwargs)[source]
__call__(*args, **kwargs)

Call self as a function.

Methods

__init__(likelihood, priors[, outdir, ...])

calc_likelihood_count()

check_draw(theta[, warning])

Checks if the draw will generate an infinite prior or likelihood

get_expected_outputs([outdir, label])

Get lists of the expected outputs directories and files.

get_initial_points_from_prior([npoints])

Method to draw a set of live points from the prior

get_nessai_model()

Get the model for nessai.

get_nested_samples()

Get the nested samples dataframe

get_posterior_weights()

Get the posterior weights for the nested samples

get_random_draw_from_prior()

Get a random draw from the prior distribution

log_likelihood(theta)

Since some nested samplers don't call the log_prior method, evaluate the prior constraint here.

log_prior(theta)

prior_transform(theta)

Prior transform method that is passed into the external sampler.

reorder_loglikelihoods(...)

Reorders the stored log-likelihood after they have been reweighted

run_sampler(*args, **kwargs)

A template method to run in subclasses

split_kwargs()

Split kwargs into configuration and run time kwargs

update_result()

Update the result object.

write_current_state()

Write the current state of the sampler

write_current_state_and_exit([signum, frame])

Overwrites the base class to make sure that Nessai terminates properly.

Attributes

abbreviation

check_point_equiv_kwargs

constraint_parameter_keys

list: List of parameters providing prior constraints

default_kwargs

Default kwargs for nessai.

external_sampler_name

fixed_parameter_keys

list: List of parameter keys that are not being sampled

hard_exit

kwargs

dict: Container for the kwargs.

ndim

int: Number of dimensions of the search parameter space

npoints_equiv_kwargs

npool

npool_equiv_kwargs

run_kwargs_list

List of kwargs used in the run method of FlowSampler

sampler_name

sampling_seed_equiv_kwargs

sampling_seed_key

Name of keyword argument for setting the sampling for the specific sampler.

search_parameter_keys

list: List of parameter keys that are being sampled

walks_equiv_kwargs

check_draw(theta, warning=True)[source]

Checks if the draw will generate an infinite prior or likelihood

Also catches the output of numpy.nan_to_num.

Parameters:
theta: array_like

Parameter values at which to evaluate likelihood

warning: bool

Whether or not to print a warning

Returns:
bool, cube (nlive,

True if the likelihood and prior are finite, false otherwise

property constraint_parameter_keys

list: List of parameters providing prior constraints

property default_kwargs

Default kwargs for nessai.

Retrieves default values from nessai directly and then includes any bilby specific defaults. This avoids the need to update bilby when the defaults change or new kwargs are added to nessai.

Includes the following kwargs that are specific to bilby:

  • nessai_log_level: allows setting the logging level in nessai

  • nessai_logging_stream: allows setting the logging stream

  • nessai_plot: allows toggling the plotting in FlowSampler.run

property fixed_parameter_keys

list: List of parameter keys that are not being sampled

classmethod get_expected_outputs(outdir=None, label=None)[source]

Get lists of the expected outputs directories and files.

These are used by bilby_pipe when transferring files via HTCondor.

Parameters:
outdirstr

The output directory.

labelstr

The label for the run.

Returns:
list

List of file names. This will be empty for nessai.

list

List of directory names.

get_initial_points_from_prior(npoints=1)[source]

Method to draw a set of live points from the prior

This iterates over draws from the prior until all the samples have a finite prior and likelihood (relevant for constrained priors).

Parameters:
npoints: int

The number of values to return

Returns:
unit_cube, parameters, likelihood: tuple of array_like

unit_cube (nlive, ndim) is an array of the prior samples from the unit cube, parameters (nlive, ndim) is the unit_cube array transformed to the target space, while likelihood (nlive) are the likelihood evaluations.

get_nessai_model()[source]

Get the model for nessai.

get_nested_samples()[source]

Get the nested samples dataframe

get_posterior_weights()[source]

Get the posterior weights for the nested samples

get_random_draw_from_prior()[source]

Get a random draw from the prior distribution

Returns:
draw: array_like

An ndim-length array of values drawn from the prior. Parameters with delta-function (or fixed) priors are not returned

property kwargs

dict: Container for the kwargs. Has more sophisticated logic in subclasses

log_likelihood(theta)[source]

Since some nested samplers don’t call the log_prior method, evaluate the prior constraint here.

Parameters:
theta: array_like

Parameter values at which to evaluate likelihood

Returns:
float: log_likelihood
log_prior(theta)[source]
Parameters:
theta: list

List of sampled values on a unit interval

Returns:
float: Joint ln prior probability of theta
property ndim

int: Number of dimensions of the search parameter space

prior_transform(theta)[source]

Prior transform method that is passed into the external sampler.

Parameters:
theta: list

List of sampled values on a unit interval

Returns:
list: Properly rescaled sampled values
static reorder_loglikelihoods(unsorted_loglikelihoods, unsorted_samples, sorted_samples)[source]

Reorders the stored log-likelihood after they have been reweighted

This creates a sorting index by matching the reweights result.samples against the raw samples, then uses this index to sort the loglikelihoods

Parameters:
sorted_samples, unsorted_samples: array-like

Sorted and unsorted values of the samples. These should be of the same shape and contain the same sample values, but in different orders

unsorted_loglikelihoods: array-like

The loglikelihoods corresponding to the unsorted_samples

Returns:
sorted_loglikelihoods: array-like

The loglikelihoods reordered to match that of the sorted_samples

property run_kwargs_list

List of kwargs used in the run method of FlowSampler

run_sampler(*args, **kwargs)[source]

A template method to run in subclasses

sampling_seed_key = 'seed'

Name of keyword argument for setting the sampling for the specific sampler. If a specific sampler does not have a sampling seed option, then it should be left as None.

property search_parameter_keys

list: List of parameter keys that are being sampled

split_kwargs()[source]

Split kwargs into configuration and run time kwargs

update_result()[source]

Update the result object.

write_current_state()[source]

Write the current state of the sampler

write_current_state_and_exit(signum=None, frame=None)[source]

Overwrites the base class to make sure that Nessai terminates properly.