TFT<T>
Models & Types · AiDotNet.Finance.Forecasting.Transformers
Temporal Fusion Transformer (TFT) neural network for multi-horizon time series forecasting.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → TFT<T>
For Beginners
TFT is like a smart assistant that considers different types of information:
- Static features: Things that don’t change (e.g., store location)
- Known future inputs: Things we know ahead (e.g., holidays, promotions)
- Unknown inputs: Historical data we can only observe (e.g., past sales)
Key innovations:
- Variable Selection: Automatically finds which features matter most
- Gated Skip Connections: Helps information flow through the network
- Interpretable Attention: Shows which time periods influenced predictions
How It Works
TFT is a state-of-the-art architecture that combines high-performance multi-horizon forecasting with interpretable insights. It uses variable selection networks, gating mechanisms, and self-attention to handle multiple input types (static, known future, unknown observed).
Reference: Lim et al., “Temporal Fusion Transformers for Interpretable Multi-horizon
Time Series Forecasting”, International Journal of Forecasting 2021.
https://arxiv.org/abs/1912.09363
Example
// Create a Temporal Fusion Transformer for multi-horizon forecasting
// Handles static, known-future, and observed inputs with variable selection
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputHeight: 96, inputWidth: 7, inputDepth: 1, outputSize: 24);
// Training mode with variable selection and interpretable attention
var model = new TFT<double>(architecture);
// ONNX inference mode with pre-trained model
var onnxModel = new TFT<double>(architecture, "tft_retail.onnx");
Constructors
| Constructor | Summary |
|---|---|
TFT() |
Creates a TFT model with default configuration for native training. |
TFT(NeuralNetworkArchitecture<T> architecture, TemporalFusionTransformerOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates a TFT network in native mode for training from scratch. |
TFT(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, TemporalFusionTransformerOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates a TFT network using pretrained ONNX model. |
Properties
| Property | Summary |
|---|---|
bool IsChannelIndependent { get; } |
|
bool SupportsTraining { get; } |
|
bool UseNativeMode { get; } |
|
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) |
|
Dictionary<string, T> GetFinancialMetrics() |
|
ModelMetadata<T> GetModelMetadata() |
|
Tensor<T> ApplyInstanceNormalization(Tensor<T> input) |
|
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps) |