TOTEM<T>

Models & Types · AiDotNet.Finance.Forecasting.Foundation

TOTEM — TOkenized Time Series EMbeddings via VQ-VAE.

Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → TimeSeriesFoundationModelBase<T> → TOTEM<T>

For Beginners

TOTEM converts continuous time series data into discrete tokens (like words in a vocabulary), making it possible to use language model techniques on numerical data. Think of it as creating a “dictionary” of common time series patterns: each chunk of data gets matched to its closest dictionary entry, creating a compact representation that language-style models can process.

How It Works

TOTEM learns discrete tokenized representations for time series via VQ-VAE, enabling the use of discrete token-based methods (like LLMs) on continuous time series data. It uses an encoder-decoder architecture with vector quantization bottleneck.

Reference: Talukder et al., “TOTEM: TOkenized Time Series EMbeddings for General Time Series Analysis”, 2024.

Example

// Create a TOTEM model for tokenized time series embeddings via VQ-VAE
// Converts continuous time series to discrete tokens for language-model-style processing
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputHeight: 512, inputWidth: 1, inputDepth: 1, outputSize: 24);
            
// Training mode with VQ-VAE encoder-decoder and vector quantization
var model = new TOTEM<double>(architecture);
            
// ONNX inference mode with pre-trained model
var onnxModel = new TOTEM<double>(architecture, "totem.onnx");

Constructors

Constructor Summary
TOTEM(NeuralNetworkArchitecture<T> architecture, TOTEMOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a TOTEM model in native mode for training or fine-tuning.
TOTEM(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, TOTEMOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a TOTEM model using a pretrained ONNX model.

Properties

Property Summary
FoundationModelSize ModelSize { get; }
bool IsChannelIndependent { get; }
bool SupportsTraining { get; }
bool UseNativeMode { get; }
int MaxContextLength { get; }
int MaxPredictionHorizon { 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)