pairs_quantity#

bayesflow.diagnostics.pairs_quantity(values: Mapping[str, ndarray] | ndarray | Callable, targets: Mapping[str, ndarray] | ndarray, *, variable_keys: Sequence[str] = None, variable_names: Sequence[str] = None, estimates: Mapping[str, ndarray] | ndarray | None = None, test_quantities: dict[str, Callable] = None, height: float = 2.5, cmap: str | Colormap = 'viridis', alpha: float = 0.9, markersize: float = 8.0, marker: str = 'o', label: str = None, label_fontsize: int = 14, tick_fontsize: int = 12, colorbar_label_fontsize: int = 14, colorbar_tick_fontsize: int = 12, colorbar_width: float = 1.8, colorbar_height: float = 0.06, colorbar_offset: float = 0.06, vmin: float = None, vmax: float = None, default_name: str = 'v', **kwargs) PairGrid[source]#

A pair plot function to plot quantities against their generating parameter values.

The value is indicated by a colormap. The marginal distribution for each parameter is plotted on the diagonal. Each column displays the values of corresponding to the parameter in the column.

The function supports the following different combinations to pass or compute the values:

  1. pass values as an array of shape (num_datasets,) or (num_datasets, num_variables)

  2. pass values as a dictionary with the keys ‘values’, ‘metric_name’ and ‘variable_names’ as provided by the metrics functions. Note that the functions have to be called without aggregation to obtain value per dataset.

  3. pass a function to values, as well as estimates. The function should have the signature fn(estimates, targets, [aggregation]) and return an object like the values described in the previous options.

Parameters:
valuesdict[str, np.ndarray] | np.ndarray | Callable,

The value of the quantity to plot. One of the following:

  1. an array of shape (num_datasets,) or (num_datasets, num_variables)

  2. a dictionary with the keys ‘values’, ‘metric_name’ and ‘variable_names’ as provided by the metrics functions. Note that the functions have to be called without aggregation to obtain value per dataset.

  3. a callable, requires passing estimates as well. The function should have the signature fn(estimates, targets, [aggregation]) and return an object like the ones described in the previous options.

targetsdict[str, np.ndarray] | np.ndarray,

The parameter values plotted on the axis.

variable_keyslist or None, optional, default: None

Select keys from the dictionary provided in samples. By default, select all keys.

variable_nameslist or None, optional, default: None

The parameter names for nice plot titles. Inferred if None

estimatesnp.ndarray of shape (n_data_sets, n_post_draws, n_params), optional, default: None

The posterior draws obtained from n_data_sets. Can only be supplied if values is of type Callable.

test_quantitiesdict or None, optional, default: None

A dict that maps plot titles to functions that compute test quantities based on estimate/target draws. Can only be supplied if values is a function.

The dict keys are automatically added to variable_keys and variable_names. Test quantity functions are expected to accept a dict of draws with shape (batch_size, ...) as the first (typically only) positional argument and return an NumPy array of shape (batch_size,). The functions do not have to deal with an additional sample dimension, as appropriate reshaping is done internally.

heightfloat, optional, default: 2.5

The height of the pair plot

cmapstr or Colormap, default: “viridis”

The colormap for the plot.

alphafloat in [0, 1], optional, default: 0.9

The opacity of the plot

markersizefloat, optional, default: 8.0

The marker size in points**2 for the scatter plot.

markerstr, optional, default: ‘o’

The marker for the scatter plot.

labelstr, optional, default: None

Label for the dataset to plot.

label_fontsizeint, optional, default: 14

The font size of the x and y-label texts (parameter names)

tick_fontsizeint, optional, default: 12

The font size of the axis tick labels

colorbar_label_fontsizeint, optional, default: 14

The font size of the colorbar label

colorbar_tick_fontsizeint, optional, default: 12

The font size of the colorbar tick labels

colorbar_widthfloat, optional, default: 1.8

The width of the colorbar in inches

colorbar_heightfloat, optional, default: 0.06

The height of the colorbar in inches

colorbar_offsetfloat, optional, default: 0.06

The vertical offset of the colorbar in inches

vminfloat, optional, default: None

Minimum value for the colormap. If None, the minimum value is determined from values.

vmaxfloat, optional, default: None

Maximum value for the colormap. If None, the maximum value is determined from values.

default_namestr, optional (default = “v”)

The default name to use for estimates if None provided

**kwargsdict, optional

Additional keyword arguments passed to the sns.PairGrid constructor

Returns:
plt.Figure

The figure instance

Raises:
ValueError

If a callable is supplied as values, but estimates is None.