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 isprior().
Returns: Negative natural log-probability between model and data, considering priors.
Return type: float- variables (
-
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 isuravu.relationship.Relationship.prior(). - walkers (
int, optional) – Number of MCMC walkers. Default is50. - n_samples (
int, optional) – Number of sample points. Default is500. - n_burn (
int, optional) – Number of burn in samples. Default is500. - progress (
bool, optional) – Show tqdm progress for sampling. Default isTrue.
Returns: Dictionary with the distributions as a list (
'distributions'), the chain ('chain') and the samples as anarray_like('samples').Return type: dict- relationship (
-
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 isuravu.relationship.Relationship.prior().
Returns: An array of random uniform numbers distributed in agreement with the priors.
Return type: array_like- array (
-
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 inprior(). - progress (
bool, optional) – Showtqdmprogress for sampling. Default isTrue. - dynamic (
bool, optional) – Should dynamic nested sampling be used?. Default isFalse.
Returns: The results from
dynesty.NestedSampler.run_nested().Return type: dict- relationship (