braindecode.visualization.compute_ssim_metrics#

braindecode.visualization.compute_ssim_metrics(explanations, reference, chs_info=None, abs_reference=True, abs_explanation=False, prctile_val=95, win_size=7)[source]#

Compute four SSIM-based attribution-quality metrics.

Companion to compute_metrics(). Returned column order matches SSIM_METRIC_NAMES:

  1. SSIM_topperc : SSIM between top-percentile masks (each kept at its own scale).

  2. SSIM_absnorm : SSIM between min-max-normalized |explanation| and reference.

  3. SSIM_norm : SSIM between min-max-normalized raw explanation and reference.

  4. SSIM_raw : SSIM between raw explanation and normalized reference.

No extra dependencies; SSIM is computed with a pure-PyTorch implementation.

Parameters:
  • explanations (numpy.ndarray) – Same shape (n_samples, n_chans, n_times). When chs_info is given, each sample is time-averaged and projected to a 2-D topomap before SSIM, matching compute_metrics()’ topographic mode.

  • reference (numpy.ndarray) – Same shape (n_samples, n_chans, n_times). When chs_info is given, each sample is time-averaged and projected to a 2-D topomap before SSIM, matching compute_metrics()’ topographic mode.

  • chs_info (list of dict, optional) – Channel info; enables topographic projection.

  • abs_reference (bool) – Same semantics as in compute_metrics().

  • abs_explanation (bool) – Same semantics as in compute_metrics().

  • prctile_val (float) – Top-percentile threshold for the SSIM_topperc mask.

  • win_size (int) – SSIM sliding-window size. 7 matches the benchmark in Sujatha Ravindran & Contreras-Vidal (2023).

Returns:

  • scores (numpy.ndarray of shape (n_samples, 4)) – SSIM values per sample. Skipped samples have an all-zero row.

  • n_skipped (int) – Number of samples skipped due to all-zero or constant attributions or reference.

Examples using braindecode.visualization.compute_ssim_metrics#

Interpretability of EEG Decoders

Interpretability of EEG Decoders