public class PotentialScaleReduction extends Object
PotentialScaleReductionclass provides an online computationa of Rhat, the potential scale reduction statistic for measuring mixing and convergence of multiple Markov chain Monte Carlo (MCMC) samplers.
At construction time, the number of estimators is specified.
There must be at least two estimators in order to compute Rhat.
Samples from the Markov chains are provided to this class via the
MMarkov chains with
Nsamples each, with a sample being a floating point value
y[m,n]. As usual,
y[m,]is the sequence of samples from the single chain
n-th samples from each chain. Unbiased mean and variance estimates are defined for sequences in the usual way (see
OnlineNormalEstimatorfor definitions). Using vector notation,
mean'(y[,])is the average value of all samples whereas
mean'(y[m,])is the average of samples from chain
var'(y[,])is the variance over all samples and
var'(y[m,])the variance of samples in chain
The definition of the Rhat is:
whereRhat = sqrt(varHatPlus/W)
varHatPlusis a weighted average of the within-chain (
W) and between-chain (
The between-chain variance is defined byvarHatPlus = (N-1)/N * W + 1/N * B.
The within-chain variance is the average of the unbiased within-chain variance estimates:B = N * var'(mean'(y[m,])) = N/(M-1) * Σm (mean'(y[m,]) - mean'(y[,]))2.
This is the usual definition for chains in which there are the same number of samples. For the implementation here, we takeW = mean'(var'(y[m,])) = 1/M Σm var'(y[m,]).
Nto be the minimum of the numbers of samples in the chains. The within-chain statistics
var'(y[m,])are computed using all of the samples for chain
m. But the cross-chain statistics are not normalized, so
mean'(y[,])is computed here as
var'(y[m,]), are available through the estimator returned by
An estimator for the complete set of samples mean and variance,
var'(y[,]), are available through
globalEstimator(). Note that these are truly global
estimates, not the estimates used in asynchronous Rhat calculations
as defined in he previous section.
|Constructor and Description|
Construct a potential scale reduction for the specified matrix Of estimates for each chain.
Construct a potential scale reduction with the specified number of Markov chains for input.
|Modifier and Type||Method and Description|
Returns the estimator for the specified chain.
Returns the estimator that pools the estimates across the chains.
Returns the number of chains for this estimator.
Returns the Rhat statistic as defined in the class documentation.
Provide a sample of the specified value from the specified chain.
public PotentialScaleReduction(int numChains)
numChains- Number of Markov chains.
IllegalArgumentException- If the number of chains is less than 2.
public PotentialScaleReduction(double yss)
yss[m][n]are for the
n-th sample from chain
m. The chains may have different numbers of samples.
yss- Matrix of estimates by chain and sample.
IllegalStateException- If the number of chains (length of
yss) is less than 2.
public int numChains()
public OnlineNormalEstimator estimator(int chain)
chain- Index of chain.
public OnlineNormalEstimator globalEstimator()
public void update(int chain, double y)
chain- Chain from which sample was drawn.
y- Value of sample.
IndexOutOfBoundsException- If the chain is less than zero or greater than or equal to the number of chains.
public double rHat()