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

parameterCountSet

Set 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]

chainIndexinteger

Return the integer index (0-based) of the Markov chain that owns this state object, used to identify chains in multi-chain posterior sampling algorithms.

chainIndexSet

Assign the integer chain index to this state object, identifying which Markov chain it belongs to in a multi-chain ensemble sampler.

  • integer chainIndex [in]

countinteger

Returns the total number of sampling steps that have been taken since the state was last reset, used for logging and convergence diagnostics.

dimensioninteger

Returns the number of active parameters (dimension of the state vector) for this sampling state, equal to the value previously set by parameterCountSet.

reset

Reset the state object to its initial condition by zeroing the step counter and clearing any accumulated history, in preparation for a new sampling run.

getdouble 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.

update

Advance the state to the new parameter vector stateNew, optionally logging it to the chain history; isConverged and outlierMask are used to track whether post-convergence steps should be recorded.

  • double precision(:) stateNew [in]

  • logical logState [in]

  • logical isConverged [in]

  • logical(:) outlierMask (optional) [in]

meandouble 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.

variancedouble 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.

acceptanceRatedouble precision

Return the fraction of proposed moves that were accepted over the recent history of this chain, used to monitor and adaptively tune proposal distributions.

restore

Replay 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; first signals 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

correlationLengthinteger

Return the current correlation length in the chains.

correlationLengthCompute

Compute correlation lengths in the chains.

  • logical(:) outlierMask (optional) [in]

postConvergenceCorrelationCountinteger

Return the number of post-convergence correlation lengths that have accrued.

Parameters

  • [acceptedStateCount] (integer; default 100) — 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; default 100) — 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

countSet

Set the state count.

  • integer stateCount [in]

Parameters

  • [acceptedStateCount] (integer; default 100) — The number of states to use in acceptance rate statistics.