DeepState<T>

Models & Types · AiDotNet.Finance.Forecasting.Neural

DeepState (Deep State Space Model) for probabilistic time series forecasting.

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

For Beginners

DeepState is like having a statistical model that can learn:

State Space Model Basics: SSMs assume your observations come from hidden “states” that evolve over time:

  • z_t = F * z_{t-1} + process_noise (state transition)
  • y_t = H * z_t + observation_noise (observation)

The states might represent:

  • Level: The current baseline value
  • Trend: The direction and rate of change
  • Seasonality: Repeating patterns (daily, weekly, yearly)

Why “Deep” State Space? Classical SSMs require manual specification of model structure. DeepState uses neural networks to:

  1. Process historical data with an RNN encoder
  2. Generate SSM parameters (F, H matrices) from learned representations
  3. Run the SSM forward to produce forecasts

Advantages:

  • Natural decomposition into interpretable components
  • Built-in uncertainty quantification
  • Handles multiple time series with shared patterns
  • Robust to missing data

Example: For energy demand forecasting:

  • The RNN learns that hot weather increases cooling demand
  • The SSM captures daily patterns (peak at 6pm) and weekly patterns (less on weekends)
  • Forecasts include uncertainty (wider intervals during unusual weather)

How It Works

DeepState combines the interpretability of classical state space models (SSM) with the flexibility of deep learning. An RNN encoder learns to parameterize an SSM, which then produces forecasts with natural uncertainty quantification.

Reference: Rangapuram et al., “Deep State Space Models for Time Series Forecasting”, 2018. https://papers.nips.cc/paper/2018/hash/5cf68969fb67aa6082363a6d4e6468e2-Abstract.html

Example

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

Constructors

Constructor Summary
DeepState(NeuralNetworkArchitecture<T> architecture, DeepStateOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a DeepState model in native mode for training from scratch.
DeepState(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, DeepStateOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a DeepState model 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 StateDimension { get; } Gets the state dimension of the SSM.
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)