Posterior Sampling State¶
Class providing the state vector during Bayesian posterior sampling simulations—the current position of a Markov chain in parameter space, together with its chain index, step count, and parameter count. Implementations store and retrieve the parameter vector (via get/set), advance the step counter, and optionally maintain a history of chain positions for convergence diagnostics. The state is updated at each MCMC step and queried by the likelihood function to evaluate the model at the proposed parameter values.
Default implementation: posteriorSampleStateSimple
Methods¶
parameterCountSetSet the number of active parameters that this state vector will track, allocating internal storage for the parameter vector of the given dimension.
integer parameterCount[in]
chainIndex→integerReturn the integer index (0-based) of the Markov chain that owns this state object, used to identify chains in multi-chain posterior sampling algorithms.
chainIndexSetAssign the integer chain index to this state object, identifying which Markov chain it belongs to in a multi-chain ensemble sampler.
integer chainIndex[in]
count→integerReturns the total number of sampling steps that have been taken since the state was last reset, used for logging and convergence diagnostics.
dimension→integerReturns the number of active parameters (dimension of the state vector) for this sampling state, equal to the value previously set by
parameterCountSet.resetReset the state object to its initial condition by zeroing the step counter and clearing any accumulated history, in preparation for a new sampling run.
get→double precision(self%parameterCount)Return the current parameter vector representing the position of this chain in the model parameter space at the most recently accepted sampling step.
updateAdvance the state to the new parameter vector
stateNew, optionally logging it to the chain history;isConvergedandoutlierMaskare used to track whether post-convergence steps should be recorded.double precision(:) stateNew[in]logical logState[in]logical isConverged[in]logical(:) outlierMask(optional) [in]
mean→double precision(self%parameterCount)Return the mean parameter vector computed over all stored steps in the chain history, providing a point estimate of the posterior mode or mean.
variance→double precision(self%parameterCount)Return the per-parameter variance computed over all stored steps in the chain history, providing a measure of posterior width for each model parameter.
acceptanceRate→double precisionReturn the fraction of proposed moves that were accepted over the recent history of this chain, used to monitor and adaptively tune proposal distributions.
restoreReplay a previously recorded state vector into the state history one step at a time, used when resuming a sampling run from a saved log file;
firstsignals the start of the restoration sequence.double precision(:) stateVector[in]logical first[in]
posteriorSampleStateCorrelation¶
An extension of the history state, this class also computes and stores the correlation length in each parameter (which is taken to be the median correlation length over all non-outlier chains).
Methods
correlationLength→integerReturn the current correlation length in the chains.
correlationLengthComputeCompute correlation lengths in the chains.
logical(:) outlierMask(optional) [in]
postConvergenceCorrelationCount→integerReturn the number of post-convergence correlation lengths that have accrued.
Parameters
[acceptedStateCount](integer; default100) — The number of states to use in acceptance rate statistics.
posteriorSampleStateHistory¶
An extension of the simple state, this class also records the mean and variance of each parameter over the history of the simulation.
Parameters
[acceptedStateCount](integer; default100) — The number of states to use in acceptance rate statistics.
posteriorSampleStateSimple¶
This class stores the current state but makes no attempt to record a history of the state and so cannot provide measures of the mean or variance of state over the simulation history. It does, however, maintain a running average of the state acceptance rate. The number of steps over which the acceptance rate should be computed is specified by the acceptedStateCount.
(Default implementation)
Methods
countSetSet the state count.
integer stateCount[in]
Parameters
[acceptedStateCount](integer; default100) — The number of states to use in acceptance rate statistics.