LSTNet<T>

Models & Types · AiDotNet.Finance.Forecasting.Neural

LSTNet (Long Short-Term Time-series Network) model for multivariate time series forecasting.

Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → LSTNet<T>

For Beginners

LSTNet is like having a team of specialists analyze your time series:

  1. The Pattern Scanner (CNN): Scans through your data looking for local patterns,

like finding “every Monday is busy” or “there’s always a dip at noon”.

  1. The Trend Tracker (GRU): Remembers long-term trends, like “sales have been

growing steadily for the past 3 months”.

  1. The Season Watcher (Skip-RNN): Compares the same time across different periods,

like comparing this Tuesday’s 3 PM with last Tuesday’s 3 PM.

  1. The Simple Forecaster (Autoregressive): Makes basic predictions based on recent

values, like “if it was 100 yesterday, it’s probably around 100 today”.

All these specialists combine their insights to produce the final forecast.

How It Works

LSTNet combines multiple neural network components to capture patterns at different temporal scales:

  • Convolutional layers for short-term local patterns
  • Recurrent layers (GRU) for long-term dependencies
  • Skip-RNN for periodic patterns
  • Autoregressive component for simple linear relationships

Reference: Lai et al., “Modeling Long- and Short-Term Temporal Patterns with Deep Neural Networks”, SIGIR 2018. https://arxiv.org/abs/1703.07015

Example

var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputHeight: 168, inputWidth: 7, inputDepth: 1, outputSize: 24);
var model = new LSTNet<double>(architecture);
var onnxModel = new LSTNet<double>(architecture, "lstnet.onnx");

Constructors

Constructor Summary
LSTNet(NeuralNetworkArchitecture<T> architecture, LSTNetOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates an LSTNet in native mode for training from scratch.
LSTNet(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, LSTNetOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates an LSTNet 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)