truth#

Module implementing the main class Truth wrapping the true log-posterior and associated definitions: parameter names and labels, prior bounds and reference bounds for initialization (optional).

gpry.truth.get_truth(loglike, bounds=None, ref_bounds=None, params=None)[source]#

Instantiates and returns a Truth|TruthCobaya object.

Parameters:
  • loglike (callable or Cobaya model object) – Log-likelihood function or Cobaya Model instance. If a Cobaya model is passed, arguments bounds, ref_bounds and params are ignored, since all that information is already contained in the Cobaya model.

  • bounds (List of [min, max], or Dict {name: [min, max],...}) – List or dictionary of parameter bounds. If it is a dictionary, the keys need to correspond to the argument names of the likelihood function, and the values can be either bounds specified as [min, max], or bounds and labels, as {"prior": [min, max], "latex": [label]}. It does not need to be defined (will be ignored) if a Cobaya Model instance is passed as loglike.

  • ref_bounds (List of [min, max], or Dict {name: [min, max],...}) – List or dictionary of “reference” parameter bounds, i.e. bounds from within which to raw the initial set of training samples.

  • params (list of str, dict {str: str}, optional) – List of names for the parameters. Alternatively, a dictionary {name: label}, where label is a LaTeX-coded string, without $’s. By default, generic parameter names x_1, x_2,... will be used.

Return type:

truth.Truth or truth.TruthCobaya

class gpry.truth.Truth(loglike, bounds=None, ref_bounds=None, params=None)[source]#

Bases: object

Class holding the true log-posterior and some information about it.

Parameters:
  • loglike (callable) – Log-likelihood function.

  • bounds (List of [min, max], or Dict {name: [min, max],...}) – List or dictionary of parameter bounds. If it is a dictionary, the keys need to correspond to the argument names of the likelihood function, and the values can be either bounds specified as [min, max], or bounds and labels, as {"prior": [min, max], "latex": [label]}. It does not need to be defined (will be ignored) if a Cobaya Model instance is passed as loglike.

  • ref_bounds (List of [min, max], or Dict {name: [min, max],...}) – List or dictionary of “reference” parameter bounds, i.e. bounds from within which to raw the initial set of training samples. ref_bounds must have the same length as bounds, with None as an entry for which reference bounds different from the prior bounds are not given.

  • params (list of str, dict {str: str}, optional) – List of names for the parameters. Alternatively, a dictionary {name: label}, where label is a LaTeX-coded string, without $’s. By default, generic parameter names x_1, x_2,... will be used.

property d#

Dimensionality of the problem.

property prior_bounds#

Prior bounds, as an array of shape = (dim, 2).

property params#

Returns the list of parameter names.

property labels#

Returns the list of labels.

logprior(X)[source]#

Evaluates and returns the log-prior for a single point X.

loglike(X)[source]#

Evaluates and returns the log-likelihood for a single point X.

logp(X)[source]#

Evaluates and returns the log-posterior for a single point X.

prior_sample(rng)[source]#

Draws one point from the prior.

ref_sample(rng)[source]#

Draws one point from the reference distribution.

as_dict()[source]#

Returns this instance as a dictionary so that it can be re-initialised with the returned values as args.

class gpry.truth.TruthCobaya(model)[source]#

Bases: Truth

Truth class wrapping a Cobaya model.

Parameters:

loglike

logprior(X)[source]#

Evaluates and returns the log-prior.

loglike(X)[source]#

Evaluates and returns the log-likelihood.

logp(X)[source]#

Evaluates and returns the log-posterior.

prior_sample(rng)[source]#

Draws one point from the prior.

ref_sample(rng)[source]#

Draws one point from the reference distribution.

as_dict()[source]#

Returns this instance as a dictionary so that it can be re-initialised with the returned values as args.