SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
CMCMC< T > Class Template Reference

Markov Chain Monte Carlo sampler for Bayesian parameter estimation. More...

#include <MCMC/MCMC.h>

Inheritance diagram for CMCMC< T >:
Inheritance graph
Collaboration diagram for CMCMC< T >:
Collaboration graph

Public Member Functions

 CMCMC (void)
 Default constructor.
 CMCMC (int nn, int nn_chains)
 Constructor with chain configuration.
 CMCMC (T *system)
 Constructor with model pointer.
bool SetProperty (const string &varname, const string &value)
 Set MCMC properties from string key-value pairs.
 ~CMCMC (void)
 Destructor.
void initialize (CMBTimeSeriesSet *results, bool random=false)
 Initialize MCMC chains with starting parameter values.
void initialize (vector< double > par)
 Initialize all chains with specific parameter values.
bool step (int k, int chain_counter)
 Perform single MCMC step for one chain.
bool step (int k, int nsamps, const string &filename, CMBTimeSeriesSet *results=nullptr, ProgressReporter *_rtw=0)
 Perform multiple MCMC steps with progress tracking and output.
vector< double > perturb (int k, int chain_counter)
 Generate proposed parameter values by perturbing current state.
void UpdateProposalCovariance (int upto)
 Re-estimates the proposal covariance from samples burn-in..upto.
void SetRandomSeed (std::uint64_t seed)
 Sets the master seed for the chains' random streams.
std::uint64_t RandomSeed () const
 The master seed of the current run.
void writeoutput (string filename)
 Write MCMC results to output file.
double posterior (vector< double > par, int chain_counter)
 Calculate log-posterior probability for given parameters.
void model (T *Model1, vector< double > par)
 Evaluate model with given parameters.
int getparamno (int i, int ts) const
 Get parameter index for a specific variable and time series.
int get_act_paramno (int i)
 Get active parameter number (legacy, may be unused).
int get_time_series (int i)
 Get time series index for parameter (legacy, may be unused).
Parameter * parameter (int i)
 Get pointer to specific parameter.
Observation * observation (int i)
 Get pointer to specific observation.
CVector sensitivity (double d, vector< double > par)
 Calculate sensitivity of model output to parameters.
CVector sensitivity_ln (double d, vector< double > par)
 Calculate log-space sensitivity (for lognormal parameters).
CMatrix sensitivity_mat_lumped (double d, vector< double > par)
 Calculate lumped sensitivity matrix.
TimeSeriesSet< double > prior_distribution (int n_bins)
 Generate histogram of prior distributions.
int readfromfile (const string &filename)
 Read MCMC state from file to continue previous run.
TimeSeriesSet< double > model (vector< double > par)
 Evaluate model for given parameters and return predictions.
void ProduceRealizations (TimeSeriesSet< double > &MCMCout)
 Generate posterior predictive realizations.
void get_outputpercentiles (TimeSeriesSet< double > &MCMCout)
 Calculate percentiles of model outputs from MCMC samples.
void SetRunTimeWindow (ProgressReporter *_rtw)
 Set progress window for GUI updates.
void Perform ()
 Main entry point to run complete MCMC analysis.

Public Attributes

T * Model
 Pointer to the model object being calibrated.
T Model_out
 Output model state after MCMC completion.
_MCMC_settings MCMC_Settings
 MCMC algorithm configuration settings.
vector< vector< double > > Params
 Parameter values for all samples and chains.
vector< double > pertcoeff
 Perturbation coefficients for each parameter.
vector< double > logp
 Log-posterior values for current state of each chain.
vector< double > logp1
 Log-posterior values for proposed states.
vector< double > u
 Uniform random values for Metropolis-Hastings accept/reject.
vector< vector< double > > proposal_chol_
 Cholesky factor of the proposal covariance; empty until the first update.
unsigned int last_covariance_update_ = 0
vector< CVector > temp_predicted
 Temporary storage for predicted model outputs.
CMBTimeSeriesSet predicted
 Model predictions as time series set.
vector< T > CopiedModels
 Copies of model object for parallel chain evaluation.
vector< int > params
 Parameter indices for model evaluation.
TimeSeriesSet< double > MData
 Measured data (observations) for likelihood calculation.
_MCMC_file_names FileInformation
 File paths for MCMC input/output.
vector< bool > apply_to_all
 Flags indicating if parameter applies to all entities.
