nessai.samplers.base

Base nested sampler object

Module Contents

Classes

BaseNestedSampler

Base nested sampler class.

class nessai.samplers.base.BaseNestedSampler(model: nessai.model.Model, nlive: int, output: str = None, seed: int = None, checkpointing: bool = True, checkpoint_interval: int = 600, checkpoint_on_iteration: bool = False, checkpoint_callback: Callable | None = None, logging_interval: int = None, log_on_iteration: bool = True, resume_file: str = None, plot: bool = True, n_pool: int | None = None, pool: Any | None = None)

Bases: abc.ABC

Base nested sampler class.

Parameters:
modelnessai.model.Model

User-defined model

outputstr, optional

Path for the output. If not specified the current working directory is used.

seedint, optional

Seed used to seed numpy and torch.

checkpointingbool, optional

Boolean to toggle checkpointing, must be enabled to resume the sampler. If false the sampler is still saved at the end of sampling.

checkpoint_intervalint

The interval used for checkpointing. By default this is a time interval in seconds. If checkpoint_on_iteration=True this corresponds to the number of iterations between checkpointing.

checkpoint_on_iterationbool

If true the checkpointing interval is checked against the number of iterations

checkpoint_callbackCallback

Callback function to be used instead of the default function. The function will be called in the code:checkpoint method as: :code`checkpoint_callback(self)`.

logging_intervalint, optional

The interval in seconds used for periodic logging. If not specified, then periodic logging is disabled.

log_on_iterationbool

If true logging will occur based on the iteration. If false logging will be periodic if logging_interval is set. In case where neither logging is enabled, log_on_iteration will be set to true with an interval of nlive.

resume_filestr, optional

Name of the file the sampler will be saved to and resumed from.

plotbool, optional

Boolean to enable or disable plotting.

n_poolint, optional

Number of threads to when for creating the multiprocessing pool.

poolobject

User defined multiprocessing pool that will be used when evaluating the likelihood.

property likelihood_evaluation_time

Current log-likelihood time

property total_likelihood_evaluations

Total number of likelihood evaluations

abstract property posterior_effective_sample_size

The effective sample size of the posterior distribution

likelihood_calls

Alias for total_likelihood_evaluations

configure_output(output: str | None, resume_file: str | None = None)

Configure the output folder

Parameters:
outputstr

Directory where the results will be stored

resume_filestr, optional

Specific file to use for checkpointing. If not specified the default is used (nested_sampler_resume.pkl)

configure_random_seed(seed: int | None)

Initialise the random seed.

Parameters:
seedOptional[int]

The random seed. If not specified, a random seed is generated.

configure_periodic_logging(logging_interval, log_on_iteration)

Configure the periodic logging.

Parameters:
logging_intervalint, optional

The interval in seconds used for periodic logging. If not specified, then periodic logging is disabled.

log_on_iterationbool

If true logging will occur based on the iteration. If false logging will be periodic if logging_interval is set. In case where neither logging is enabled, log_on_iteration will be set to true with an interval of nlive.

periodically_log_state()

Log the state of the sampler.

Calls log_state if the elapsed interval in time (or iterations) is more than the specified interval.

initialise_history() None

Initialise the dictionary to store history

update_history() None

Update the history dictionary

checkpoint(periodic: bool = False, force: bool = False, save_existing: bool = True)

Checkpoint the classes internal state.

Parameters:
periodicbool

Indicates if the checkpoint is regular periodic checkpointing or forced by a signal. If forced by a signal, it will show up on the state plot.

forcebool

Force the sampler to checkpoint.

save_existingbool

If True, the previous checkpoint will be copied to .old. If False, the new checkpoint will override the previous file.

classmethod resume_from_pickled_sampler(sampler: Any, model: nessai.model.Model, checkpoint_callback: Callable | None = None)

Resume from pickle data.

Parameters:
dataAny

Pickle data

modelnessai.model.Model

User-defined model

checkpoint_callbackOptional[Callable]

Checkpoint callback function. If not specified, the default method will be used.

Returns:
Instance of BaseNestedSampler
classmethod resume(filename: str, model: nessai.model.Model, **kwargs)

Resumes the interrupted state from a checkpoint pickle file.

Parameters:
filenamestr

Pickle file to resume from

modelnessai.model.Model

User-defined model

Returns:
obj

Instance of BaseNestedSampler

close_pool(code=None)

Close the multiprocessing pool.

get_result_dictionary()

Return a dictionary that contains results.

Only includes version, seed and sampling time. Child classes should call this method and add to the dictionary.