TimeSeriesModelBase<T>
Base Classes · AiDotNet.TimeSeries
Provides a base class for all time series forecasting models in the library.
Implements: IModelShape, IParameterChunkSource<T>, IParameterManifestProvider, ITimeSeriesModel<T>, ITrainingEpochReporter<T>
Known derived types: ARIMAModel<T>, ARIMAXModel<T>, ARMAModel<T>, ARModel<T>, AutoformerModel<T>, BayesianStructuralTimeSeriesModel<T>, ChronosFoundationModel<T>, DLinearModel<T>, DeepANT<T>, DeepARModel<T>, DynamicRegressionWithARIMAErrors<T>, ExponentialSmoothingModel<T>, GARCHModel<T>, InformerModel<T>, InterventionAnalysisModel<T>, LSTMVAE<T>, MAModel<T>, NBEATSModel<T>, NHiTSModel<T>, NLinearModel<T>, NeuralNetworkARIMAModel<T>, ProphetModel<T, TInput, TOutput>, SARIMAModel<T>, STLDecomposition<T>, SpectralAnalysisModel<T>, StateSpaceModel<T>, TBATSModel<T>, TemporalFusionTransformer<T>, TiDEModel<T>, TimeSeriesIsolationForest<T>, TransferFunctionModel<T>, UnobservedComponentsModel<T, TInput, TOutput>, VectorAutoRegressionModel<T>
For Beginners
A time series model helps predict future values based on past observations.
Think of a time series like a sequence of measurements taken over time - for example, daily temperatures, monthly sales, or hourly website visits. These models analyze the patterns in historical data to make predictions about what will happen next.
This base class is like a blueprint that all specific time series models follow. It ensures that every model can:
- Be trained on historical data to learn patterns
- Make predictions for future periods based on what it learned
- Evaluate how accurate its predictions are compared to actual values
- Be saved to disk and loaded later without retraining
Time series models are used in many real-world applications, including:
- Weather forecasting
- Stock market prediction
- Demand planning for retail
- Energy consumption forecasting
- Website traffic prediction
How It Works
This abstract class defines the common interface and functionality that all time series models share, including training, prediction, evaluation, and serialization/deserialization capabilities.
Time series models capture temporal dependencies in data and use patterns learned from historical observations to predict future values. This base class provides the foundation for implementing various time series forecasting algorithms like ARIMA, Exponential Smoothing, TBATS, and more complex machine learning approaches.
Properties
| Property | Summary |
|---|---|
Func<TrainingProgress<T>, bool> TrainingEpochCallback { get; set; } |
|
ILossFunction<T> DefaultLossFunction { get; } |
|
ParameterLayoutSnapshot ParameterLayout { get; } |
|
bool SupportsParameterInitialization { get; } |
Gets the trainable parameters of the model as a vector. |
long ParameterCount { get; } |
|
string TrainingStopReason { get; set; } |
Why the current run stopped before exhausting its epoch budget, or null if it ran to completion. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> EvaluateModel(Matrix<T> xTest, Vector<T> yTest) |
Evaluates the performance of the trained model on test data. |
Dictionary<string, T> GetFeatureImportance() |
Gets the feature importance scores as a dictionary. |
DynamicShapeInfo GetDynamicShapeInfo() |
|
IEnumerable<ParameterChunk<T>> GetParameterStateChunks() |
Exposes canonical registered state for device-side checkpoints. |
IEnumerable<Tensor<T>> GetParameterChunks() |
Streams state in manifest order without flattening tensor-backed components. |
IEnumerable<int> GetActiveFeatureIndices() |
Gets the indices of features (lags/time periods) actively used by the model. |
IFullModel<T, Matrix<T>, Vector<T>> Clone() |
Creates a clone of the time series model. |
IFullModel<T, Matrix<T>, Vector<T>> DeepCopy() |
Creates a deep copy of the time series model. |
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
Creates a new model with the specified parameters. |
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the time series model. |
ModelOptions GetOptions() |
|
T PredictSingle(Vector<T> input) |
Generates a prediction for a single input vector. |
Vector<T> ComputeGradients(Matrix<T> input, Vector<T> target, ILossFunction<T> lossFunction) |
|
Vector<T> Forecast(Vector<T> history, int steps) |
Generates a forecast for multiple steps ahead. |
Vector<T> GetParameters() |
|
Vector<T> Predict(Matrix<T> input) |
Generates forecasts using the trained time series model. |
Vector<T> Predict(Vector<T> lookback, int horizon) |
Predicts several future steps at once from a single lookback window — the multi-horizon overload of Predict. |
Vector<T> SanitizeParameters(Vector<T> parameters) |
|
bool IsFeatureUsed(int featureIndex) |
Determines if a specific feature (lag) is actively used by the model. |
byte[] Serialize() |
|
int[] GetInputShape() |
|
int[] GetOutputShape() |
|
void ApplyGradients(Vector<T> gradients, T learningRate) |
|
void Deserialize(byte[] data) |
Deserializes the model from a byte array. |
void Dispose() |
|
void LoadModel(string filePath) |
|
void LoadState(Stream stream) |
Loads the time series model’s state from a stream. |
void Reset() |
Resets the model to its untrained state. |
void SaveModel(string filePath) |
|
void SaveState(Stream stream) |
Saves the time series model’s current state to a stream. |
void SetActiveFeatureIndices(IEnumerable<int> featureIndices) |
Sets the active feature indices for this model. |
void SetParameterChunks(IEnumerable<Tensor<T>> chunks) |
Restores canonical tensor chunks on their device, preserving custom setters and hooks. |
void SetParameters(Vector<T> parameters) |
Sets the parameters for this model. |
void Train(Matrix<T> x, Vector<T> y) |
|
void Train(Matrix<T> x, Vector<T> y, CancellationToken callerToken) |