threeML.bayesian package

Submodules

threeML.bayesian.bayesian_analysis module

class threeML.bayesian.bayesian_analysis.BayesianAnalysis(likelihood_model: astromodels.core.model.Model, data_list: threeML.data_list.DataList, **kwargs)[source]

Bases: object

property analysis_type
convergence_plots(n_samples_in_each_subset, n_subsets)[source]

Compute the mean and variance for subsets of the samples, and plot them. They should all be around the same values if the MCMC has converged to the posterior distribution.

The subsamples are taken with two different strategies: the first is to slide a fixed-size window, the second is to take random samples from the chain (bootstrap)

Parameters
  • n_samples_in_each_subset – number of samples in each subset

  • n_subsets – number of subsets to take for each strategy

Returns

a matplotlib.figure instance

property data_list
Returns

data list for this analysis

property likelihood_model
Returns

likelihood model (a Model instance)

property log_like_values

Returns the value of the log_likelihood found by the bayesian sampler while sampling from the posterior. If you need to find the values of the parameters which generated a given value of the log. likelihood, remember that the samples accessible through the property .raw_samples are ordered in the same way as the vector returned by this method.

Returns

a vector of log. like values

property log_marginal_likelihood

Return the log marginal likelihood (evidence

) if computed
return

property log_probability_values

Returns the value of the log_probability (posterior) found by the bayesian sampler while sampling from the posterior. If you need to find the values of the parameters which generated a given value of the log. likelihood, remember that the samples accessible through the property .raw_samples are ordered in the same way as the vector returned by this method.

Returns

a vector of log probabilty values

plot_chains(thin=None)[source]

Produce a plot of the series of samples for each parameter

Parameters

thin – use only one sample every ‘thin’ samples

Returns

a matplotlib.figure instance

property raw_samples

Access the samples from the posterior distribution generated by the selected sampler in raw form (i.e., in the format returned by the sampler)

Returns

the samples as returned by the sampler

restore_median_fit()[source]

Sets the model parameters to the mean of the marginal distributions

property results
sample(quiet=False)[source]
property sampler

Access the instance of the sampler used to sample the posterior distribution :return: an instance of the sampler

property samples

Access the samples from the posterior distribution generated by the selected sampler

Returns

a dictionary with the samples from the posterior distribution for each parameter

set_sampler(sampler_name: str, **kwargs)[source]

Set the sampler :param sampler_name: (str) Name of sampler :param share_spectrum: (optional) Option to share the spectrum calc between detectors with the same input energy bins

threeML.bayesian.tutorial_material module

class threeML.bayesian.tutorial_material.BayesianAnalysisWrap(likelihood_model: astromodels.core.model.Model, data_list: threeML.data_list.DataList, **kwargs)[source]

Bases: threeML.bayesian.bayesian_analysis.BayesianAnalysis

sample(*args, **kwargs)[source]
threeML.bayesian.tutorial_material.array_to_cmap(values, cmap, use_log=False)[source]

Generates a color map and color list that is normalized to the values in an array. Allows for adding a 3rd dimension onto a plot

Parameters
  • values – a list a values to map into a cmap

  • cmap – the mpl colormap to use

  • use_log – if the mapping should be done in log space

threeML.bayesian.tutorial_material.get_bayesian_analysis_object_complex_likelihood()[source]
threeML.bayesian.tutorial_material.get_bayesian_analysis_object_simple_likelihood()[source]
threeML.bayesian.tutorial_material.plot_likelihood_function(bayes, fig=None, show_prior=False)[source]
threeML.bayesian.tutorial_material.plot_sample_path(bayes, burn_in=None, truth=None)[source]
Parameters

jl (JointLikelihood) –

Returns

Module contents