diff --git a/darts/models/forecasting/arima.py b/darts/models/forecasting/arima.py index 675ad11cff..686ac55b13 100644 --- a/darts/models/forecasting/arima.py +++ b/darts/models/forecasting/arima.py @@ -32,7 +32,7 @@ def __init__( q: int = 0, seasonal_order: Tuple[int, int, int, int] = (0, 0, 0, 0), trend: Optional[str] = None, - random_state: int = 0, + random_state: Optional[int] = None, add_encoders: Optional[dict] = None, ): """ARIMA @@ -81,7 +81,11 @@ def __init__( self.seasonal_order = seasonal_order self.trend = trend self.model = None - np.random.seed(random_state) + self._random_state = ( + random_state + if random_state is None + else np.random.RandomState(random_state) + ) def _fit(self, series: TimeSeries, future_covariates: Optional[TimeSeries] = None): super()._fit(series, future_covariates) @@ -144,6 +148,7 @@ def _predict( nsimulations=n, repetitions=num_samples, initial_state=self.model.states.predicted[-1, :], + random_state=self._random_state, exog=future_covariates.values(copy=False) if future_covariates else None, diff --git a/darts/tests/models/forecasting/test_local_forecasting_models.py b/darts/tests/models/forecasting/test_local_forecasting_models.py index 8191205f52..f1361d1f98 100644 --- a/darts/tests/models/forecasting/test_local_forecasting_models.py +++ b/darts/tests/models/forecasting/test_local_forecasting_models.py @@ -616,7 +616,7 @@ def test_model_repr_call(self): ), # no params changed ( ARIMA(1, 1, 1), - "ARIMA(p=1, d=1, q=1, seasonal_order=(0, 0, 0, 0), trend=None, random_state=0, add_encoders=None)", + "ARIMA(p=1, d=1, q=1, seasonal_order=(0, 0, 0, 0), trend=None, random_state=None, add_encoders=None)", ), # default value for a param ] for model, expected in model_expected_name_pairs: diff --git a/darts/tests/models/forecasting/test_probabilistic_models.py b/darts/tests/models/forecasting/test_probabilistic_models.py index 08d7a49712..9fb53345a2 100644 --- a/darts/tests/models/forecasting/test_probabilistic_models.py +++ b/darts/tests/models/forecasting/test_probabilistic_models.py @@ -48,7 +48,7 @@ models_cls_kwargs_errs = [ (ExponentialSmoothing, {}, 0.3), - (ARIMA, {"p": 1, "d": 0, "q": 1}, 0.03), + (ARIMA, {"p": 1, "d": 0, "q": 1, "random_state": 42}, 0.03), ] models_cls_kwargs_errs += [ @@ -150,7 +150,6 @@ class ProbabilisticTorchModelsTestCase(DartsBaseTestClass): def test_fit_predict_determinism(self): for model_cls, model_kwargs, _ in models_cls_kwargs_errs: - # whether the first predictions of two models initiated with the same random state are the same model = model_cls(**model_kwargs) model.fit(self.constant_noisy_ts) diff --git a/requirements/core.txt b/requirements/core.txt index 7437f5dbba..17fd72b69c 100644 --- a/requirements/core.txt +++ b/requirements/core.txt @@ -4,7 +4,7 @@ joblib>=0.16.0 lightgbm>=3.2.0 matplotlib>=3.3.0 nfoursid>=1.0.0 -numpy>=1.19.0 +numpy>=1.19.0,<1.24.0 pandas>=1.0.5 pmdarima>=1.8.0 prophet>=1.1.1