vector< Parameter > * parameters = nullptr
 Pointer to vector of Parameter objects.
vector< Observation > * observations = nullptr
 Pointer to vector of Observation objects.
ProgressReporter * rtw = nullptr
 Pointer to progress window for GUI updates.
vector< vector< TimeSeriesSet< double > > > BTCout_obs
 Posterior predictive samples for observations.
vector< vector< TimeSeriesSet< double > > > BTCout_obs_noise
 Posterior predictive samples with simulated measurement noise.
vector< vector< TimeSeriesSet< double > > > BTCout_obs_prcntle
 Percentiles of posterior predictive distribution.
vector< vector< TimeSeriesSet< double > > > BTCout_obs_prcntle_noise
 Percentiles of posterior predictive distribution with noise.
vector< CMatrix > global_sens_lumped
 Global sensitivity analysis results (lumped).
TimeSeriesSet< double > paramsList
 List of all parameter samples from MCMC.
TimeSeriesSet< double > realized_paramsList
 Parameter samples for posterior predictive realizations.
vector< double > calc_output_percentiles
 Percentiles to calculate for output distributions.
double accepted_count = 0
 Count of accepted proposals.
std::uint64_t random_seed_ = 0
 Master seed for the chains' random streams; see SetRandomSeed().
bool random_seed_set_ = false
vector< RandomStream > chain_streams_
 One random stream per chain, so no generator is shared between threads.
double total_count = 0
 Count of total proposals (accepted + rejected).
string last_error
 Last error message from MCMC execution.

Private Member Functions

int_value_pair Min (const vector< double > &vec, int current_counter, int n_chains)
 Find minimum value and its chain index.
int_value_pair Max (const vector< double > &vec, int current_counter, int n_chains)
 Find maximum value and its chain index.

Detailed Description

template<class T>
class CMCMC< T >

Markov Chain Monte Carlo sampler for Bayesian parameter estimation.

The CMCMC class implements a sophisticated Metropolis-Hastings MCMC algorithm with advanced features for Bayesian inference in sediment source fingerprinting.

Algorithm Overview

MCMC generates samples from the posterior distribution p(θ|data) ∝ p(data|θ) × p(θ) using a random walk with accept/reject steps:

  1. Propose: Generate candidate θ* from proposal distribution q(θ*|θ_current)
  2. Evaluate: Calculate posterior ratio R = p(θ*|data) / p(θ_current|data)
  3. Accept/Reject: Accept θ* with probability min(1, R), else keep θ_current
  4. Repeat: Continue until desired number of samples obtained

Key Features

  • Multiple parallel chains for convergence diagnostics
  • Adaptive proposal tuning to achieve target acceptance rate
  • Sensitivity-based proposals for efficient exploration
  • Posterior predictive sampling for uncertainty quantification
  • Progress tracking with GUI integration
  • Checkpoint/resume capability for long runs

Usage in SedSat3

MCMC provides fully Bayesian estimates of source contributions with uncertainty:

  • Mean contributions from posterior means
  • Credible intervals (e.g., 95% intervals) from percentiles
  • Correlation between source contributions
  • Posterior predictive distributions for tracer concentrations

Mathematical Details

Log-posterior calculation:

log p(θ|data) = log p(data|θ) + log p(θ) + constant
= Σ log N(y_i | model(θ)_i, σ_i²) + Σ log p(θ_j)
void model(T *Model1, vector< double > par)
Evaluate model with given parameters.
Definition MCMC.hpp:197

Where:

  • y_i are observed tracer concentrations
  • model(θ)_i are predicted concentrations from mixing model
  • σ_i are measurement uncertainties
  • p(θ_j) are parameter prior distributions
Template Parameters
TModel class type (e.g., SourceSinkData) that provides:
  • Parameter evaluation interface
  • Likelihood calculation
  • Model predictions
Note
Thread-safe: Multiple chains can run in parallel
Warning
Requires careful tuning of proposal distribution for efficiency
See also
Parameter
Observation
SourceSinkData

Example usage:

