TinyTimeMixers<T>
Models & Types · AiDotNet.Finance.Forecasting.Foundation
Tiny Time Mixers (TTM) foundation model for compact, high-performance time series forecasting.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → TimeSeriesFoundationModelBase<T> → TinyTimeMixers<T>
For Beginners
TTM proves that bigger isn’t always better:
MLP-Mixer Architecture: Instead of expensive attention mechanisms, TTM alternates between two types of mixing:
- Temporal Mixing: An MLP that mixes information across time steps within each feature.
Think of it as learning “how does the pattern at time t relate to time t-1, t-2, etc.?”
- Channel Mixing: An MLP that mixes information across features at each time step.
Think of it as learning “how does price relate to volume at this moment?”
Why So Small Yet Effective:
- Time series have simpler structure than language or images
- MLP-Mixers capture temporal patterns efficiently without attention overhead
- Patch-based input reduces the sequence length the model needs to process
- Careful architectural choices maximize information per parameter
Practical Benefits:
- Runs on CPU in real-time (no GPU required)
- Trains in minutes instead of hours
- Perfect for edge deployment (IoT, mobile)
- Low memory footprint (~20MB model size)
How It Works
TTM is IBM Research’s lightweight foundation model that uses an MLP-Mixer architecture instead of attention-based transformers. With only 1-5 million parameters, it outperforms or matches models 20-40x its size on standard forecasting benchmarks.
Reference: Ekambaram et al., “Tiny Time Mixers (TTMs): Fast Pre-trained Models
for Enhanced Zero/Few-Shot Forecasting of Multivariate Time Series”, NeurIPS 2024.
https://arxiv.org/abs/2401.03955
Thread Safety: This class is NOT thread-safe. Create separate instances for concurrent usage.
Example
// Create a Tiny Time Mixers (TTM) for compact, high-performance forecasting
// MLP-Mixer architecture with only 1-5M parameters that rivals 20-40x larger models
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputHeight: 512, inputWidth: 7, inputDepth: 1, outputSize: 24);
// Training mode with temporal and channel mixing MLPs
var model = new TinyTimeMixers<double>(architecture);
// ONNX inference mode with pre-trained model
var onnxModel = new TinyTimeMixers<double>(architecture, "ttm_base.onnx");
Constructors
| Constructor | Summary |
|---|---|
TinyTimeMixers(NeuralNetworkArchitecture<T> architecture, TinyTimeMixersOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates a Tiny Time Mixers model in native mode for training or fine-tuning. |
TinyTimeMixers(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, TinyTimeMixersOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates a Tiny Time Mixers 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() |
|
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) |