Problems
Loading...
1 / 1

Double Exponential Smoothing

Time Series
Medium

Double exponential smoothing (Holt's linear trend method) extends simple exponential smoothing by adding a second component to track the trend. Simple exponential smoothing (EMA) lags behind data with a trend because it only models the level. Holt's method maintains separate estimates for level and trend, allowing it to follow trending data much more closely.

Given a time series and smoothing parameters alpha (level) and beta (trend), compute the smoothed level at each time step.

Algorithm

Initialize: level_0 = series[0], trend_0 = series[1] - series[0]. Then for each t >= 1:

lt=αyt+(1α)(lt1+bt1)bt=β(ltlt1)+(1β)bt1l_t = \alpha \cdot y_t + (1 - \alpha)(l_{t-1} + b_{t-1}) \\ b_t = \beta (l_t - l_{t-1}) + (1 - \beta) b_{t-1}

Return the level values [l_0, l_1, ..., l_{n-1}].

Loading visualization...

Examples

Input:

series = [10, 20, 30], alpha = 0.5, beta = 0.5

Output:

[10.0, 20.0, 30.0]

The series has a perfect linear trend. With alpha=beta=0.5, the method tracks it exactly: l_1 = 0.520 + 0.5(10+10) = 20, l_2 = 0.530 + 0.5(20+10) = 30.

Input:

series = [5, 5, 5, 5], alpha = 0.9, beta = 0.1

Output:

[5.0, 5.0, 5.0, 5.0]

Constant series: initial trend is 0 and stays 0. Level stays at 5.0 regardless of alpha and beta.

Hint 1

Start with level = series[0] and trend = series[1] - series[0]. Store level in the result. Then loop from t=1: compute new_level, new_trend, update variables, and append new_level to the result.

Hint 2

The level update uses (level + trend) as the predicted value, blended with the actual observation. The trend update blends the observed trend change (new_level - old_level) with the previous trend.

Requirements

  • Initialize level as the first value and trend as series[1] - series[0]
  • Update level using both the observation and the previous level + trend
  • Update trend using the change in level
  • Return a list of level values with the same length as the input

Constraints

  • series has at least 2 elements
  • 0 < alpha <= 1, 0 < beta <= 1
  • Return a list of floats with the same length as the input
  • Time limit: 300 ms
Try Similar Problems