gcfit.probabilities.posterior#
- gcfit.probabilities.posterior(theta, observations, fixed_initials=None, L_components=None, prior_likelihood=None, *, hyperparams=False, return_indiv=True)#
Compute the full posterior probability given theta and observations.
Combines the various likelihood functions (through log_likelihood) and the priors on the given theta parameters to compute and return the full posterior probability.
This function is designed for use by a bayesian sampler class, like emcee.EnsembleSampler or dynesty.DynamicNestedSampler. The accepted arguments are therefore slightly different than what might be expected in other parts of the package (e.g. theta must be an array).
- Parameters:
- thetanp.ndarray
An array of model input parameters, which must be in the expected order (W0, M, rh, ra, g, delta, a1, a2, a3, BHret, s2, F and d). Only parameters which are specified in fixed_initials may be excluded here. A dictionary of parameters is not allowed.
- observationsObservations
The Observations instance corresponding to this cluster, to provide the “data” for this posterior calculation.
- fixed_initialsdict, optional
An optional dictionary of parameters which provides fixed values for specific parameters used to fill out the theta array. This is useful for allowing samplers to explore a smaller set of parameters by fixing certain usually free ones.
- L_componentslist of lists, optional
List of likelihood components to compute. Must be a list of lists in the same format as observations.valid_likelihoods (dataset name, likelihood function, *function params). Will default to using those given by observations.valid_likelihoods.
- prior_likelihoodPriors or “ignore”, optional
The Priors object corresponding to the desired sets of priors for this given parameter set. If None (the default), will use the default priors defined in priors.DEFAULT_PRIORS. If “ignore”, will assume the priors have already been dealt with (e.g. as done in dynesty) and will ignore them.
- hyperparamsbool, optional
Whether to include bayesian hyperparameters in all likelihood functions.
- return_indivbool, optional
If True (default) will also return all individual likelihood values alongside the posterior probability. Can be used by some sampler classes, such as the blobs functionality of emcee.
- Returns:
- float or tuple
The total posterior probability. If return_indiv is True, will return a tuple where the first element is the posterior probability and the remaining elements are the individual log likelihood values for each likelihood function.