TimeMachine<T>
Models & Types · AiDotNet.Finance.Forecasting.StateSpace
TimeMachine’s four-Mamba architecture for long-term time series forecasting.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → TimeMachine<T>
For Beginners
TimeMachine is a modern architecture whose key insight is that “A Time Series is Worth 4 Mambas.” After RevIN, E1 embeds the history length. Two outer Mambas process that representation in complementary orientations. E2 then creates a smaller representation for two inner Mambas. Residual projection P1 joins the inner path, its result is concatenated with the outer path, and P2 produces the forecast.
Key Benefits:
- Linear complexity O(n) from SSM backbone
- Complementary channel/embedding scans capture cross-variate and temporal structure
- RevIN handles non-stationarity
- State-of-the-art results on long-term forecasting benchmarks
How It Works
TimeMachine embeds the input length twice and uses two outer and two inner Mamba branches in complementary channel/embedding orientations.
Reference: Ahamed et al., “TimeMachine: A Time Series is Worth 4 Mambas for Long-term Forecasting”, 2024.
https://arxiv.org/abs/2403.09898
Example
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputHeight: 512, inputWidth: 7, inputDepth: 1, outputSize: 96);
var model = new TimeMachine<double>(architecture);
var onnxModel = new TimeMachine<double>(architecture, "timemachine.onnx");
Constructors
| Constructor | Summary |
|---|---|
TimeMachine(NeuralNetworkArchitecture<T> architecture, TimeMachineOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new instance of the TimeMachine model in native mode for training. |
TimeMachine(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, TimeMachineOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new instance of the TimeMachine model in ONNX mode for inference. |
Properties
| Property | Summary |
|---|---|
bool IsChannelIndependent { get; } |
|
bool SupportsTraining { get; } |
Gets whether the model supports training (native mode only). |
bool UseNativeMode { get; } |
|
bool UseReversibleNormalization { get; } |
Gets whether reversible instance normalization is used. |
int ContextLength { get; } |
Gets the input context length for the model. |
int ForecastHorizon { get; } |
Gets the forecast horizon (number of future steps to predict). |
int NumFeatures { get; } |
|
int PatchSize { get; } |
|
int PredictionHorizon { get; } |
|
int SequenceLength { get; } |
|
int Stride { get; } |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> Evaluate(Tensor<T> predictions, Tensor<T> actuals) |
Evaluates forecast quality against actual values. |
Dictionary<string, T> GetFinancialMetrics() |
Gets financial-specific metrics about the model. |
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input) |
|
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the TimeMachine model. |
Tensor<T> ApplyInstanceNormalization(Tensor<T> input) |
Applies instance normalization to the input. |
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps) |
Performs autoregressive forecasting step by step. |
Tensor<T> Forward(Tensor<T> input) |
Performs the forward pass through all layers. |
ValueTuple<Tensor<T>, Tensor<T>, Tensor<T>> ForecastWithIntervals(Tensor<T> input, double confidenceLevel) |
Generates forecasts with prediction intervals for uncertainty quantification. |