TFC<T>

Models & Types · AiDotNet.Finance.Forecasting.Foundation

TF-C — Time-Frequency Consistency for Self-Supervised Time Series.

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

For Beginners

TF-C learns to understand time series by looking at the same data in two ways: as a sequence of values over time, and as a set of frequencies (like breaking a musical chord into individual notes). By training the model to agree on what it sees from both perspectives, it learns robust patterns that work well for downstream tasks like forecasting and classification.

How It Works

TF-C learns time series representations by enforcing consistency between time-domain and frequency-domain representations via contrastive learning, capturing both temporal and spectral patterns. It uses dual CNN encoders with a shared projection head.

Reference: Zhang et al., “Self-Supervised Contrastive Pre-Training For Time Series via Time-Frequency Consistency”, NeurIPS 2022.

Example

// Create a TF-C model for self-supervised time series representation learning
// Enforces consistency between time-domain and frequency-domain representations
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputHeight: 512, inputWidth: 1, inputDepth: 1, outputSize: 24);
            
// Training mode with dual CNN encoders and contrastive learning
var model = new TFC<double>(architecture);
            
// ONNX inference mode with pre-trained model
var onnxModel = new TFC<double>(architecture, "tfc.onnx");

Constructors

Constructor Summary
TFC(NeuralNetworkArchitecture<T> architecture, TFCOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a TF-C model in native mode for training or fine-tuning.
TFC(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, TFCOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates a TF-C 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)