// Create MCMC sampler for source apportionment
CMCMC<SourceSinkData> mcmc(&sourceData);
// Configure settings
mcmc.MCMC_Settings.total_number_of_samples = 50000;
mcmc.MCMC_Settings.number_of_chains = 4;
mcmc.MCMC_Settings.burnout_samples = 10000;
mcmc.MCMC_Settings.acceptance_rate = 0.234;
// Set parameters and observations
mcmc.parameters = &sourceParameters;
mcmc.observations = &tracerObservations;
// Run MCMC
mcmc.Perform();
// Extract results
mcmc.writeoutput("mcmc_results.txt");
mcmc.get_outputpercentiles(results); // Get credible intervals
CMCMC(void)
Default constructor.
Definition MCMC.hpp:26

Definition at line 350 of file MCMC.h.

Constructor & Destructor Documentation

◆ CMCMC() [1/3]

template<class T>
CMCMC< T >::CMCMC ( void )

Default constructor.

Creates an uninitialized MCMC object. Must call other initialization methods before running.

Definition at line 26 of file MCMC.hpp.

◆ CMCMC() [2/3]

template<class T>
CMCMC< T >::CMCMC ( int nn,
int nn_chains )

Constructor with chain configuration.

Parameters
nnNumber of parameters
nn_chainsNumber of parallel chains

Initializes MCMC with specified dimensions and chain count.

◆ CMCMC() [3/3]

template<class T>
CMCMC< T >::CMCMC ( T * system)

Constructor with model pointer.

Parameters
systemPointer to model object to be calibrated

Preferred constructor that links MCMC to a specific model instance.

Definition at line 719 of file MCMC.hpp.

References FileInformation, MCMC_Settings, Model, observations, parameters, params, and pertcoeff.

◆ ~CMCMC()

template<class T>
CMCMC< T >::~CMCMC ( void )

Destructor.

Cleans up allocated memory and closes output files.

Definition at line 31 of file MCMC.hpp.

References logp, logp1, and Params.

Member Function Documentation

◆ get_act_paramno()

template<class T>
int CMCMC< T >::get_act_paramno ( int i)

Get active parameter number (legacy, may be unused).

Parameters
iParameter index
Returns
Active parameter number

◆ get_outputpercentiles()

template<class T>
void CMCMC< T >::get_outputpercentiles ( TimeSeriesSet< double > & MCMCout)

Calculate percentiles of model outputs from MCMC samples.

Parameters
MCMCoutTimeSeriesSet containing MCMC samples

Computes credible intervals (percentiles specified in calc_output_percentiles) for all model outputs, providing uncertainty bounds on predictions.

Definition at line 879 of file MCMC.hpp.

References BTCout_obs, BTCout_obs_noise, BTCout_obs_prcntle, BTCout_obs_prcntle_noise, calc_output_percentiles, FileInformation, MCMC_Settings, Model, and ProduceRealizations().

◆ get_time_series()

template<class T>
int CMCMC< T >::get_time_series ( int i)

Get time series index for parameter (legacy, may be unused).

Parameters
iParameter index
Returns
Time series index

◆ getparamno()

template<class T>
int CMCMC< T >::getparamno ( int i,
int ts ) const

Get parameter index for a specific variable and time series.

Parameters
iVariable index
tsTime series index
Returns
Parameter index in MCMC parameter vector

Referenced by initialize().

◆ initialize() [1/2]

template<class T>
void CMCMC< T >::initialize ( CMBTimeSeriesSet * results,
bool random = false )

Initialize MCMC chains with starting parameter values.

Parameters
resultsPointer to results structure to store output (optional)
randomIf true, randomize initial values within parameter ranges

Sets up chains at initial parameter values. If random=true and noinipurt=false, adds random perturbations to explore different starting regions.

Precondition
parameters and observations must be set
Postcondition
Chains are positioned at starting values

Definition at line 214 of file MCMC.hpp.

References chain_streams_, CopiedModels, DrawRandomSeed(), high, last_covariance_update_, log, logp, logp1, low, MCMC_Settings, Model, parameter(), parameters, Params, pertcoeff, posterior(), predicted, proposal_chol_, random_seed_, random_seed_set_, and temp_predicted.

Referenced by Conductor::ExecuteTestCMBBayesian(), SourceSinkData::MCMC(), and Perform().

◆ initialize() [2/2]

template<class T>
void CMCMC< T >::initialize ( vector< double > par)

Initialize all chains with specific parameter values.

Parameters
parVector of parameter values [p1, p2, ..., pn]

All chains start at the same parameter values (may be perturbed if noinipurt=false).

Definition at line 302 of file MCMC.hpp.

