UniTS<T>

Models & Types · AiDotNet.Finance.Forecasting.Foundation

UniTS (Unified Time Series Model) implementation for multi-task time series processing.

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

For Beginners

UniTS is designed to be a universal time series model:

The Key Insight: Different time series tasks share common patterns. Instead of training separate models, UniTS learns a unified representation that works for all tasks.

Supported Tasks:

  1. Forecasting: Predict future values
  2. Classification: Categorize entire time series
  3. Anomaly Detection: Identify unusual patterns
  4. Imputation: Fill in missing values

Architecture:

  • Multi-scale temporal convolution for local patterns (different kernel sizes)
  • Transformer layers for global dependencies
  • Task-specific output heads for different outputs
  • Shared backbone pretrained on diverse datasets

Advantages:

  • One model for multiple tasks (transfer learning)
  • Strong zero-shot performance on new domains
  • Efficient inference (shared computation)

How It Works

UniTS is a unified architecture that handles multiple time series tasks including forecasting, classification, anomaly detection, and imputation using a single pretrained model with task-specific output heads.

Reference: Gao et al., “UniTS: A Unified Multi-Task Time Series Model”, 2024. https://arxiv.org/abs/2403.00131

Example

// Create a UniTS unified model for multi-task time series processing
// Handles forecasting, classification, anomaly detection, and imputation from a single backbone
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputHeight: 512, inputWidth: 7, inputDepth: 1, outputSize: 24);
            
// Training mode with multi-scale temporal convolution and task-specific heads
var model = new UniTS<double>(architecture);
            
// ONNX inference mode with pre-trained model
var onnxModel = new UniTS<double>(architecture, "units_base.onnx");

Constructors

Constructor Summary
UniTS(NeuralNetworkArchitecture<T> architecture, UniTSOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Initializes a new instance in native mode for training.
UniTS(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, UniTSOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Initializes a new instance using an ONNX pretrained model.

Properties

Property Summary
bool IsChannelIndependent { get; }
bool SupportsTraining { get; }
bool UseNativeMode { get; }
int NumClasses { get; } Gets the number of classes for classification task.
int NumFeatures { get; }
int PatchSize { get; }
int PredictionHorizon { get; }
int SequenceLength { get; }
int Stride { get; }
int[] ConvKernelSizes { get; } Gets the convolution kernel sizes.
string TaskType { get; } Gets the task type (forecasting, classification, anomaly, imputation).

Methods

Method Summary
Dictionary<string, T> Evaluate(Tensor<T> predictions, Tensor<T> actuals)
Dictionary<string, T> GetFinancialMetrics()
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input)
ModelMetadata<T> GetModelMetadata()
Tensor<T> ApplyInstanceNormalization(Tensor<T> input)
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps)
Tensor<T> Classify(Tensor<T> input) Performs classification by computing class probabilities.
Tensor<T> DetectAnomalies(Tensor<T> input) Performs anomaly detection by computing reconstruction error.
Tensor<T> Impute(Tensor<T> input, Tensor<T> mask) Performs imputation by filling missing values.