cogwheel.sampling.Sampler¶
- class cogwheel.sampling.Sampler(posterior, run_kwargs=None, sample_prior=False, dir_permissions=493, file_permissions=420)¶
Bases:
ABC,JSONMixinGeneric base class for sampling distributions.
Subclasses implement the interface with specific sampling codes.
Parameter space folding is used; this means that the some (“folded”) dimensions are sampled over half their original range, and a map to the other half of the range is defined by reflecting or shifting about the midpoint. The folded posterior distribution is defined as the sum of the original posterior over all
2**n_foldsmapped points. This is intended to reduce the number of modes in the posterior.- Parameters:
- posteriorcogwheel.posterior.Posterior
Implements the prior and likelihood.
- run_kwargsdict
Keyword arguments for the sampler or its run method. Allowed keys depend on the particular sampler used.
- sample_priorFalse
Deprecated, will raise ValueError if it is not False.
- dir_permissions, file_permissionsoctal
Directory and file permissions.
Methods
Return whether the run completed successfully.
Keyword arguments to instantiate the class.
Name of the module that defines the instance's class.
Return a pathlib.Path object with a new run directory, following a standardized naming scheme for output directories.
Define for sampling classes which compute evidence.
Return a pandas.DataFrame with the posterior samples.
Return a new instance of the class, possibly updating init_kwargs.
Make a directory to save results and run sampler.
Return list of possible parameters to configure sampler, along with their default values.
Submit a parameter estimation run using the HTCondor scheduler.
Write class instance to json file.
Attributes
DEFAULT_RUN_KWARGSJSON_FILENAMEPROFILING_FILENAMELike
.posterior.prior.sampled_paramsbut the folded parameters have 'folded_' prepended.subclass_registry- static completed(rundir) bool¶
Return whether the run completed successfully.
- get_init_dict(**kwargs)¶
Keyword arguments to instantiate the class.
- get_module_name()¶
Name of the module that defines the instance’s class.
- get_rundir(parentdir)¶
Return a pathlib.Path object with a new run directory, following a standardized naming scheme for output directories. Directory will be of the form {parentdir}/{prior_name}/{eventname}/{RUNDIR_PREFIX}{run_id}
- Parameters:
- parentdiros.PathLike
Path to a directory where to store parameter estimation data.
- load_evidence() dict¶
Define for sampling classes which compute evidence.
Return a dict with the following items:
‘log_ev’ = log evidence from sampling
‘log_ev_std’ = log standard deviation of evidence
If using nested importance sampling (NIS), should also have:
‘log_ev_NIS’ = log evidence from nested importance sampling
‘log_ev_std_NIS’ = log standard deviation of NIS evidence
- load_samples()¶
Return a pandas.DataFrame with the posterior samples.
- reinstantiate(**new_init_kwargs)¶
Return a new instance of the class, possibly updating init_kwargs.
Values not passed will be taken from the current instance.
- run(rundir)¶
Make a directory to save results and run sampler.
- Parameters:
- rundiros.PathLike
Directory where to save output, will create if needed.
- run_kwargs_options()¶
Return list of possible parameters to configure sampler, along with their default values.
Refer to each sampler’s documentation for details. Sampler parameters not listed here are handled automatically by
cogwheel.- Returns:
- list of inspect.Parameter
- property sampled_params¶
Like
.posterior.prior.sampled_paramsbut the folded parameters have ‘folded_’ prepended.- Returns:
- list of str
- submit_condor(rundir, request_cpus=1, request_memory='8G', request_disk='1G', resuming=False, postprocess=True, **submit_kwargs)¶
Submit a parameter estimation run using the HTCondor scheduler.
This method generates ‘submit.sub’ and ‘executable.sh’ files, the user should provide any instructions for the submit file as **submit_kwargs.
- Parameters:
- rundirstr, os.PathLike
Run directory, e.g. from self.get_rundir
- request_cpus, request_memory, request_diskint or str
Specifications in the HTCondor submit file.
- resumingbool
Whether to attempt resuming a previous run if rundir already exists.
- postprocessbool
Whether to perform convergence tests to the run after sampling. See
postprocessing.postprocess_rundir.- **submit_kwargs
Further options to include in the HTCondor submit file. Do not pass executable, output, error, log, queue, which will be dealt with automatically.
- submit_lsf(rundir, n_hours_limit=48, memory_per_task='32GB', resuming=False, bsub_cmds=(), postprocess=True)¶
- Parameters:
- rundirstr, os.PathLike
Run directory, e.g. from self.get_rundir
- n_hours_limitint
Number of hours to allocate for the job.
- memory_per_taskstr
Determines the memory and number of cpus.
- resumingbool
Whether to attempt resuming a previous run if rundir already exists.
- bsub_cmdstuple of str
Strings with BSUB commands.
- postprocessbool
Whether to perform convergence tests to the run after sampling. See
postprocessing.postprocess_rundir.
- submit_slurm(rundir, n_hours_limit=48, memory_per_task='32G', resuming=False, sbatch_cmds=(), postprocess=True)¶
- Parameters:
- rundirstr, os.PathLike
Run directory, e.g. from self.get_rundir
- n_hours_limitint
Number of hours to allocate for the job.
- memory_per_taskstr
Determines the memory and number of cpus.
- resumingbool
Whether to attempt resuming a previous run if rundir already exists.
- sbatch_cmdstuple of str
Strings with SBATCH commands.
- postprocessbool
Whether to perform convergence tests to the run after sampling. See
postprocessing.postprocess_rundir.
- to_json(dirname, basename=None, *, dir_permissions=493, file_permissions=420, overwrite=False)¶
Write class instance to json file.
It can then be loaded with read_json.