plot_pairs()

Contents

plot_pairs()#

liesel.goose.plot_pairs(results, params=None, param_indices=None, chain_indices=None, max_chains=5, alpha=0.2, title=None, title_spacing=0.9, style='whitegrid', diag_kind='kde', color_palette=None, height=3, aspect_ratio=1.0, save_path=None, include_warmup=False, show=True, highlight_divergences='auto', divergence_scope='parameter')[source]#

Produces a pairplot panel.

Parameters:
  • results (SamplingResults | Mapping[str, ArrayLike]) – Result object of the sampling process. Must have a method get_posterior_samples() which extracts all samples from the posterior distribution. Alternatively, you can directly supply a dictionary of samples, for example the output of SamplingResults.get_posterior_samples.

  • params (str | list[str] | None, default: None) – Names of the model parameters that are contained in the plot. Must coincide with the dictionary keys of the Position with the posterior samples. If None, all parameters are included.

  • param_indices (int | Sequence[int] | None, default: None) – Indices of each model parameter that are contained in the plot. Selects e.g. beta[0] out of a beta parameter vector. A single index can be specified as an integer or a sequence containing one integer. If None, all subparameters are included.

  • chain_indices (int | Sequence[int] | None, default: None) – Indices of chains for each model subparameter that are contained in the plot. Selects e.g. chain 0 and chain 2 out of multiple chains. A single index can be specified as an integer or a sequence containing one integer. If None, all chains are included.

  • max_chains (int | None, default: 5) – Upper bound how many chains are included within each subplot/facet. Avoids overplotting. If None, all chains contained in the results input are plotted. Always starts chain selection from the lowest chain index upwards. For selecting specific chains use the argument chain_indices.

  • alpha (float, default: 0.2) – Amount of transparency; a float between 0 and 1.

  • title (str | None, default: None) – Plot title.

  • title_spacing (float, default: 0.9) – Determines the margin/whitespace between the plot title (set with fig.suptitle()) and the first row of subplots/facets. Passed to the top argument of fig.subplots_adjust().

  • style (str, default: 'whitegrid') – Passed to the style argument of sns.set_theme(). Valid options are darkgrid, whitegrid, dark, white, and ticks.

  • diag_kind (str, default: 'kde') – Kind of plot for the diagonal subplots. Can be ‘kde’ (default) for kernel density estimates or ‘hist’ for histograms.

  • color_palette (str | list[str] | Mapping[int, str] | None, default: None) – Passed to the palette argument of sns.pairplot(). String values must be valid inputs of sns.color_palette() such as a seaborn color palette or a matplotlib colormap. Custom colors can be set with a list of color strings or a dictionary with the chain indices as keys and color strings as values. The number of color strings must coincide with the number of plotted chains. If None, the default tab10 matplotlib colormap is chosen.

  • height (float, default: 3) – Height in inches of each subplot/facet within the grid.

  • aspect_ratio (float, default: 1.0) – Ratio of width / height of each subplot/facet within the grid, i.e. width = aspect_ratio * height.

  • legend_position – Determines the color legend position. Coordinates are relative to the upper panel within the plot grid. The first coordinate specifies the horizontal, the second coordinate the vertical position. Might require an adjustment when changing the figure_size values or the number of chains.

  • save_path (str | None, default: None) – File path where the plot is saved.

  • include_warmup (bool, default: False) – Include warmup samples and initial values. Initial values have no transition diagnostic and are never highlighted.

  • show (bool, default: True) – Display the plot. Set to False to save or inspect the figure without displaying it.

  • highlight_divergences (bool | Literal['auto'], default: 'auto') – With "auto" (default), highlight when usable diagnostics are available. Raw sample dictionaries and results known to have no HMC/NUTS kernels plot without markers. Missing, incomplete, or misaligned diagnostics, including a missing required kernel mapping, emit a warning and disable highlighting. Set True to require highlighting and raise on unusable diagnostics; set False to disable highlighting and skip diagnostic checks. Highlight draws associated with divergent HMC or NUTS transitions. Requires SamplingResults. Includes NUTS transitions that also reached maximum tree depth. Scatter panels show opaque red crosses; each affected diagonal shows one red rug combining divergent draws across chains. Histograms and densities still use all retained draws and preserve chain colors. The rug also works for a single parameter. One shared “Divergent” legend entry is added only when at least one displayed panel has marked draws. Diagnostics respect thinning: discarded iterations are not displayed. Markers identify stored draws after the full kernel sequence, not intermediate locations along divergent trajectories.

  • divergence_scope (Literal['parameter', 'any'], default: 'parameter') – Used when highlighting is enabled ("auto" or True). With "parameter" (default), each diagonal marks divergences from the kernel updating that parameter; off-diagonal panels mark a draw if a kernel updating either parameter diverged. Requires SamplingResults.kernels_by_pos_key; unmapped parameters and parameters updated by other kernel types contribute no divergence flags. Components of a jointly updated vector share the kernel’s flags. With "any", every panel uses divergences from all HMC/NUTS kernels, including kernels updating unplotted parameters. This scope does not require the mapping.

Raises:
  • TypeError – If highlight_divergences=True is used with a raw sample dictionary.

  • ValueError – If highlight_divergences is invalid, or highlighting is enabled and divergence_scope is invalid. Also raised in strict mode (True) for unusable diagnostics or a missing required kernel mapping.

Warns:

UserWarning – In automatic mode, if highlighting is skipped because diagnostics or a required kernel mapping are unavailable or inconsistent.