From 77910c714b04edc861b41bd401a14fcd975334e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 25 Dec 2025 20:39:03 +0100 Subject: [PATCH] refactor(quickadapter): improve outlier detection fitting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../tests/api/test_api_helpers.py | 2 +- .../freqaimodels/QuickAdapterRegressorV3.py | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ReforceXY/reward_space_analysis/tests/api/test_api_helpers.py b/ReforceXY/reward_space_analysis/tests/api/test_api_helpers.py index 4c6ba58..d07eaac 100644 --- a/ReforceXY/reward_space_analysis/tests/api/test_api_helpers.py +++ b/ReforceXY/reward_space_analysis/tests/api/test_api_helpers.py @@ -299,7 +299,7 @@ class TestAPIAndHelpers(RewardSpaceTestBase): "test_output", ] ) - self.assertEqual(args.num_samples, 100) + self.assertEqual(args.num_samples, SCENARIOS.SAMPLE_SIZE_SMALL) self.assertEqual(str(args.out_dir), "test_output") def test_complete_statistical_analysis_writer(self): diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index 3ee3016..462c391 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -311,8 +311,10 @@ class QuickAdapterRegressorV3(BaseRegressionModel): "threshold_outlier", QuickAdapterRegressorV3.PREDICTIONS_EXTREMA_THRESHOLD_OUTLIER_DEFAULT, ) - if not isinstance(threshold_outlier, (int, float)) or not ( - 0 < threshold_outlier < 1 + if ( + not isinstance(threshold_outlier, (int, float)) + or not np.isfinite(threshold_outlier) + or not (0 < threshold_outlier < 1) ): threshold_outlier = ( QuickAdapterRegressorV3.PREDICTIONS_EXTREMA_THRESHOLD_OUTLIER_DEFAULT @@ -345,7 +347,11 @@ class QuickAdapterRegressorV3(BaseRegressionModel): "thresholds_alpha", QuickAdapterRegressorV3.PREDICTIONS_EXTREMA_THRESHOLDS_ALPHA_DEFAULT, ) - if not isinstance(thresholds_alpha, (int, float)) or thresholds_alpha < 0: + if ( + not isinstance(thresholds_alpha, (int, float)) + or not np.isfinite(thresholds_alpha) + or thresholds_alpha < 0 + ): thresholds_alpha = ( QuickAdapterRegressorV3.PREDICTIONS_EXTREMA_THRESHOLDS_ALPHA_DEFAULT ) @@ -1147,13 +1153,13 @@ class QuickAdapterRegressorV3(BaseRegressionModel): di_values = pred_df.get("DI_values") - # fit the DI_threshold + # Fit DI_value cutoff if not warmed_up: - f = [0, 0, 0] - cutoff = 2 + f = [0.0, 0.0, 0.0] + cutoff = 2.0 else: f = sp.stats.weibull_min.fit( - pd.to_numeric(di_values, errors="coerce").dropna() + pd.to_numeric(di_values, errors="coerce").dropna(), floc=0 ) cutoff = sp.stats.weibull_min.ppf( self.predictions_extrema["threshold_outlier"], *f -- 2.53.0