nessai.samplers.base#
Base nested sampler object
Classes#
Base nested sampler class. |
Module Contents#
- class nessai.samplers.base.BaseNestedSampler(model: nessai.model.Model, nlive: int, output: str = None, seed: int = None, rng: numpy.random.Generator | None = 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.ABCBase nested sampler class.
- Parameters:
- model
nessai.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=Truethis 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.
- model
- property likelihood_evaluation_time#
Current log-likelihood time
- property total_likelihood_evaluations#
Total number of likelihood evaluations
- likelihood_calls#
Alias for
total_likelihood_evaluations
- abstract property posterior_effective_sample_size#
The effective sample size of the posterior distribution
- 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)
- update_output(output: str) None#
Update the output directory and resume file.
- Parameters:
- output: str
Path to the output directory
- configure_rng(seed: int | None = None, rng: numpy.random.Generator | None = None)#
Configure the random number generation.
If a seed is not specified, a random seed is generated using the specified random number generator, or the default numpy random number if not specified. In the latter case, the seed is then used to seed the new numpy random number generator.
..versionadded:: 0.14.0
- Parameters:
- seedOptional[int]
The random seed. If not specified, a random seed is generated.
- rng: Optional[np.random.Generator]
Random number generator. If not specified, the default numpy random number generator is used with the specified seed.
- configure_random_seed(seed: int | None = None) None#
Initialise the random seed
- ..deprecated:: 0.14.0
Deprecated in favour of
configure_rng().
- 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_stateif 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, output: str | None = None, checkpoint_callback: Callable | None = None)#
Resume from pickle data.
- Parameters:
- dataAny
Pickle data
- model
nessai.model.Model User-defined model
- outputOptional[str]
New output directory. If not specified, the output directory will be the same as the previous run.
- 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, output: str | None = None, **kwargs)#
Resumes the interrupted state from a checkpoint pickle file.
- Parameters:
- filenamestr
Pickle file to resume from
- model
nessai.model.Model User-defined model
- outputOptional[str]
New output directory. If not specified, the output directory will be the same as the previous run.
- 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.