bayesvalidrox.bayes_inference.mcmc.MCMC¶
- class bayesvalidrox.bayes_inference.mcmc.MCMC(engine, mcmc_params, Discrepancy, bias_inputs, error_model, req_outputs, selected_indices, emulator, out_dir, name, BiasInputs=None)¶
Bases:
object
A class for bayesian inference via a Markov-Chain Monte-Carlo (MCMC) Sampler to approximate the posterior distribution of the Bayes theorem: $$p(theta|mathcal{y}) = frac{p(mathcal{y}|theta) p(theta)}
{p(mathcal{y})}.$$
This class make inference with emcee package [1] using an Affine Invariant Ensemble sampler (AIES) [2].
- [1] Foreman-Mackey, D., Hogg, D.W., Lang, D. and Goodman, J., 2013.emcee:
the MCMC hammer. Publications of the Astronomical Society of the Pacific, 125(925), p.306. https://emcee.readthedocs.io/en/stable/
- [2] Goodman, J. and Weare, J., 2010. Ensemble samplers with affine
invariance. Communications in applied mathematics and computational science, 5(1), pp.65-80.
Attributes¶
- BayesOptsobj
Bayes object.
- enginebayesvalidrox.Engine
Engine object that contains the surrogate, model and expdesign
- mcmc_paramsdict
Dictionary of parameters for the mcmc. Required are - init_samples - n_steps - n_walkers - n_burn - moves - multiplrocessing - verbose
- Discrepancybayesvalidrox.Discrepancy
Discrepancy object that described the uncertainty of the data.
bias_inputs :
error_model :
req_outputs :
selected_indices :
emulator :
- out_dirstring
Directory to write the outputs to.
- namestring
Name of this MCMC selection (?)
- BiasInputs
The default is None.
- __init__(engine, mcmc_params, Discrepancy, bias_inputs, error_model, req_outputs, selected_indices, emulator, out_dir, name, BiasInputs=None)¶
Methods
__init__
(engine, mcmc_params, Discrepancy, ...)eval_model
(theta)Evaluates the (meta-) model at the given theta.
log_likelihood
(theta)Computes likelihood ( p(mathcal{Y}|theta)) of the performance of the (meta-)model in reproducing the observation data.
log_posterior
(theta)Computes the posterior likelihood (p(theta| mathcal{Y})) for the given parameterset.
log_prior
(theta)Calculates the log prior likelihood ( p(theta)) for the given parameter set(s) ( theta ).
normpdf
(outputs, obs_data, total_sigma2s[, ...])Calculates the likelihood of simulation outputs compared with observation data.
run_sampler
(observation, total_sigma2)Run the MCMC sampler for the given observations and stdevs.
train_error_model
(sampler)Trains an error model using a Gaussian Process Regression.
- eval_model(theta)¶
Evaluates the (meta-) model at the given theta.
Parameters¶
- thetaarray of shape (n_samples, n_params)
Parameter set, i.e. proposals of the MCMC chains.
Returns¶
- mean_preddict
Mean model prediction.
- std_preddict
Std of model prediction.
- log_likelihood(theta)¶
Computes likelihood ( p(mathcal{Y}|theta)) of the performance of the (meta-)model in reproducing the observation data.
Parameters¶
- thetaarray of shape (n_samples, n_params)
Parameter set, i.e. proposals of the MCMC chains.
Returns¶
- log_likearray of shape (n_samples)
Log likelihood.
- log_posterior(theta)¶
Computes the posterior likelihood (p(theta| mathcal{Y})) for the given parameterset.
Parameters¶
- thetaarray of shape (n_samples, n_params)
Parameter set, i.e. proposals of the MCMC chains.
Returns¶
- log_likearray of shape (n_samples)
Log posterior likelihood.
- log_prior(theta)¶
Calculates the log prior likelihood ( p(theta)) for the given parameter set(s) ( theta ).
Parameters¶
- thetaarray of shape (n_samples, n_params)
Parameter sets, i.e. proposals of MCMC chains.
Returns¶
- logprior: float or array of shape n_samples
Log prior likelihood. If theta has only one row, a single value is returned otherwise an array.
- normpdf(outputs, obs_data, total_sigma2s, sigma2=None, std=None)¶
Calculates the likelihood of simulation outputs compared with observation data.
Parameters¶
- outputsdict
A dictionary containing the simulation outputs as array of shape (n_samples, n_measurement) for each model output.
- obs_datadict
A dictionary/dataframe containing the observation data.
- total_sigma2sdict
A dictionary with known values of the covariance diagonal entries, a.k.a. sigma^2.
- sigma2array, optional
An array of the sigma^2 samples, when the covariance diagonal entries are unknown and are being jointly inferred. The default is None.
- stddict, optional
A dictionary containing the root mean squared error as array of shape (n_samples, n_measurement) for each model output. The default is None.
Returns¶
- logLikarray of shape (n_samples)
Likelihoods.