superstats.diagnostics.plots.posterior_samples#
Posterior sample visualization helpers.
Functions
|
Plot time-invariant parameter posteriors. |
|
Plot time-varying parameter posteriors. |
- superstats.diagnostics.plots.posterior_samples.plot_time_invariant_posterior(estimates, targets=None, variable_keys=None, variable_names=None, aggregation=None, mixture_names=None, num_cols=2, color='#356673', title_fontsize=22, label_fontsize=18, tick_fontsize=16, figsize=None)[source]#
Plot time-invariant parameter posteriors.
- Parameters:
- estimates
Mapping[str,np.ndarray]ornp.ndarray Posterior samples. If a dict, values of shape (num_datasets, num_post_samples, num_steps, num_components), keyed by variable. If an array, shape (num_datasets, num_post_samples, num_steps, num_params) directly - treated as single-component parameters; mixture grouping is not inferable from array input.
- targets
Mapping[str,np.ndarray],np.ndarray,orNone,optional, default:None Ground-truth values, matching the input type of estimates. If a dict, values of shape (num_datasets, num_components). If an array, shape (num_datasets, num_params) directly. If given, drawn as black dashed vertical lines. When aggregation is None, one solid line per panel marks that panel’s specific dataset’s true value. When aggregation is given, the per-dataset true values are collapsed with aggregation and a single solid line is drawn per panel.
- variable_keyssequence
ofstrorNone,optional, default:None Which variables to select and plot, and in what order, when estimates is a dict. By default, all keys, in dict insertion order. Ignored for array input.
- variable_namessequence
ofstrorNone,optional, default:None Display names (used for panel labels/titles), in the same order as variable_keys (or the array’s last axis). Defaults to variable_keys for dict input, or param_0, param_1, … for array input.
- aggregation
callable()orNone,optional, default:None Controls both the posterior layout and the target summary. If None: one panel per (dataset, parameter) pair; rows=params, cols=datasets, param name as row label, dataset index as column title; targets (if given) are shown per dataset. If a callable (e.g. np.mean, np.median): posterior samples are pooled across datasets into one panel per parameter, arranged in a num_cols-column grid; targets (if given) are collapsed across datasets with aggregation into a single reference value per panel.
- mixture_names
dictorNone,optional, default:None Mapping from base parameter name (e.g. “a”, without any “_mixture_weights” suffix) to a list of component names. Defaults to “component 0”, “component 1”, … when not supplied. Only applies to dict input with multi-component values.
- num_cols
int,optional, default: 2 Number of subplot columns when aggregation is not None.
- color
str,optional, default:BASE_COLOR Base color for non-mixture parameters.
- title_fontsize
int,optional, default: 22 The font size of the panel titles.
- label_fontsize
int,optional, default: 18 The font size of the row labels (param names, non-pooled layout only).
- tick_fontsize
int,optional, default: 16 The font size of the axis tick labels.
- figsize
tupleoftwofloatsorNone,optional, default:None Explicit figure size in inches. If None, the default layout size is used.
- estimates
- Returns:
- fig
plt.Figure-thefigureinstanceforoptionalsaving
- fig
- Raises:
ValueErrorIf no variables are found to plot (empty variable_keys, whether resolved by default or passed explicitly), or if variable_names doesn’t match the number of variables for array input.
- Parameters:
- Return type:
Figure
- superstats.diagnostics.plots.posterior_samples.plot_time_varying_posterior(estimates, targets=None, variable_keys=None, variable_names=None, aggregation=None, aggregate_strategy='full_uncertainty', uncertainty_fun='95ci', smoothing=None, smoothing_window=5, marginal=True, num_cols=2, alpha=0.5, color='#356673', title_fontsize=22, label_fontsize=18, tick_fontsize=16, figsize=None)[source]#
Plot time-varying parameter posteriors.
- Parameters:
- estimates
Mapping[str,np.ndarray]ornp.ndarray Posterior samples. If a dict, values of shape (num_datasets, num_post_samples, num_steps, 1), keyed by variable. If an array, shape (num_datasets, num_post_samples, num_steps, num_params) directly.
- targets
Mapping[str,np.ndarray],np.ndarray,orNone,optional, default:None Ground-truth trajectories, matching the input type of estimates. If a dict, values of shape (num_datasets, num_steps, 1). If an array, shape (num_datasets, num_steps, num_params) directly. If given, drawn as a black dashed line on top of each panel: the raw per-dataset trajectory when aggregation is None, or aggregated across datasets (using aggregation) when aggregation is not None. Smoothed with the same smoothing settings as the posterior trajectories, for a fair visual comparison.
- variable_keyssequence
ofstrorNone,optional, default:None Which variables to select and plot, and in what order, when estimates/targets are dicts. By default, all keys, in dict insertion order. Ignored for array input.
- variable_namessequence
ofstrorNone,optional, default:None Display names (used for panel labels/titles), in the same order as variable_keys (or the array’s last axis). Defaults to variable_keys for dict input, or param_0, param_1, … for array input.
- aggregation
callable()orNone,optional, default:None None: one panel per (param, dataset). callable: one panel per param, aggregated across datasets. Called as aggregation(trajectories, axis=0) and must return a (T,) center. The same function aggregates targets across datasets when both targets and aggregation are given.
- aggregate_strategy{“full_uncertainty”, “no_epistemic”},
optional, default: “full_uncertainty” Only used when aggregation is not None. “full_uncertainty”: flatten datasets and posterior samples, then summarize. “no_epistemic”: median across posterior samples per dataset first, then aggregate.
- uncertainty_fun{“std”, “95ci”, “mad”, “95hdi”}
orcallable()orNone,optional, default: “95ci” Band drawn around the center line. A callable receives (N, T) trajectories and must return (lo, hi), each of shape (T,).
- smoothing{“sma”, “ema”}
orNone,optional, default:None Applied to each trajectory (and to targets, if given) before computing the center, uncertainty, and marginal.
- smoothing_window
int,optional, default: 5 Window size for sma, or span parameter for ema.
- marginalbool,
optional, default:True Attach a marginal KDE panel to the right of each trajectory axis. The KDE is computed on the same array used for the uncertainty band.
- num_cols
int,optional, default: 2 Number of subplot columns when aggregation is not None.
- color
str,optional, default:BASE_COLOR Line and band color.
- alpha
floatin[0, 1],optional, default: 0.5 Alpha for the uncertainty band.
- title_fontsize
int,optional, default: 22 The font size of the panel titles.
- label_fontsize
int,optional, default: 18 The font size of the axis label texts.
- tick_fontsize
int,optional, default: 16 The font size of the axis tick labels.
- figsize
tupleoftwofloatsorNone,optional, default:None Explicit figure size in inches. If None, the default layout size is used.
- estimates
- Returns:
- fig
plt.Figure-thefigureinstanceforoptionalsaving
- fig
- Raises:
ValueErrorIf estimates/targets are inconsistent (mismatched dict keys, or a variable_names length mismatch for array input), or if aggregate_strategy, or uncertainty_fun when given as a string, is not one of the recognized values.
- Parameters:
aggregation (Callable | None)
aggregate_strategy (Literal['full_uncertainty', 'no_epistemic'])
uncertainty_fun (Literal['std', '95ci', 'mad', '95hdi'] | ~collections.abc.Callable | None)
smoothing (Literal['sma', 'ema'] | None)
smoothing_window (int)
marginal (bool)
num_cols (int)
alpha (float)
color (str)
title_fontsize (int)
label_fontsize (int)
tick_fontsize (int)
- Return type:
Figure