Sampler#

class gammapy.modeling.Sampler(backend='ultranest', sampler_opts=None, run_opts=None)[source]#

Bases: object

Sampler class.

The sampler class provides a uniform interface to multiple sampler backends. Currently available: “UltraNest”.

Parameters:
backend{“ultranest”}

Global backend used for sampler. Default is “ultranest”. UltraNest: Most options can be found in the UltraNest doc.

sampler_optsdict, optional

Sampler options passed to the sampler. Noteworthy options:

live_pointsint

Minimum number of live points used in the sampling. Increase this number to get more accurate results. For more samples in the posterior increase this number or the min_ess parameter. Default is 400 live points.

frac_remainfloat

Integrate until this fraction of the integral is left in the remainder. Set to a low number (1e-2 … 1e-5) to make sure peaks are discovered. Set to a higher number (0.5) if you know the posterior is simple. Default is 0.5.

min_essint

Target number of effective posterior samples. Increase this number to get more accurate results. Default is live_points, but you may need to increase it to 1000 or more for complex posteriors.

log_dirstr

Where to store output files. Default is None and no results are not stored.

resumestr

‘overwrite’, overwrite previous data. ‘subfolder’, create a fresh subdirectory in log_dir. ‘resume’ or True, continue previous run if available. Only works when dimensionality, transform or likelihood are consistent.

step_samplerbool

Use a step sampler. This can be more efficient for higher dimensions (>10 or 15 parameters), but much slower for lower dimensions. Default is False.

nstepsint

Number of steps to take in each direction in the step sampler. Increase this number to get more accurate results at the cost of more computation time. Default is 10.

See the full list of options on the UltraNest documentation.

run_optsdict, optional

Optional run options passed to the given backend when running the sampler. See the full list of run options on the UltraNest documentation.

Notes

If you are using the “UltraNest” library, please follow its citation scheme: Cite UltraNest.

Examples

For a usage example, see Bayesian analysis with nested sampling tutorial.

Methods Summary

run(datasets)

Run the sampler on the provided datasets.

sampler_ultranest(parameters, like)

Defines the Ultranest sampler and options.

Methods Documentation

run(datasets)[source]#

Run the sampler on the provided datasets.

Parameters:
datasetsDatasets

Datasets to fit.

Returns:
resultSamplerResult

The sampler results. See the class description to get the exact content.

sampler_ultranest(parameters, like)[source]#

Defines the Ultranest sampler and options.

Returns the result in the SamplerResult that contains the updated models, samples, posterior distribution and other information.

Parameters:
parametersParameters

The models parameters to sample.

likeSamplerLikelihood

The likelihood function.

Returns:
resultSamplerResult

The sampler results.