]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
feat(qav3): add a few metrics for trials selection
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 26 May 2025 17:21:58 +0000 (19:21 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 26 May 2025 17:21:58 +0000 (19:21 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py

index 6b2a3947d2ec072fd4b05a7d2b6734749c6a1e70..c7f77ee11f748e45e9e72ea3abc3b92f4b233f78 100644 (file)
@@ -406,7 +406,16 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
         n_objectives = len(study.directions)
 
         label_metric = self.ft_params.get("label_metric", "euclidean")
-        metrics = {"euclidean", "chebyshev", "manhattan", "minkowski"}
+        metrics = {
+            "euclidean",
+            "chebyshev",
+            "manhattan",
+            "minkowski",
+            "canberra",
+            "braycurtis",
+            "hellinger",
+            "geometric_mean",
+        }
         if label_metric not in metrics:
             raise ValueError(
                 f"Unsupported label metric: {label_metric}. Supported metrics are {', '.join(metrics)}"
@@ -451,6 +460,31 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
                     ),
                     1.0 / p_order,
                 )
+            elif metric == "canberra":
+                return np.sum(
+                    np.abs(normalized_matrix - ideal_point)
+                    / (np.abs(normalized_matrix) + np.abs(ideal_point)),
+                    axis=1,
+                )
+            elif metric == "braycurtis":
+                return np.divide(
+                    np.sum(np.abs(normalized_matrix - ideal_point), axis=1),
+                    np.sum(normalized_matrix + ideal_point, axis=1),
+                    out=np.zeros(normalized_matrix.shape[0], dtype=float),
+                    where=(np.sum(normalized_matrix + ideal_point, axis=1) != 0),
+                )
+            elif metric == "hellinger":
+                return np.sqrt(np.sum((np.sqrt(normalized_matrix) - 1.0) ** 2, axis=1))
+            elif metric == "geometric_mean":
+                return (
+                    np.array([])
+                    if normalized_matrix.shape[1] == 0
+                    else 1.0
+                    - (
+                        np.prod(normalized_matrix, axis=1)
+                        ** (1.0 / normalized_matrix.shape[1])
+                    )
+                )
             else:
                 raise ValueError(f"Unsupported distance metric: {metric}")