From 8a697f741c3690858216e4f8f588b22978e77071 Mon Sep 17 00:00:00 2001 From: Ash Vardanian <1983160+ashvardanian@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:18:13 +0000 Subject: [PATCH] Improve: Normalize Pearson as distance --- include/usearch/index_plugins.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/usearch/index_plugins.hpp b/include/usearch/index_plugins.hpp index 25ab8ce4..b3ad5edf 100644 --- a/include/usearch/index_plugins.hpp +++ b/include/usearch/index_plugins.hpp @@ -1204,7 +1204,9 @@ template 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; } };