NBEATSFinance<T>
Models & Types · AiDotNet.Finance.Forecasting.Neural
N-BEATS (Neural Basis Expansion Analysis for Time Series) model for financial forecasting.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → NBEATSFinance<T>
For Beginners
N-BEATS works by stacking multiple “blocks” that each try to explain part of the time series. Each block:
- Looks at the input
- Produces a “backcast” (its explanation of the past)
- Produces a “forecast” (its prediction for the future)
- Passes the “residual” (what it couldn’t explain) to the next block
This hierarchical approach allows N-BEATS to decompose complex patterns into simpler components, similar to how you might break down a sound wave into different frequency components.
Key benefits:
- Interpretable: Can separate trend from seasonality
- No feature engineering: Works directly on raw time series
- State-of-the-art accuracy: Competitive with or better than traditional methods
How It Works
N-BEATS is a deep neural architecture that uses basis expansion to decompose time series into interpretable components. It achieves state-of-the-art performance while providing the ability to decompose forecasts into trend and seasonality components.
Reference: Oreshkin et al., “N-BEATS: Neural basis expansion analysis for
interpretable time series forecasting”, ICLR 2020. https://arxiv.org/abs/1905.10437
Example
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputHeight: 60, inputWidth: 1, inputDepth: 1, outputSize: 24);
var model = new NBEATSFinance<double>(architecture);
var onnxModel = new NBEATSFinance<double>(architecture, "nbeats.onnx");
Constructors
| Constructor | Summary |
|---|---|
NBEATSFinance(NeuralNetworkArchitecture<T> architecture, NBEATSModelOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates an N-BEATS network in native mode for training from scratch. |
NBEATSFinance(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, NBEATSModelOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates an N-BEATS 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) |