diff --git a/LICENSE b/LICENSE index e8d5947..a4df98f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 DECAR Systems Group +Copyright (c) 2022 DECAR Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/pykoop/koopman_pipeline.py b/pykoop/koopman_pipeline.py index 18f1d8b..80ad541 100644 --- a/pykoop/koopman_pipeline.py +++ b/pykoop/koopman_pipeline.py @@ -2821,7 +2821,9 @@ def make_scorer( an error has occured in estimator fitting. If set to ``'raise'``, a :class:`ValueError` is raised. If a numerical value is given, a :class:`sklearn.exceptions.FitFailedWarning` warning is raised and - the specified score is returned. + the specified score is returned. The error score defines the worst + possible score. If a score is finite but lower than the error + score, the error score will be returned instead. multistep : bool If true, predict using :func:`predict_trajectory`. Otherwise, @@ -3204,7 +3206,9 @@ def score_trajectory( error has occured in estimator fitting. If set to ``'raise'``, a :class:`ValueError` is raised. If a numerical value is given, a :class:`sklearn.exceptions.FitFailedWarning` warning is raised and the - specified score is returned. + specified score is returned. The error score defines the worst possible + score. If a score is finite but lower than the error score, the error + score will be returned instead. min_samples : int Number of samples in initial condition. @@ -3298,6 +3302,13 @@ def score_trajectory( # Invert losses if regression_metric not in greater_is_better: score *= -1 + # If score is worse than error score, return that. + if np.isfinite(error_score) and (score < error_score): + warnings.warn( + f'Score `score={score}` is finite, but is lower than error ' + f'score `error_score={error_score}`. Returning error score.', + sklearn.exceptions.FitFailedWarning) + return error_score return score diff --git a/tests/test_koopman_pipeline.py b/tests/test_koopman_pipeline.py index 2762359..9d8c34a 100644 --- a/tests/test_koopman_pipeline.py +++ b/tests/test_koopman_pipeline.py @@ -560,6 +560,22 @@ class TestKoopmanPipelineScore: False, None, ), + # Finite score worse than error score should return error score. + ( + np.array([ + [1e-2, 1e-3], + ]).T, + np.array([ + [1e5, 1e6], + ]).T, + None, + 1, + 'neg_mean_squared_error', + -100, + 1, + False, + -100, + ), ], ) def test_score_trajectory(