References chain_streams_, DrawRandomSeed(), getparamno(), high, log, logp, logp1, low, MCMC_Settings, parameter(), Params, pertcoeff, posterior(), random_seed_, random_seed_set_, and sensitivity().

◆ Max()

template<class T>
int_value_pair CMCMC< T >::Max ( const vector< double > & vec,
int current_counter,
int n_chains )
private

Find maximum value and its chain index.

Parameters
vecVector of values (one per chain)
current_counterCurrent sample number
n_chainsNumber of chains
Returns
Pair containing chain index and maximum value

Utility for tracking worst (lowest likelihood) chain.

Definition at line 970 of file MCMC.hpp.

References int_value_pair::counter, and int_value_pair::value.

◆ Min()

template<class T>
int_value_pair CMCMC< T >::Min ( const vector< double > & vec,
int current_counter,
int n_chains )
private

Find minimum value and its chain index.

Parameters
vecVector of values (one per chain)
current_counterCurrent sample number
n_chainsNumber of chains
Returns
Pair containing chain index and minimum value

Utility for tracking best (highest likelihood) chain.

Definition at line 954 of file MCMC.hpp.

References int_value_pair::counter, and int_value_pair::value.

◆ model() [1/2]

template<class T>
void CMCMC< T >::model ( T * Model1,
vector< double > par )

Evaluate model with given parameters.

Parameters
Model1Pointer to model object to evaluate
parParameter values to use

Sets parameters in model and computes predictions. Used within posterior() for likelihood calculation.

Definition at line 197 of file MCMC.hpp.

References MCMC_Settings.

◆ model() [2/2]

template<class T>
TimeSeriesSet< double > CMCMC< T >::model ( vector< double > par)

Evaluate model for given parameters and return predictions.

Parameters
parParameter values
Returns
TimeSeriesSet of model predictions

Wrapper for model evaluation that returns predictions in convenient format.

Definition at line 53 of file MCMC.hpp.

References MCMC_Settings, and Model.

◆ observation()

template<class T>
Observation * CMCMC< T >::observation ( int i)

Get pointer to specific observation.

Parameters
iObservation index
Returns
Pointer to Observation object

Definition at line 47 of file MCMC.hpp.

References observations.

◆ parameter()

template<class T>
Parameter * CMCMC< T >::parameter ( int i)

Get pointer to specific parameter.

Parameters
iParameter index
Returns
Pointer to Parameter object

Definition at line 40 of file MCMC.hpp.

References parameters.

Referenced by initialize(), initialize(), posterior(), prior_distribution(), and UpdateProposalCovariance().

◆ Perform()

template<class T>
void CMCMC< T >::Perform ( )

Main entry point to run complete MCMC analysis.

Executes full MCMC workflow:

  1. Initialize chains
  2. Run burn-in samples
  3. Run production samples
  4. Calculate statistics and diagnostics
  5. Generate posterior predictive distributions
  6. Save results to files
Precondition
parameters and observations must be set
MCMC_Settings must be configured
Postcondition
Results written to output files
paramsList contains posterior samples
See also
MCMC_Settings

Definition at line 908 of file MCMC.hpp.

References initialize(), and MCMC_Settings.

◆ perturb()

template<class T>
vector< double > CMCMC< T >::perturb ( int k,
int chain_counter )

Generate proposed parameter values by perturbing current state.

Parameters
kChain index to perturb
Returns
Vector of proposed parameter values

Proposal distribution: θ* ~ N(θ_current, diag(pertcoeff²)) Respects parameter bounds by reflecting or rejecting out-of-bounds proposals.

Definition at line 498 of file MCMC.hpp.

References chain_streams_, MCMC_Settings, pertcoeff, proposal_chol_, RandomStream::StandardNormal(), and step().

Referenced by step().

◆ posterior()

template<class T>
double CMCMC< T >::posterior ( vector< double > par,
int chain_counter )

Calculate log-posterior probability for given parameters.

Parameters
parParameter vector [θ1, θ2, ..., θn]
chain_counterChain index for thread-safe model evaluation
Returns
ln(p(θ|data)) = ln(p(data|θ)) + ln(p(θ))

Computes:

  1. Log-likelihood: Σ ln N(y_observed | y_predicted(θ), σ²)
  2. Log-prior: Σ ln p(θ_i) from Parameter::CalcLogPriorProbability()
  3. Log-posterior: Sum of above
