peal.visualization.model_comparison.create_comparison

peal.visualization.model_comparison.create_comparison(explainer, dataset, criterions, columns, score_reference_idx, device, max_samples=100000000, checkbox_dict_in=None, batch_size=1)[source]

Pick one sample per criterion combination and explain it with each model.

The dataset is scanned from index 50 onwards; the first sample matching each combination of criterions is kept together with every model’s softmax score for score_reference_idx. Then get_explanation is called per column and the whole thing is rendered as one image.

Parameters:
  • explainer (LRPExplainer or CounterfactualExplainer) – Reused for all columns; its predictor is swapped per column.

  • dataset (peal dataset) – Indexable dataset returning (x, y).

  • criterions (dict) – {name: callable(x, y) -> bool} defining the row buckets.

  • columns (dict) – {column_name: (explanation_type, model, target_key, base_path)}; model is called on x.unsqueeze(0).to(device).

  • score_reference_idx (int) – Class index whose softmax score is reported per row.

  • device (str or torch.device) – Device the models run on.

  • max_samples (int) – Maximum number of dataset indices scanned.

  • checkbox_dict_in (dict, optional) – Explicit {criterion: LongTensor (n_rows,)} rows to look for instead of the full 2 ** n grid; must contain a "class" key.

  • batch_size (int) – Batch size for the counterfactual explainer.

Returns:

The composed comparison image from make_image_grid.

Return type:

torch.Tensor