Skip to content

Commit a7a1011

Browse files
committed
[BUG] Guard ETS against invalid multiplicative input and instability
1 parent ff28266 commit a7a1011

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

aeon/forecasting/stats/_ets.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,29 @@ def _get_int(x):
178178
dtype=np.int32,
179179
)
180180
data = y.squeeze()
181-
(self.parameters_, self.aic_) = nelder_mead(
182-
1,
183-
1 + 2 * (self._trend_type != 0) + (self._seasonality_type != 0),
184-
data,
185-
self._model,
186-
max_iter=self.iterations,
187-
)
181+
if (
182+
self._error_type == 2
183+
or self._trend_type == 2
184+
or self._seasonality_type == 2
185+
):
186+
if np.any(~np.isfinite(data)) or np.any(data <= 0):
187+
raise ValueError(
188+
"Multiplicative ETS models require strictly positive data."
189+
)
190+
try:
191+
(self.parameters_, self.aic_) = nelder_mead(
192+
1,
193+
1 + 2 * (self._trend_type != 0) + (self._seasonality_type != 0),
194+
data,
195+
self._model,
196+
max_iter=self.iterations,
197+
)
198+
except ZeroDivisionError as exc:
199+
raise ValueError(
200+
"ETS optimisation failed due to numerical instability. "
201+
"This may occur when multiplicative ETS produces "
202+
"invalid (non-positive or infinite) forecasts."
203+
) from exc
188204
self.alpha_, self.beta_, self.gamma_, self.phi_ = _extract_ets_params(
189205
self.parameters_, self._model
190206
)

0 commit comments

Comments
 (0)