Note
Uses log-space to prevent numerical underflow
See also
Parameter::CalcLogPriorProbability()

Definition at line 179 of file MCMC.hpp.

References CopiedModels, MCMC_Settings, parameter(), and temp_predicted.

Referenced by initialize(), initialize(), and sensitivity().

◆ prior_distribution()

template<class T>
TimeSeriesSet< double > CMCMC< T >::prior_distribution ( int n_bins)

Generate histogram of prior distributions.

Parameters
n_binsNumber of bins for histogram
Returns
TimeSeriesSet containing prior PDFs for each parameter

Creates visual representation of priors for plotting and comparison with posteriors.

Definition at line 793 of file MCMC.hpp.

References log, MCMC_Settings, and parameter().

◆ ProduceRealizations()

template<class T>
void CMCMC< T >::ProduceRealizations ( TimeSeriesSet< double > & MCMCout)

Generate posterior predictive realizations.

Parameters
MCMCoutTimeSeriesSet containing MCMC samples

Samples parameters from posterior and evaluates model to create posterior predictive distribution for uncertainty quantification.

Number of realizations set by MCMC_Settings.number_of_post_estimate_realizations.

Definition at line 835 of file MCMC.hpp.

Referenced by get_outputpercentiles().

◆ RandomSeed()

template<class T>
std::uint64_t CMCMC< T >::RandomSeed ( ) const
inline

The master seed of the current run.

Definition at line 546 of file MCMC.h.

References random_seed_.

◆ readfromfile()

template<class T>
int CMCMC< T >::readfromfile ( const string & filename)

Read MCMC state from file to continue previous run.

Parameters
filenamePath to file containing saved MCMC state
Returns
Number of samples read, or negative value on error

Restores:

  • Current parameter values for each chain
  • Perturbation coefficients
  • Acceptance statistics

Allows resuming long MCMC runs without starting over.

Definition at line 767 of file MCMC.hpp.

References logp, logp1, MCMC_Settings, Params, and pertcoeff.

◆ sensitivity()

template<class T>
CVector CMCMC< T >::sensitivity ( double d,
vector< double > par )

Calculate sensitivity of model output to parameters.

Parameters
dFinite difference step size (fractional)
parCurrent parameter values
Returns
Vector of sensitivities dOutput/dθ for each parameter

Computes numerical derivatives using forward finite differences: S_i = (model(θ + δθ_i) - model(θ)) / δθ_i

Used for sensitivity-based proposal adaptation.

Definition at line 737 of file MCMC.hpp.

References MCMC_Settings, and posterior().

Referenced by initialize().

◆ sensitivity_ln()

template<class T>
CVector CMCMC< T >::sensitivity_ln ( double d,
vector< double > par )

Calculate log-space sensitivity (for lognormal parameters).

Parameters
dFinite difference step size (fractional)
parCurrent parameter values in log-space
Returns
Vector of log-space sensitivities

Definition at line 755 of file MCMC.hpp.

◆ sensitivity_mat_lumped()

template<class T>
CMatrix CMCMC< T >::sensitivity_mat_lumped ( double d,
vector< double > par )

Calculate lumped sensitivity matrix.

Parameters
dFinite difference step size
parCurrent parameter values
Returns
Matrix of sensitivities [outputs × parameters]

Computes full Jacobian matrix of model outputs with respect to parameters. Used for global sensitivity analysis and identifiability assessment.

◆ SetProperty()

template<class T>
bool CMCMC< T >::SetProperty ( const string & varname,
const string & value )

Set MCMC properties from string key-value pairs.

Parameters
varnameProperty name (e.g., "number_of_samples", "acceptance_rate")
valueProperty value as string
Returns
true if property was recognized and set successfully

Allows configuration from text files or user input.

Definition at line 75 of file MCMC.hpp.

References FileInformation, last_error, and MCMC_Settings.

Referenced by Conductor::ExecuteTestCMBBayesian(), and SourceSinkData::MCMC().

◆ SetRandomSeed()

template<class T>
void CMCMC< T >::SetRandomSeed ( std::uint64_t seed)

Sets the master seed for the chains' random streams.

Chain i draws from RandomStream(seed, i), so the same seed and settings give the same samples however many threads run the chains. Call before initialize(); if it is not called, initialize() draws a seed from the operating system. RandomSeed() returns the seed used either way.

