bilby.core.sampler.zeus.Zeus

class bilby.core.sampler.zeus.Zeus(likelihood, priors, outdir='outdir', label='label', use_ratio=False, plot=False, skip_import_verification=False, pos0=None, nburn=None, burn_in_fraction=0.25, resume=True, burn_in_act=3, **kwargs)[source]

Bases: Emcee

bilby wrapper for Zeus (https://zeus-mcmc.readthedocs.io/)

All positional and keyword arguments (i.e., the args and kwargs) passed to run_sampler will be propagated to zeus.EnsembleSampler, see documentation for that class for further help. Under Other Parameters, we list commonly used kwargs and the bilby defaults.

Parameters:
nwalkers: int, (500)

The number of walkers

nsteps: int, (100)

The number of steps

nburn: int (None)

If given, the fixed number of steps to discard as burn-in. These will be discarded from the total number of steps set by nsteps and therefore the value must be greater than nsteps. Else, nburn is estimated from the autocorrelation time

burn_in_fraction: float, (0.25)

The fraction of steps to discard as burn-in in the event that the autocorrelation time cannot be calculated

burn_in_act: float

The number of autocorrelation times to discard as burn-in

__init__(likelihood, priors, outdir='outdir', label='label', use_ratio=False, plot=False, skip_import_verification=False, pos0=None, nburn=None, burn_in_fraction=0.25, resume=True, burn_in_act=3, **kwargs)[source]
__call__(*args, **kwargs)

Call self as a function.

Methods

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

calc_likelihood_count()

calculate_autocorrelation(samples[, c])

Uses the emcee.autocorr module to estimate the autocorrelation

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_random_draw_from_prior()

Get a random draw from the prior distribution

log_likelihood(theta)

log_prior(theta)

print_nburn_logging_info()

Prints logging info as to how nburn was calculated

prior_transform(theta)

Prior transform method that is passed into the external sampler.

run_sampler(*args, **kwargs)

A template method to run in subclasses

write_chains_to_file(sample)

write_current_state()

Writes a pickle file of the sampler to disk using dill

write_current_state_and_exit([signum, frame])

Make sure that if a pool of jobs is running only the parent tries to checkpoint and exit.

Attributes

abbreviation

check_point_equiv_kwargs

checkpoint_info

Defines various things related to checkpointing and storing data

constraint_parameter_keys

list: List of parameters providing prior constraints

default_kwargs

external_sampler_name

fixed_parameter_keys

list: List of parameter keys that are not being sampled

hard_exit

kwargs

dict: Container for the kwargs.

nburn

nburn_equiv_kwargs

ndim

int: Number of dimensions of the search parameter space

npool

npool_equiv_kwargs

nsteps

nwalkers

nwalkers_equiv_kwargs

sampler

Returns the emcee sampler object

sampler_chain

sampler_function_kwargs

sampler_init_kwargs

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

stored_chain

Read the stored zero-temperature chain data in from disk

stored_loglike

Returns the log-likelihood stored on disk

stored_logprior

Returns the log-prior stored on disk

stored_samples

Returns the samples stored on disk

calculate_autocorrelation(samples, c=3)[source]

Uses the emcee.autocorr module to estimate the autocorrelation

Parameters:
samples: array_like

A chain of samples.

c: float

The minimum number of autocorrelation times needed to trust the estimate (default: 3). See emcee.autocorr.integrated_time.

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 checkpoint_info

Defines various things related to checkpointing and storing data

Returns:
checkpoint_info: named_tuple

An object with attributes sampler_file, chain_file, and chain_template. The first two give paths to where the sampler and chain data is stored, the last a formatted-str-template with which to write the chain data to disk

property constraint_parameter_keys

list: List of parameters providing prior constraints

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. Both can be empty. Defaults to a single directory: "{outdir}/{name}_{label}/", where name is abbreviation if it is defined for the sampler class, otherwise it defaults to sampler_name.

Parameters:
outdirstr

The output directory.

labelstr

The label for the run.

Returns:
list

List of file names.

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_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]
Parameters:
theta: list

List of values for the likelihood parameters

Returns:
float: Log-likelihood or log-likelihood-ratio given the current

likelihood.parameter values

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

print_nburn_logging_info()[source]

Prints logging info as to how nburn was calculated

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
run_sampler(*args, **kwargs)[source]

A template method to run in subclasses

property sampler

Returns the emcee sampler object

If, already initialized, returns the stored _sampler value. Otherwise, first checks if there is a pickle file from which to load. If there is not, then initialize the sampler and set the initial random draw

sampling_seed_key = None

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

property stored_chain

Read the stored zero-temperature chain data in from disk

property stored_loglike

Returns the log-likelihood stored on disk

property stored_logprior

Returns the log-prior stored on disk

property stored_samples

Returns the samples stored on disk

write_current_state()[source]

Writes a pickle file of the sampler to disk using dill

Overwrites the stored sampler chain with one that is truncated to only the completed steps

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

Make sure that if a pool of jobs is running only the parent tries to checkpoint and exit. Only the parent has a ‘pool’ attribute.

For samplers that must hard exit (typically due to non-Python process) use os._exit that cannot be excepted. Other samplers exiting can be caught as a SystemExit.