Diagnostics
This provides a small set of utilities in NumPyro that are used to diagnose posterior samples.
Autocorrelation
- autocorrelation(x: ndarray[tuple[Any, ...], dtype[_ScalarT]], axis: int = 0, bias: bool = True) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]
Computes the autocorrelation of samples at dimension
axis.- Parameters:
x (numpy.ndarray) – the input array.
axis (int) – the dimension to calculate autocorrelation.
bias – whether to use a biased estimator.
- Returns:
autocorrelation of
x.- Return type:
Autocovariance
- autocovariance(x: ndarray[tuple[Any, ...], dtype[_ScalarT]], axis: int = 0, bias: bool = True) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]
Computes the autocovariance of samples at dimension
axis.- Parameters:
x (numpy.ndarray) – the input array.
axis (int) – the dimension to calculate autocovariance.
bias – whether to use a biased estimator.
- Returns:
autocovariance of
x.- Return type:
Effective Sample Size
- effective_sample_size(x: ndarray[tuple[Any, ...], dtype[_ScalarT]], bias: bool = True) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]
Computes effective sample size of input
x, where the first dimension ofxis chain dimension and the second dimension ofxis draw dimension.References:
Introduction to Markov Chain Monte Carlo, Charles J. Geyer
Stan Reference Manual version 2.18, Stan Development Team
- Parameters:
x (numpy.ndarray) – the input array.
bias – whether to use a biased estimator of the autocovariance.
- Returns:
effective sample size of
x.- Return type:
Gelman Rubin
- gelman_rubin(x: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]
Computes R-hat over chains of samples
x, where the first dimension ofxis chain dimension and the second dimension ofxis draw dimension. It is required thatx.shape[0] >= 2andx.shape[1] >= 2.- Parameters:
x (numpy.ndarray) – the input array.
- Returns:
R-hat of
x.- Return type:
Split Gelman Rubin
- split_gelman_rubin(x: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]
Computes split R-hat over chains of samples
x, where the first dimension ofxis chain dimension and the second dimension ofxis draw dimension. It is required thatx.shape[1] >= 4.- Parameters:
x (numpy.ndarray) – the input array.
- Returns:
split R-hat of
x.- Return type:
HPDI
- hpdi(x: ndarray[tuple[Any, ...], dtype[_ScalarT]], prob: float = 0.9, axis: int = 0) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]
Computes “highest posterior density interval” (HPDI) which is the narrowest interval with probability mass
prob.- Parameters:
x (numpy.ndarray) – the input array.
prob (float) – the probability mass of samples within the interval.
axis (int) – the dimension to calculate hpdi.
- Returns:
Array containing the lower and upper bounds of the HPDI along the specified axis. The output has the same shape as
xexcept that the size alongaxisis 2 (lower bound first, upper bound second).- Return type:
Summary
- summary(samples: dict | ndarray, prob: float = 0.9, group_by_chain: bool = True) dict[source]
Returns a summary table displaying diagnostics of
samplesfrom the posterior. The diagnostics displayed are mean, standard deviation, median, the 90% Credibility Intervalhpdi(),effective_sample_size(), andsplit_gelman_rubin().- Parameters:
samples (dict or numpy.ndarray) – a collection of input samples with left most dimension is chain dimension and second to left most dimension is draw dimension.
prob (float) – the probability mass of samples within the HPDI interval.
group_by_chain (bool) – If True, each variable in samples will be treated as having shape num_chains x num_samples x sample_shape. Otherwise, the corresponding shape will be num_samples x sample_shape (i.e. without chain dimension).
- print_summary(samples: dict | ndarray[tuple[Any, ...], dtype[_ScalarT]], prob: float = 0.9, group_by_chain: bool = True) None[source]
Prints a summary table displaying diagnostics of
samplesfrom the posterior. The diagnostics displayed are mean, standard deviation, median, the 90% Credibility Intervalhpdi(),effective_sample_size(), andsplit_gelman_rubin().- Parameters:
samples (dict or numpy.ndarray) – a collection of input samples with left most dimension is chain dimension and second to left most dimension is draw dimension.
prob (float) – the probability mass of samples within the HPDI interval.
group_by_chain (bool) – If True, each variable in samples will be treated as having shape num_chains x num_samples x sample_shape. Otherwise, the corresponding shape will be num_samples x sample_shape (i.e. without chain dimension).