peal.data.custom_datasets.plot_latents_with_arrows

peal.data.custom_datasets.plot_latents_with_arrows(original_latents, counterfactual_latents, filename, y_target_start_confidence, y_target_end_confidence, decision_boundary, extent=[0, 1, 0, 1], xlabel='Foreground Intensity', ylabel='Background Intensity', attempts=1)[source]

Scatter factual and counterfactual 2D latents and connect them by arrows.

One subplot per counterfactual attempt: the decision boundary grid is drawn as a semi-transparent bwr background, originals are circles and counterfactuals squares (both filled by the target-class confidence), and a green arrow points from each original to its counterfactual. The figure is written to filename and closed. Called by ImageDataset.global_counterfactual_visualization.

Parameters:
  • original_latents (array_like) – [N, 2] latent coordinates. The attempts are consecutive blocks of N // attempts entries.

  • counterfactual_latents (array_like) – [N, 2] latent coordinates. The attempts are consecutive blocks of N // attempts entries.

  • filename (str) – Output image path.

  • y_target_start_confidence (array_like) – Target-class confidence before and after the edit, used as the colormap value of the two markers.

  • y_target_end_confidence (array_like) – Target-class confidence before and after the edit, used as the colormap value of the two markers.

  • decision_boundary (numpy.ndarray) – Probability grid shown as the background image.

  • extent (list of float, optional) – [xmin, xmax, ymin, ymax] of both the background and the axes.

  • xlabel (str, optional) – Axis labels. "Foreground Intensity" additionally draws the 0.5 guide lines of the square dataset.

  • ylabel (str, optional) – Axis labels. "Foreground Intensity" additionally draws the 0.5 guide lines of the square dataset.

  • attempts (int, optional) – Number of subplots the latents are split into.