TSMixer<T>

Models & Types · AiDotNet.Finance.Forecasting.Transformers

TSMixer: An all-MLP architecture for time series forecasting.

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

For Beginners

TSMixer is a simpler alternative to transformer-based models that:

  • Uses only MLPs (fully connected layers)
  • Alternates between mixing information across time and across features
  • Is faster to train and more memory-efficient than attention-based models

The core idea is that mixing time and feature information separately but alternately is sufficient for capturing complex patterns in multivariate time series.

How It Works

TSMixer achieves state-of-the-art results using only multilayer perceptrons (MLPs), without attention mechanisms. It alternates between time-mixing and feature-mixing operations to capture both temporal patterns and cross-variable relationships.

Reference: Chen et al., “TSMixer: An All-MLP Architecture for Time Series Forecasting”, TMLR 2023. https://arxiv.org/abs/2303.06053

Example

// Create a TSMixer for efficient time series forecasting using only MLPs
// Alternates time-mixing and feature-mixing without attention mechanisms
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputHeight: 96, inputWidth: 7, inputDepth: 1, outputSize: 24);
            
// Training mode with alternating time/feature mixing layers
var model = new TSMixer<double>(architecture);
            
// ONNX inference mode with pre-trained model
var onnxModel = new TSMixer<double>(architecture, "tsmixer_weather.onnx");

Constructors

Constructor Summary
TSMixer(NeuralNetworkArchitecture<T> architecture, TSMixerOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a new TSMixer instance for native training mode.
TSMixer(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, TSMixerOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a new TSMixer instance for ONNX inference mode.

Properties

Property Summary
bool IsChannelIndependent { get; } Gets whether the model processes channels independently.
bool SupportsTraining { get; } Gets whether this network supports training.
bool UseNativeMode { get; } Gets whether the model uses native mode (true) or ONNX mode (false).
int NumFeatures { get; } Gets the number of input features.
int PatchSize { get; } Gets the patch size.
int PredictionHorizon { get; } Gets the prediction horizon.
int SequenceLength { get; } Gets the input sequence length.
int Stride { get; } Gets the stride.

Methods

Method Summary
Dictionary<string, T> Evaluate(Tensor<T> testData, Tensor<T> testLabels) Evaluates the model on a test dataset.
Dictionary<string, T> GetFinancialMetrics() Gets financial metrics specific to the model.
ModelInputShapeConstraint GetInputShapeConstraint() Generated from [ModelInputShapeConstraint].
ModelMetadata<T> GetModelMetadata() Gets metadata about the model.
Tensor<T> ApplyInstanceNormalization(Tensor<T> input) Applies instance normalization (RevIN) to the input.
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps) Generates multi-step forecasts using autoregressive prediction.
Tensor<T> ForwardForTraining(Tensor<T> input) Tape-aware training forward.