uravu.relationship¶
The Relationship
class is a foundational component of the uravu
package, and acts as the main API for use of the package.
This class enables the storage of the relationship between the model and the data.
Objects of this class offer easy methods to perform maximum likelihood evaluation, Markiv chain Monte Carlo (MCMC) for posterior probabiltiy determination and Bayesian evidence estimation by nested sampling.
See the tutorials online for more guidence of how to use this package.

class
uravu.relationship.
Relationship
(function: Callable, abscissa: Union[List[float], numpy.ndarray], ordinate: Union[List[Union[uravu.distribution.Distribution, scipy.stats._distn_infrastructure.rv_frozen, float]], numpy.ndarray], bounds: Tuple[Tuple[float, float]] = None, ordinate_error: Union[List[float], numpy.ndarray] = None)[source]¶ Bases:
object
The
Relationship
class is the base of theuravu
package, enabling the use of Bayesian inference for the assessment of a model’s ability to describe some data.Attributes: :param function (
callable
): The function that is modelled. :param abscissa (array_like
): The abscissa data that the modelling should be performed on. :param ordinate (list
oruravu.distribution.Distribution
orarray_like
): The ordinate data against with the model should be compared. This should be anlist
oruravu.distribution.Distribution
unless aordinate_error
is given. :param variables (list
ofuravu.distribution.Distribution
): Variables in thefunction
.bounds (tuple
): The minimum and maximum values for each parameters. ln_evidence (uncertainties.core.Variable
): The naturallog of the Bayesian evidence for the model to the given data. mcmc_results (dict
): The results fromemcee.EnsembleSampler.run_mcmc()
sampling. nested_sampling_results (dict
): The results fromdynesty.NestedSampler.run_nested()
nested sampling.Parameters:  function – The functional relationship to be modelled.
 abscissa – The abscissa data. If multidimensional, the array is expected to have the shape
(N, d)
, whereN
is the number of data points andd
is the dimensionality.  ordinate – The ordinate data. This should have a shape
(N,)
.  bounds – The minimum and maximum values for each parameters. Defaults to
None
.  ordinate_error – The uncertainty in the ordinate, this should be the standard error in the measurement. Only used if
ordinate
is not alist
oruravu.distribution.Distribution
. Defaults toNone
.

bayesian_information_criteria
()[source]¶ Calculate the Bayesian information criteria for the relationship.
Returns: Bayesian information criteria. Return type: float

flatchain
¶ Sampling flatchain.
Type: return

get_sample
(i)[source]¶ Return the variable values for a given sample.
Parameters: i ( int
) – The sample index.Returns: Variable values at given index. Return type: list
offloat

len_parameters
¶ Determine the number of variables in the assessment function.
Returns: py:attr`int`: Number of variables.

max_likelihood
(method, x0=None, **kwargs)[source]¶ Determine values for the variables which maximise the likelihood for the
Relationship
. For keyword arguments see thescipy.optimize.minimize()
documentation.Parameters: x0 ( array_like
) – Initial guess values for the parameters.

mcmc
(prior_function=None, walkers=50, n_samples=500, n_burn=500, progress=True)[source]¶ Perform MCMC to get the posterior probability distributions for the variables of the relationship. Note, running this method will populate the
variables
attribute withDistribution
objects. Once run, a result dictionary containing thedistributions
,chain
, andsamples
fromemcee
is piped into the class variablemcmc_results
.Parameters:  prior_function (
callable
, optional) – The function to populated some prior distributions. Default is the broad uniform priors inprior()
.  walkers (
int
, optional) – Number of MCMC walkers. Default is50
.  n_samples (
int
, optional) – Number of sample points. Default is :py:attr:500`.  n_burn (
int
, optional) – Number of burn in samples. Default is500
.  progress (
bool
, optional) – Showtqdm
progress for sampling. Default isTrue
.
 prior_function (

mcmc_done
¶ Has MCMC been performed? Determined based on the type of the variables.
Returns: Has MCMC been performed? Return type: bool

nested_sampling
(prior_function=None, progress=True, dynamic=False, **kwargs)[source]¶ Perform nested sampling, or dynamic nested sampling, to determine the Bayesian naturallog evidence. For keyword arguments see the
dynesty.NestedSampler.run_nested()
documentation. Once run, the result dictionary produced bydynesty.NestedSampler.run_nested()
is piped into the class variablenested_sampling_results
.Parameters:  prior_function (
callable
, optional) – The function to populate some prior distributions. Default is the broad uniform priors inprior()
.  progress (
bool
, optional) – Showtqdm
progress for sampling. Default isTrue
.
 prior_function (

nested_sampling_done
¶ Has nested sampling been performed? Determined based on if the ln_evidence has a value.
Returns: Has nested sampling been performed? Return type: bool

prior
()[source]¶ Standard priors for the relationship. These priors are broad, uninformative, for normal variables running the range
[x  x * 10, x + x * 10)
(wherex
is the variable value).Returns: scipy.stats
functions describing the priors.Return type: list
ofscipy.stats.rv_continuous

variable_medians
¶ The median values for each of the variables.
Returns: Variable medians. Return type: array_like

variable_modes
¶ The mode values for each of the variables.
Returns: Variable modes. Return type: array_like

x
¶ Abscissa values.
Returns: Abscissa values. Return type: array_like

y
¶ Ordinate values.
Returns: Ordinate values. Return type: array_like