Skip to content

Commit

Permalink
fix the issue with distance.py for plotting the pairwise matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
edyoshikun committed Feb 4, 2025
1 parent 6f91a1a commit a8b66cd
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions viscy/representation/evaluation/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ def compute_embedding_distances(
prediction_path: Path,
output_path: Path,
distance_metric: Literal["cosine", "euclidean", "normalized_euclidean"] = "cosine",
verbose: bool = False,
) -> pd.DataFrame:
"""
Compute and save pairwise distances between embeddings.
Expand All @@ -318,8 +317,6 @@ def compute_embedding_distances(
name of saved CSV file
distance_metric : str, optional
Distance metric to use for computing distances between embeddings
verbose : bool, optional
If True, plots the distance matrix visualization
Returns
-------
Expand All @@ -340,15 +337,15 @@ def compute_embedding_distances(
if distance_metric == "euclidean":
cross_dist /= np.sqrt(features.shape[1])

if verbose:
# Plot the distance matrix
plt.figure(figsize=(10, 10))
plt.imshow(cross_dist, cmap="viridis")
plt.colorbar(label=f"{distance_metric.capitalize()} Distance")
plt.title(f"{distance_metric.capitalize()} Distance Matrix")
plt.tight_layout()
plt.show()

# Plot the distance matrix
plt.figure(figsize=(10, 10))
plt.imshow(cross_dist, cmap="viridis")
plt.colorbar(label=f"{distance_metric.capitalize()} Distance")
plt.title(f"{distance_metric.capitalize()} Distance Matrix")
plt.tight_layout()
base_name = prediction_path.stem
plt.savefig(output_path / f"{base_name}_distance_matrix.png", dpi=600)
plt.close()
rank_fractions = rank_nearest_neighbors(cross_dist, normalize=True)

# Compute piece-wise dissimilarity and rank difference
Expand Down

0 comments on commit a8b66cd

Please sign in to comment.