Definition at line 706 of file MCMC.hpp.

References random_seed_, and random_seed_set_.

Referenced by Conductor::ExecuteTestCMBBayesian(), and SourceSinkData::MCMC().

◆ SetRunTimeWindow()

template<class T>
void CMCMC< T >::SetRunTimeWindow ( ProgressReporter * _rtw)

Set progress window for GUI updates.

Parameters
_rtwPointer to ProgressReporter object

Links MCMC to a progress dialog for real-time status updates.

Definition at line 713 of file MCMC.hpp.

◆ step() [1/2]

template<class T>
bool CMCMC< T >::step ( int k,
int chain_counter )

Perform single MCMC step for one chain.

Parameters
kSample iteration number
chain_counterIndex of chain to advance
Returns
true if proposed state was accepted, false if rejected

Executes one Metropolis-Hastings update:

  1. Propose new parameters
  2. Calculate log-posterior
  3. Accept/reject based on Metropolis ratio
  4. Update acceptance statistics

Definition at line 367 of file MCMC.hpp.

References MCMC_Settings, and perturb().

Referenced by Conductor::ExecuteTestCMBBayesian(), SourceSinkData::MCMC(), and perturb().

◆ step() [2/2]

template<class T>
bool CMCMC< T >::step ( int k,
int nsamps,
const string & filename,
CMBTimeSeriesSet * results = nullptr,
ProgressReporter * _rtw = 0 )

Perform multiple MCMC steps with progress tracking and output.

Parameters
kStarting sample number
nsampsNumber of samples to generate
filenameOutput file for saving samples
resultsPointer to results structure (optional)
_rtwPointer to progress window for GUI updates (optional)
Returns
true if completed successfully

Runs the main MCMC loop with:

  • Periodic output saving
  • Adaptive proposal tuning
  • Progress bar updates
  • Convergence monitoring
See also
ProgressReporter

Definition at line 540 of file MCMC.hpp.

References rtw.

◆ UpdateProposalCovariance()

template<class T>
void CMCMC< T >::UpdateProposalCovariance ( int upto)

Re-estimates the proposal covariance from samples burn-in..upto.

Stores its Cholesky factor in proposal_chol_; keeps the previous factor when there are too few samples or the matrix is not positive definite.

Definition at line 411 of file MCMC.hpp.

References log, MCMC_Settings, parameter(), and Params.

◆ writeoutput()

template<class T>
void CMCMC< T >::writeoutput ( string filename)

Write MCMC results to output file.

Parameters
filenamePath to output file

Saves:

  • Parameter samples (after burn-in)
  • Acceptance rates
  • Posterior statistics (mean, std dev, percentiles)
  • Convergence diagnostics

Format is typically tab-delimited text for easy import into analysis software.

Member Data Documentation

◆ accepted_count

template<class T>
double CMCMC< T >::accepted_count = 0

Count of accepted proposals.

Running total across all chains and samples. Used to calculate overall acceptance rate.

Definition at line 862 of file MCMC.h.

◆ apply_to_all

template<class T>
vector<bool> CMCMC< T >::apply_to_all

Flags indicating if parameter applies to all entities.

Used for shared parameters across multiple sources or observations.

Definition at line 662 of file MCMC.h.

◆ BTCout_obs

template<class T>
vector<vector<TimeSeriesSet<double> > > CMCMC< T >::BTCout_obs

Posterior predictive samples for observations.

Model predictions at sampled parameter values. Structure: BTCout_obs[observation][realization]

Definition at line 775 of file MCMC.h.

Referenced by get_outputpercentiles().

◆ BTCout_obs_noise

template<class T>
vector<vector<TimeSeriesSet<double> > > CMCMC< T >::BTCout_obs_noise

Posterior predictive samples with simulated measurement noise.

As BTCout_obs but with added observation errors sampled from measurement uncertainty distributions.

Definition at line 783 of file MCMC.h.

Referenced by get_outputpercentiles().

◆ BTCout_obs_prcntle

template<class T>
vector<vector<TimeSeriesSet<double> > > CMCMC< T >::BTCout_obs_prcntle

Percentiles of posterior predictive distribution.

Credible intervals for model predictions (e.g., 2.5%, 50%, 97.5% percentiles).

Definition at line 790 of file MCMC.h.

Referenced by get_outputpercentiles().

