Sample

Use these functions to run sampling/integration processes.

xpsi.Sample.run_multinest(likelihood, prior, check_kwargs={}, **kwargs)[source]

Initialise MultiNest and integrate.

Parameters:
  • likelihood (dict) – Keyword arguments required for instantiation of Likelihood.

  • prior (dict) – Keyword arguments required for instantiation of Prior.

  • check_kwargs (dict) – Keywords for likelihood function checker. Passed to checker before commencement of sampling.

  • kwargs – Keyword arguments for PyMultiNest.

xpsi.Sample.run_emcee(likelihood, prior, MPI=True, **kwargs)[source]

Initialise emcee and sample.

Parameters:
  • likelihood – An instance of Likelihood.

  • prior – An instance of Prior.

  • MPI (bool) – Parallelise with MPI? If calling script not lauched with an MPI directive, sampling will not commence because there is only one process. Default is True since only in testing is it justifiable to use a single process.

  • kwargs –

    Passed to initialisers of appropriate classes:

    • boolean to resume, under keyword resume;

    • number of steps, under keyword nsteps;

    • number of walkers, under keyword nwalkers;

    • moments of initial walker multivariate Gaussian distribution, under keyword walker_dist_moments (can be None);

    • root directory for output, under keyword root_dir.

The above objects are used to instantiate Posterior.

Returns:

An instance of emcee.backends.HDFBackend.

xpsi.Sample.run_ptemcee(likelihood, prior, MPI=True, **kwargs)[source]

Initialise ptemcee and sample.

Parallel-tempered ensemble MCMC. The cold chain (\(\beta=1\)) provides the posterior samples, written in the same format as the other X-PSI samplers so the output is read directly by xpsi.PostProcessing (with use_nestcheck=False); the full temperature ladder additionally yields a thermodynamic-integration estimate of the evidence.

Parameters:
  • likelihood – An instance of Likelihood.

  • prior – An instance of Prior.

  • MPI (bool) – Parallelise with MPI? If calling script not lauched with an MPI directive, sampling will not commence because there is only one process. Default is True since only in testing is it justifiable to use a single process.

  • kwargs –

    Passed to initialisers of appropriate classes:

    • boolean to resume, under keyword resume;

    • number of steps, under keyword nsteps;

    • number of walkers per temperature, under keyword nwalkers;

    • number of temperatures, under keyword ntemps (can be None to let ptemcee choose);

    • maximum temperature, under keyword Tmax (can be None);

    • explicit inverse-temperature ladder, under keyword betas (can be None);

    • adapt the temperature ladder, under keyword adapt;

    • moments of initial walker multivariate Gaussian distribution, under keyword walker_dist_moments (can be None);

    • walker initialisation mode ('prior', 'gaussian' or 'samples'), under keyword init_mode (None to choose from the other arguments);

    • posterior samples (path or array, e.g. a MultiNest .txt output) to initialise from, under keyword init_samples;

    • scatter around those samples in units of the posterior standard deviation, under keyword init_scatter;

    • save the initial walker positions, under keyword save_init;

    • root directory for output, under keyword root_dir;

    • output file-root basename, under keyword root;

    • checkpoint interval in iterations, under keyword checkpoint;

    • burn-in and thinning of the written cold chain, under keywords burn_in and thin.

The above objects are used to instantiate Posterior.

Returns:

An instance of PTEmceeSampler.

xpsi.Sample.run_ultranest(likelihood, prior, sampler_params={}, runtime_params={}, use_stepsampler=False, stepsampler_params={}, out_filename='weighted_post_ultranest_xpsi')[source]
Wrapper for the UltraNest (https://johannesbuchner.github.io/UltraNest/)

package (Buchner 2021).

Parameters:
  • likelihood – An instance of Likelihood.

  • prior – An instance of Prior.

  • sampler_params – A dictionary of the keyword arguments passed to the instance of UltranestSampler to initialise the sampler.

  • runtime_params – A dictionary of the keyword arguments passed to the instance of UltranestSampler to run the sampler.

  • use_stepsampler – Boolean indicating if the step sampler is used. In this case the ultranest.stepsampler.SliceSampler is used.

  • stepsampler_params – A dictionary of the keyword arguments passed to the to the instance of UltranestSampler specifying the step sampler runtime parameters.

  • out_filename – String specifying the name of the output file.

Returns:

An instance of UltranestSampler