uravu.sampling

The sampling module implements the use of a generalised MCMC (using emcee) and nested sampling (using dynesty) for the Relationship objects.

uravu.sampling.ln_probability(variables, function, abscissa, ordinate, priors)[source]

Determine the natural log probability for a given set of variables, by summing the prior and likelihood.

Parameters:
  • variables (array_like) – Variables for the function evaluation.
  • function (callable) – The function to be evaluated.
  • abscissa (array_like) – The abscissa values.
  • ordinate (array_like) – The ordinate values.
  • unaccounted_uncertainty (bool) – Should an unaccounted uncertainty parameter be considered.
  • prior_function (callable, optional) – The function to populated some prior distributions. Default is prior().
Returns:

Negative natural log-probability between model and data, considering priors.

Return type:

float

uravu.sampling.mcmc(relationship, prior_function=None, walkers=50, n_samples=500, n_burn=500, progress=True)[source]

Perform MCMC to get the probability distributions for the variables of the relationship.

Parameters:
  • relationship (uravu.relationship.Relationship) – The relationship to determine the posteriors of.
  • prior_function (callable, optional) – The function to populated some prior distributions. Default is uravu.relationship.Relationship.prior().
  • walkers (int, optional) – Number of MCMC walkers. Default is 50.
  • n_samples (int, optional) – Number of sample points. Default is 500.
  • n_burn (int, optional) – Number of burn in samples. Default is 500.
  • progress (bool, optional) – Show tqdm progress for sampling. Default is True.
Returns:

Dictionary with the distributions as a list ('distributions'), the chain ('chain') and the samples as an array_like ('samples').

Return type:

dict

uravu.sampling.nested_prior(array, priors)[source]

Convert to dynesty prior style from at used within uravu.

Parameters:
  • array (array_like) – An array of random uniform numbers (0, 1]. The shape of which is M x N, where M is the number of parameters and N is the number of walkers.
  • prior_function (callable, optional) – The function to populated some prior distributions. Default is uravu.relationship.Relationship.prior().
Returns:

An array of random uniform numbers distributed in agreement with the priors.

Return type:

array_like

uravu.sampling.nested_sampling(relationship, prior_function=None, progress=True, dynamic=False, **kwargs)[source]

Perform the nested sampling, or dynamic nested sampling, in order to determine the Bayesian natural log evidence. See the dynesty.NestedSampler.run_nested() documentation.

Parameters:
  • relationship (Relationship) – The relationship to estimate the evidence for.
  • prior_function (callable, optional) – The function to populated some prior distributions. Default is the broad uniform priors in prior().
  • progress (bool, optional) – Show tqdm progress for sampling. Default is True.
  • dynamic (bool, optional) – Should dynamic nested sampling be used?. Default is False.
Returns:

The results from dynesty.NestedSampler.run_nested().

Return type:

dict