◆ BTCout_obs_prcntle_noise

template<class T>
vector<vector<TimeSeriesSet<double> > > CMCMC< T >::BTCout_obs_prcntle_noise

Percentiles of posterior predictive distribution with noise.

Credible intervals including measurement uncertainty.

Definition at line 797 of file MCMC.h.

Referenced by get_outputpercentiles().

◆ calc_output_percentiles

template<class T>
vector<double> CMCMC< T >::calc_output_percentiles

Percentiles to calculate for output distributions.

Vector of percentile values (0-1 scale) to compute. Typical: {0.025, 0.16, 0.5, 0.84, 0.975} for 95% and 68% intervals.

Definition at line 846 of file MCMC.h.

Referenced by get_outputpercentiles().

◆ chain_streams_

template<class T>
vector<RandomStream> CMCMC< T >::chain_streams_

One random stream per chain, so no generator is shared between threads.

Definition at line 869 of file MCMC.h.

Referenced by initialize(), initialize(), and perturb().

◆ CopiedModels

template<class T>
vector<T> CMCMC< T >::CopiedModels

Copies of model object for parallel chain evaluation.

Each chain gets its own model copy to allow thread-safe parallel execution. Dimensions: [number_of_chains]

Definition at line 570 of file MCMC.h.

Referenced by initialize(), and posterior().

◆ FileInformation

template<class T>
_MCMC_file_names CMCMC< T >::FileInformation

File paths for MCMC input/output.

Configuration structure containing output directory and filenames.

Definition at line 607 of file MCMC.h.

Referenced by CMCMC(), get_outputpercentiles(), and SetProperty().

◆ global_sens_lumped

template<class T>
vector<CMatrix> CMCMC< T >::global_sens_lumped

Global sensitivity analysis results (lumped).

Sensitivity matrices calculated across posterior samples.

Definition at line 804 of file MCMC.h.

◆ last_covariance_update_

template<class T>
unsigned int CMCMC< T >::last_covariance_update_ = 0

Definition at line 533 of file MCMC.h.

Referenced by initialize().

◆ last_error

template<class T>
string CMCMC< T >::last_error

Last error message from MCMC execution.

If MCMC fails or encounters issues, error description is stored here.

Definition at line 883 of file MCMC.h.

Referenced by SetProperty().

◆ logp

template<class T>
vector<double> CMCMC< T >::logp

Log-posterior values for current state of each chain.

Dimensions: [number_of_chains] Updated after each MCMC step.

Definition at line 440 of file MCMC.h.

Referenced by ~CMCMC(), initialize(), initialize(), and readfromfile().

◆ logp1

template<class T>
vector<double> CMCMC< T >::logp1

Log-posterior values for proposed states.

Temporary storage for evaluating proposed parameter values. Dimensions: [number_of_chains]

Definition at line 448 of file MCMC.h.

Referenced by ~CMCMC(), initialize(), initialize(), and readfromfile().

◆ MCMC_Settings

template<class T>
_MCMC_settings CMCMC< T >::MCMC_Settings

MCMC algorithm configuration settings.

All tuning parameters and flags controlling MCMC behavior. Modify before calling Perform() or initialize().

Definition at line 416 of file MCMC.h.

Referenced by CMCMC(), get_outputpercentiles(), initialize(), initialize(), model(), model(), Perform(), perturb(), posterior(), prior_distribution(), readfromfile(), sensitivity(), SetProperty(), step(), and UpdateProposalCovariance().

◆ MData

template<class T>
TimeSeriesSet<double> CMCMC< T >::MData

Measured data (observations) for likelihood calculation.

Contains observed tracer concentrations and their uncertainties. Used to calculate likelihood: p(data|θ).

Definition at line 600 of file MCMC.h.

◆ Model

template<class T>
T* CMCMC< T >::Model

Pointer to the model object being calibrated.

The model provides likelihood evaluation and predictions. For SedSat3, this is typically a SourceSinkData object.

Definition at line 359 of file MCMC.h.

Referenced by CMCMC(), Conductor::ExecuteTestCMBBayesian(), get_outputpercentiles(), initialize(), SourceSinkData::MCMC(), and model().

◆ Model_out

template<class T>
T CMCMC< T >::Model_out

Output model state after MCMC completion.

Contains model configured with best-fit or posterior mean parameters.

