MySQL 26.10.0
Source Code Documentation
fx_holt_winters_state.h
Go to the documentation of this file.
1/* Copyright (c) 2025, 2026, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#pragma once
25
26#include <vector>
27
28#include "fx_stats_util.h"
29
30/**
31 @struct Holt_Winters_State
32 @brief Holt-Winters parameters, fitted state and residual statistics.
33
34 This struct encapsulates the parameters and state variables required by the
35 Holt-Winters algorithm to generate forecasts. The members include:
36 - Smoothing parameters: @ref m, @ref alpha, @ref beta, @ref gamma
37 - Current level and trend: @ref level, @ref trend
38 - Seasonal components: @ref season
39 - Other state variables: @ref last_idx, @ref last_ts, @ref residual_stats
40
41 @note The state variables are updated as new data is processed, allowing the
42 model to adapt to changes in the underlying time series.
43*/
45 // Model params
46 int m{1440}; // seasonal period (e.g., 1440 for daily data)
47 double alpha{0.3}; // smoothing factor for level (0 <= α <= 1)
48 double beta{0.1}; // smoothing factor for trend (0 <= β <= 1)
49 double gamma{0.05}; // smoothing factor for seasonal component (0 <= γ <= 1)
50 double level{0.0}; // current level (baseline value)
51 double trend{0.0}; // current trend (slope), MiB/min
52 // Seasonal component ring buffer, size m, by phase (minute of day)
53 std::vector<double> season;
54
55 // Index of the last processed observation across all batches since model
56 // initialization, used to select the seasonal slot when forecasting.
57 int64_t last_idx{-1};
58 // Timestamp of the last data point
59 int64_t last_ts{0};
60 // Index of the next metric to process, zero-based
61 unsigned int next_metric{0};
62 // Time series resolution (cadence) in seconds
64 // Stats for the confidence interval, or basically what's left after
65 // removing the trend, season and level components, aka 'noise'
67 // True if the model has been initialized
68 bool initialized{false};
69};
Holt-Winters parameters, fitted state and residual statistics.
Definition: fx_holt_winters_state.h:44
double alpha
Definition: fx_holt_winters_state.h:47
double trend
Definition: fx_holt_winters_state.h:51
double level
Definition: fx_holt_winters_state.h:50
int64_t last_ts
Definition: fx_holt_winters_state.h:59
bool initialized
Definition: fx_holt_winters_state.h:68
int m
Definition: fx_holt_winters_state.h:46
int64_t last_idx
Definition: fx_holt_winters_state.h:57
unsigned int next_metric
Definition: fx_holt_winters_state.h:61
int sample_seconds
Definition: fx_holt_winters_state.h:63
Welford_Stats residual_stats
Definition: fx_holt_winters_state.h:66
double gamma
Definition: fx_holt_winters_state.h:49
std::vector< double > season
Definition: fx_holt_winters_state.h:53
double beta
Definition: fx_holt_winters_state.h:48
Maintains running statistics for a stream of values using Welford's online algorithm.
Definition: fx_stats_util.h:100