Hippo<T>
Models & Types · AiDotNet.Finance.Forecasting.StateSpace
HiPPO (High-order Polynomial Projection Operators) for time series forecasting.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → Hippo<T>
For Beginners
HiPPO answers a fundamental question in sequence modeling: “How do we optimally remember a continuous history in a fixed-size memory?”
The Core Problem: When processing a sequence (like a time series), we need to “remember” the past. But we can’t store infinite history - we need a fixed-size “state”. HiPPO shows how to create a state that is the OPTIMAL approximation of history.
How It Works:
- Polynomial Basis: Approximate history using polynomials (like Legendre)
- Optimal Projection: State x(t) = coefficients of best polynomial fit to history
- Online Update: Update state efficiently as new inputs arrive
- Memory Matrix A: Derived mathematically to ensure optimal approximation
The Math (simplified):
- State Space Model: dx/dt = Ax + Bu
- A is the “HiPPO matrix” for your chosen polynomial basis
- x(t) contains polynomial coefficients: history(s) ≈ Σ x_i(t) * P_i(s)
- Different A matrices give different memory properties
Available Methods:
- HiPPO-LegS: Sliding window memory (recent history weighted equally)
- HiPPO-LegT: Fixed window [0,t] (entire history weighted equally)
- HiPPO-LagT: Exponential decay (recent > distant)
Why HiPPO Matters:
- Mathematically principled initialization for SSMs
- Provably optimal history compression
- Foundation for S4, Mamba, and modern sequence models
- Enables models to handle very long sequences efficiently
How It Works
HiPPO provides the theoretical foundation for efficient state space models like S4 and Mamba. It defines optimal state matrices for compressing sequential input history into a fixed-size state.
Reference: Gu et al., “HiPPO: Recurrent Memory with Optimal Polynomial Projections”, 2020.
https://arxiv.org/abs/2008.07669
Example
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputHeight: 256, inputWidth: 1, inputDepth: 1, outputSize: 24);
var model = new Hippo<double>(architecture);
var onnxModel = new Hippo<double>(architecture, "hippo.onnx");
Constructors
| Constructor | Summary |
|---|---|
Hippo(NeuralNetworkArchitecture<T> architecture, HippoOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new instance of the HiPPO model in native mode for training. |
Hippo(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, HippoOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new instance of the HiPPO 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; } |
|
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 StateDimension { get; } |
Gets the state dimension (polynomial order) of the HiPPO model. |
int Stride { get; } |
|
string HippoMethod { get; } |
Gets the HiPPO method used for state initialization. |
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. |
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the HiPPO 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. |