Skip to content

HyperTreeSTL default forecast fails for short horizons #10

Description

@janrth

Summary

HyperTreeSTL(type="default") fails during forecasting when the forecast horizon is shorter than the learned trend smoothing window / seasonal period. I hit this with fcst_h=3 on a monthly grocery-price example.

Reproduction

Train a default HyperTreeSTL model and forecast with a short horizon, for example:

from hypertrees.models import HyperTreeSTL

fcst_h = 3
model = HyperTreeSTL(period=12, num_seasonal_components=2, freq="M", fcst_h=fcst_h)
model.train(
    lgb_params={"learning_rate": 0.05},
    num_iterations=8,
    train_data=train_one,
    validation=False,
)
model.forecast(test_data=test_one)

where test_one has exactly 3 rows and includes the required series_id, date, time, and feature columns.

Observed behavior

Forecasting raises from the default STL forward pass:

RuntimeError: Forecasting not successful: Argument #4: Padding size should be less than the corresponding input dimension

The immediate source is torch.nn.functional.pad(..., mode="reflect") in _forward_default. With fcst_h=3, the input length is 3 but the smoothing window can produce padding such as (7, 7).

There is also a second short-horizon edge case in seasonal centering: when T < period, the existing reflected tail may not be long enough to pad to a full seasonal cycle before view(C, m, N).

Expected behavior

HyperTreeSTL(type="default") should support short forecast horizons such as fcst_h=3 and fcst_h=1, or fail earlier with a clear validation error. Since the model already accepts any positive fcst_h, handling short horizons seems preferable.

Suggested fix

A local patch fixes this by:

  • capping the default smoothing window by the actual sequence length so reflect padding satisfies pad < T
  • bypassing smoothing for T <= 1
  • repeating reflected seasonal values enough times when padding T < period to a full seasonal cycle
  • adding regression tests for 3-step and 1-step horizons

I can open a PR with that patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions