Skip to content

Commit 8860285

Browse files
Refactor lag handling in arma.py for clarity
1 parent 86c5199 commit 8860285

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/nns/arma.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,20 +768,22 @@ def _numeric_seasonal_weights(
768768
lags: NDArray[np.int64],
769769
) -> NDArray[np.float64]:
770770
output = np.empty(lags.size, dtype=np.float64)
771-
for index in range(lags.size):
772-
# R NNS 13.0 reverses by the candidate's POSITION in seasonal.factor
773-
# (variable[seq(length(variable), 1, -i)]), not by its lag value.
774-
rev_var = variable[:: -(index + 1)]
771+
772+
for index, lag in enumerate(lags):
773+
# Numeric seasonal_factor entries are actual lag values.
774+
rev_var = variable[::-int(lag)]
775775
with np.errstate(invalid="ignore", divide="ignore"):
776776
output[index] = abs(
777777
np.float64(np.std(rev_var, ddof=1)) / np.float64(np.mean(rev_var))
778778
)
779+
779780
with np.errstate(invalid="ignore", divide="ignore"):
780781
baseline_cv = abs(
781782
np.float64(np.std(variable, ddof=1)) / np.float64(np.mean(variable))
782783
)
783784
relative = output / baseline_cv
784785
seasonal_weighting = 1.0 / relative
786+
785787
observation_weighting = 1.0 / np.sqrt(lags.astype(np.float64))
786788
denom = float(np.sum(observation_weighting * seasonal_weighting))
787789
return (seasonal_weighting * observation_weighting) / denom

0 commit comments

Comments
 (0)