Principle:Dotnet Machinelearning SSA Model Fitting
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Time Series, .NET |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
SSA model fitting constructs the trajectory matrix from training data, performs SVD to extract principal components, and builds the recurrence model used for extrapolation. The resulting model is stateful, maintaining an internal buffer that can be updated with new observations.
Description
Fitting an SSA forecasting model transforms a configured estimator and a training dataset into a trained transformer capable of producing forecasts. The fitting process involves several computational stages:
1. Trajectory matrix construction: The training data (the first trainSize observations from the input column) is organized into an L x K trajectory matrix, where L is the window size and K = trainSize - L + 1. Each column of this matrix is a lagged copy of the series.
2. SVD decomposition: Singular Value Decomposition is applied to the trajectory matrix to identify the principal components. The singular values quantify the variance captured by each component. Components with large singular values correspond to dominant patterns (trend, seasonality), while components with small singular values correspond to noise.
3. Rank selection and component grouping: Based on the configured rank selection method, a subset of r singular components is retained. These components define the signal subspace. The remaining components are discarded as noise.
4. Recurrence model construction: The retained left singular vectors are used to derive the linear recurrence coefficients that enable extrapolation. These coefficients define how future values are computed as a weighted sum of past values.
The fitted model — SsaForecastingTransformer — is stateful. It implements IStatefulTransformer and wraps an AdaptiveSingularSpectrumSequenceModelerInternal that maintains:
- The current series buffer (last N observations)
- The SVD decomposition results
- The recurrence coefficients
- The adaptive state (if adaptive mode is enabled)
This statefulness is what distinguishes time series transformers from standard ML.NET transformers: processing new data changes the model's internal state, affecting subsequent predictions.
Usage
Call .Fit(dataView) on a configured SsaForecastingEstimator to produce the transformer. The input IDataView must contain the column named in the estimator's inputColumnName with data type Single (float). The first trainSize rows of this column are used for fitting. After fitting, the transformer can be used to create a TimeSeriesPredictionEngine for making forecasts.
Theoretical Basis
The fitting process implements the embedding and decomposition stages of the SSA algorithm:
Embedding: The univariate series {x_t} is mapped to a multivariate representation via the trajectory matrix:
Embed: R^N -> R^(L x K)
T(x) = | x(1) x(2) ... x(K) |
| x(2) x(3) ... x(K+1) |
| ... ... ... ... |
| x(L) x(L+1) ... x(N) |
Decomposition: SVD factorizes the trajectory matrix:
T(x) = Σ_{i=1}^{d} σ_i * u_i * v_i^T
where d = rank(T(x)) <= min(L, K)
Rank selection (signal-noise separation): For rank r:
Signal subspace: span{u_1, u_2, ..., u_r}
Noise subspace: span{u_{r+1}, ..., u_d}
Variance explained by signal = Σ_{i=1}^{r} σ_i^2 / Σ_{i=1}^{d} σ_i^2
Recurrence coefficient derivation: The linear recurrence relation for forecasting uses the last element of each retained left singular vector:
Let π_i = u_i[L] (last element of i-th left singular vector)
Let v^2 = Σ_{i=1}^{r} π_i^2
Recurrence vector R = (1/(1 - v^2)) * Σ_{i=1}^{r} π_i * u_i[1:L-1]
Forecast: x_hat(n) = R^T * [x(n-1), x(n-2), ..., x(n-L+1)]
The condition v^2 < 1 (guaranteed when not all signal is in the last coordinate) ensures the recurrence is well-defined.