DeepFactor<T>
Models & Types · AiDotNet.Finance.Forecasting.Neural
DeepFactor (Deep Factor Model) for multivariate time series forecasting.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → DeepFactor<T>
For Beginners
DeepFactor is designed for forecasting many related time series:
The Factor Model Idea: Many time series are driven by common underlying patterns:
- Stock prices: Market factors, sector factors, economic factors
- Retail sales: Holiday effects, weather, economic conditions
- Energy demand: Temperature, time of day, day of week
The Decomposition: y_t = (factor_loadings * global_factors_t) + local_t + noise
- Global factors: Shared patterns learned from all series
- Factor loadings: How much each series is affected by each factor
- Local component: Series-specific patterns not captured by factors
Why Deep Learning? Traditional factor models use linear relationships. DeepFactor uses neural networks to:
- Learn non-linear factor dynamics (factors can evolve in complex ways)
- Automatically discover the right number and type of factors
- Capture complex interactions between factors
Architecture:
- Factor Model: RNN that generates global factor values over time
- Loading Layer: Maps factors to series-specific contributions
- Local Model: Smaller network for series-specific patterns
- Combination: Merges factor-based and local predictions
Benefits:
- Efficient: Shares computation across many series via factors
- Interpretable: Factors can be analyzed to understand shared patterns
- Robust: Less overfitting when series share common dynamics
How It Works
DeepFactor combines classical factor models with deep learning. It decomposes time series into global factors (shared patterns) and local components (series-specific behavior), learning both through neural networks for improved forecasting accuracy.
Reference: Wang et al., “Deep Factors for Forecasting”, 2019.
https://arxiv.org/abs/1905.12417
Example
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputHeight: 60, inputWidth: 1, inputDepth: 1, outputSize: 24);
var model = new DeepFactor<double>(architecture);
var onnxModel = new DeepFactor<double>(architecture, "deepfactor.onnx");
Constructors
| Constructor | Summary |
|---|---|
DeepFactor(NeuralNetworkArchitecture<T> architecture, DeepFactorOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates a DeepFactor model in native mode for training from scratch. |
DeepFactor(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, DeepFactorOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates a DeepFactor model using pretrained ONNX model. |
Properties
| Property | Summary |
|---|---|
bool IsChannelIndependent { get; } |
|
bool SupportsTraining { get; } |
|
bool UseNativeMode { get; } |
|
int NumFactors { get; } |
Gets the number of latent factors in the model. |
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) |