MQCNN<T>

Models & Types · AiDotNet.Finance.Forecasting.Neural

MQCNN (Multi-Quantile Convolutional Neural Network) for probabilistic time series forecasting.

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

For Beginners

MQCNN gives you confidence intervals with your predictions:

What are Quantiles? Quantiles are percentiles of the predicted distribution:

  • 10th percentile (P10): 10% of values fall below this
  • 50th percentile (P50): The median (50% above, 50% below)
  • 90th percentile (P90): 90% of values fall below this

Why Predict Multiple Quantiles? Instead of just saying “tomorrow’s price will be $100”:

  • P10: $95 (likely lower bound - 90% chance actual is above this)
  • P50: $100 (median prediction)
  • P90: $105 (likely upper bound - 90% chance actual is below this)

The Architecture:

  1. Encoder: Dilated convolutions extract temporal patterns from history
  2. Context: Compressed representation of the encoded sequence
  3. Decoder: Produces quantile predictions from the context

Quantile Loss (Pinball Loss): Unlike MSE which penalizes all errors equally, quantile loss:

  • For P90: Penalizes under-predictions more than over-predictions
  • For P10: Penalizes over-predictions more than under-predictions
  • For P50: Equal penalty (reduces to MAE)

Example Use Cases:

  • Stock price prediction with confidence bounds
  • Demand forecasting with safety stock levels
  • Energy load forecasting with peak/valley estimates

How It Works

MQCNN is a probabilistic forecasting model that predicts multiple quantiles simultaneously, providing uncertainty estimates along with point forecasts. It uses an encoder-decoder architecture with dilated causal convolutions for temporal modeling.

Reference: Wen et al., “A Multi-Horizon Quantile Recurrent Forecaster”, 2017. https://arxiv.org/abs/1711.11053

Example

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

Constructors

Constructor Summary
MQCNN(NeuralNetworkArchitecture<T> architecture, MQCNNOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates an MQCNN in native mode for training from scratch.
MQCNN(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, MQCNNOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates an MQCNN using pretrained ONNX model.

Properties

Property Summary
bool IsChannelIndependent { get; }
bool SupportsTraining { get; }
bool UseNativeMode { get; }
double[] Quantiles { get; } Gets the quantile levels being predicted.
int NumFeatures { get; }
int NumQuantiles { get; } Gets the number of quantiles this model predicts.
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)