Skip to content

Commit

Permalink
Improve: Normalize Pearson as distance
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Mar 31, 2024
1 parent 4b8e1a8 commit 8a697f7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/usearch/index_plugins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,9 @@ template <typename scalar_at = float, typename result_at = float> struct metric_
return 0;
result_t corr = dim * ab_sum - a_sum * b_sum;
denom = std::sqrt(denom);
return -corr / denom;
// The normal Pearson correlation value is between -1 and 1, but we are looking for a distance.
// So instead of returning `corr / denom`, we return `1 - corr / denom`.
return 1 - corr / denom;
}
};

Expand Down

0 comments on commit 8a697f7

Please sign in to comment.