Definition at line 366 of file MCMC.h.

◆ observations

template<class T>
vector<Observation>* CMCMC< T >::observations = nullptr

Pointer to vector of Observation objects.

Contains observed tracer concentrations and measurement uncertainties. Must be set before running MCMC.

Definition at line 678 of file MCMC.h.

Referenced by CMCMC(), and observation().

◆ parameters

template<class T>
vector<Parameter>* CMCMC< T >::parameters = nullptr

Pointer to vector of Parameter objects.

Contains prior distributions, ranges, and names for all parameters. Must be set before running MCMC.

Definition at line 670 of file MCMC.h.

Referenced by CMCMC(), initialize(), and parameter().

◆ Params

template<class T>
vector<vector<double> > CMCMC< T >::Params

Parameter values for all samples and chains.

Storage structure: Params[chain_index][parameter_index] Dimensions: [number_of_chains][number_of_parameters]

Definition at line 424 of file MCMC.h.

Referenced by ~CMCMC(), initialize(), initialize(), readfromfile(), and UpdateProposalCovariance().

◆ params

template<class T>
vector<int> CMCMC< T >::params

Parameter indices for model evaluation.

Maps MCMC parameter space to model parameter space. May be a subset if some parameters are fixed.

Definition at line 592 of file MCMC.h.

Referenced by CMCMC().

◆ paramsList

template<class T>
TimeSeriesSet<double> CMCMC< T >::paramsList

List of all parameter samples from MCMC.

Complete chain history after burn-in for posterior analysis.

Definition at line 811 of file MCMC.h.

◆ pertcoeff

template<class T>
vector<double> CMCMC< T >::pertcoeff

Perturbation coefficients for each parameter.

Adaptive proposal standard deviations, one per parameter. Updated during sampling to achieve target acceptance rate.

Definition at line 432 of file MCMC.h.

Referenced by CMCMC(), initialize(), initialize(), perturb(), and readfromfile().

◆ predicted

template<class T>
CMBTimeSeriesSet CMCMC< T >::predicted

Model predictions as time series set.

Contains predicted tracer concentrations for plotting and comparison with observations.

Definition at line 562 of file MCMC.h.

Referenced by initialize(), and SourceSinkData::MCMC().

◆ proposal_chol_

template<class T>
vector<vector<double> > CMCMC< T >::proposal_chol_

Cholesky factor of the proposal covariance; empty until the first update.

Definition at line 532 of file MCMC.h.

Referenced by initialize(), and perturb().

◆ random_seed_

template<class T>
std::uint64_t CMCMC< T >::random_seed_ = 0

Master seed for the chains' random streams; see SetRandomSeed().

Definition at line 865 of file MCMC.h.

Referenced by initialize(), initialize(), RandomSeed(), and SetRandomSeed().

◆ random_seed_set_

template<class T>
bool CMCMC< T >::random_seed_set_ = false

Definition at line 866 of file MCMC.h.

Referenced by initialize(), initialize(), and SetRandomSeed().

◆ realized_paramsList

template<class T>
TimeSeriesSet<double> CMCMC< T >::realized_paramsList

Parameter samples for posterior predictive realizations.

Subset of posterior samples used to generate model predictions.

Definition at line 818 of file MCMC.h.

◆ rtw

template<class T>
ProgressReporter* CMCMC< T >::rtw = nullptr

Pointer to progress window for GUI updates.

If not nullptr, MCMC will update progress bar and display current acceptance rate, parameter values, etc.

Definition at line 722 of file MCMC.h.

Referenced by step().

◆ temp_predicted

template<class T>
vector<CVector> CMCMC< T >::temp_predicted

Temporary storage for predicted model outputs.

Used during likelihood evaluation to store model predictions for each chain without modifying the main model object.

Definition at line 554 of file MCMC.h.

Referenced by initialize(), and posterior().

◆ total_count

template<class T>
double CMCMC< T >::total_count = 0

Count of total proposals (accepted + rejected).

Running total of all MCMC steps attempted.

Definition at line 876 of file MCMC.h.

◆ u

template<class T>
vector<double> CMCMC< T >::u

Uniform random values for Metropolis-Hastings accept/reject.

Pre-generated uniform random numbers U(0,1) for comparing with acceptance probability. Dimensions: [number_of_chains]

Definition at line 457 of file MCMC.h.


The documentation for this class was generated from the following files: