]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
perf(qav3): improve _get_n_clusters heuristic
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 28 Sep 2025 21:06:41 +0000 (23:06 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 28 Sep 2025 21:06:41 +0000 (23:06 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py

index eb52e4f426ba317e520a860e8b72807c05b455ba..8a4035cade9f90d5bd3378d7e33e8fac48122120 100644 (file)
@@ -861,7 +861,12 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
                 if upper_bound < 2:
                     return 1
                 lower_bound = min(min_n_clusters, upper_bound)
-                n_clusters = int(round(np.log2(max(n_uniques, 2))))
+                n_uniques_bounded = max(n_uniques, 2)
+                n_clusters = int(
+                    round(
+                        (np.log2(n_uniques_bounded) + np.sqrt(n_uniques_bounded)) / 2.0
+                    )
+                )
                 return max(lower_bound, min(n_clusters, upper_bound))
 
             if metric in {