Skip to content

Conversation

@ooples
Copy link
Owner

@ooples ooples commented Nov 8, 2025

…n for Issue #402

This commit implements Phase 3 of advanced time series capabilities as requested in issue #402:

Foundation Models (Critical Priority):

  • Temporal Fusion Transformer (TFT): Multi-horizon interpretable forecasting with attention mechanisms, variable selection, and probabilistic quantile predictions
  • Chronos Foundation Model: Zero-shot forecasting using tokenization and transformer architecture inspired by language models

Advanced Architectures (High Priority):

  • N-HiTS: Neural Hierarchical Interpolation for Time Series with multi-rate sampling, hierarchical pooling, and interpolation-based basis functions for efficient long-horizon forecasting
  • DeepAR: Probabilistic autoregressive forecasting with LSTM networks, supporting multiple related time series and uncertainty quantification
  • Informer: Efficient transformer with ProbSparse attention (O(L log L) complexity) and self-attention distilling for long-sequence forecasting

Anomaly Detection (High Priority):

  • DeepANT: Deep learning-based anomaly detection using CNN for time series prediction and error-based anomaly scoring
  • LSTM-VAE: Variational Autoencoder with LSTM encoder/decoder for unsupervised anomaly detection via reconstruction error

Key Features:

  • Multi-horizon forecasting capabilities across all models
  • Probabilistic prediction support with quantile forecasts (TFT, DeepAR, Chronos)
  • Comprehensive options classes for model configuration
  • Serialization/deserialization support for model persistence
  • Anomaly detection subdirectory structure under src/TimeSeries/AnomalyDetection/
  • All models follow existing TimeSeriesModelBase patterns for consistency

Technical Implementation:

  • All models inherit from TimeSeriesModelBase
  • Support for generic numeric types (float, double)
  • Comprehensive XML documentation for beginners and advanced users
  • Parameter-efficient architectures with proper initialization
  • Training with numerical gradient computation (production systems would use automatic differentiation)

These implementations provide state-of-the-art capabilities for:

  • Long-horizon forecasting (N-HiTS, Informer)
  • Interpretable predictions (TFT)
  • Probabilistic forecasts (DeepAR, TFT, Chronos)
  • Zero-shot learning (Chronos)
  • Anomaly detection (DeepANT, LSTM-VAE)

Addresses requirements from Issue #402 for modern time series foundation models and anomaly detection capabilities.

User Story / Context

  • Reference: [US-XXX] (if applicable)
  • Base branch: merge-dev2-to-master

Summary

  • What changed and why (scoped strictly to the user story / PR intent)

Verification

  • Builds succeed (scoped to changed projects)
  • Unit tests pass locally
  • Code coverage >= 90% for touched code
  • Codecov upload succeeded (if token configured)
  • TFM verification (net46, net6.0, net8.0) passes (if packaging)
  • No unresolved Copilot comments on HEAD

Copilot Review Loop (Outcome-Based)

Record counts before/after your last push:

  • Comments on HEAD BEFORE: [N]
  • Comments on HEAD AFTER (60s): [M]
  • Final HEAD SHA: [sha]

Files Modified

  • List files changed (must align with scope)

Notes

  • Any follow-ups, caveats, or migration details

…n for Issue #402

This commit implements Phase 3 of advanced time series capabilities as requested in issue #402:

**Foundation Models (Critical Priority):**
- Temporal Fusion Transformer (TFT): Multi-horizon interpretable forecasting with attention mechanisms, variable selection, and probabilistic quantile predictions
- Chronos Foundation Model: Zero-shot forecasting using tokenization and transformer architecture inspired by language models

**Advanced Architectures (High Priority):**
- N-HiTS: Neural Hierarchical Interpolation for Time Series with multi-rate sampling, hierarchical pooling, and interpolation-based basis functions for efficient long-horizon forecasting
- DeepAR: Probabilistic autoregressive forecasting with LSTM networks, supporting multiple related time series and uncertainty quantification
- Informer: Efficient transformer with ProbSparse attention (O(L log L) complexity) and self-attention distilling for long-sequence forecasting

**Anomaly Detection (High Priority):**
- DeepANT: Deep learning-based anomaly detection using CNN for time series prediction and error-based anomaly scoring
- LSTM-VAE: Variational Autoencoder with LSTM encoder/decoder for unsupervised anomaly detection via reconstruction error

**Key Features:**
- Multi-horizon forecasting capabilities across all models
- Probabilistic prediction support with quantile forecasts (TFT, DeepAR, Chronos)
- Comprehensive options classes for model configuration
- Serialization/deserialization support for model persistence
- Anomaly detection subdirectory structure under src/TimeSeries/AnomalyDetection/
- All models follow existing TimeSeriesModelBase patterns for consistency

**Technical Implementation:**
- All models inherit from TimeSeriesModelBase<T>
- Support for generic numeric types (float, double)
- Comprehensive XML documentation for beginners and advanced users
- Parameter-efficient architectures with proper initialization
- Training with numerical gradient computation (production systems would use automatic differentiation)

These implementations provide state-of-the-art capabilities for:
- Long-horizon forecasting (N-HiTS, Informer)
- Interpretable predictions (TFT)
- Probabilistic forecasts (DeepAR, TFT, Chronos)
- Zero-shot learning (Chronos)
- Anomaly detection (DeepANT, LSTM-VAE)

Addresses requirements from Issue #402 for modern time series foundation models and anomaly detection capabilities.
Copilot AI review requested due to automatic review settings November 8, 2025 20:02
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 8, 2025

Warning

Rate limit exceeded

@ooples has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 27 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f99b0d2 and 691c50c.

📒 Files selected for processing (11)
  • src/Models/Options/DeepAROptions.cs (1 hunks)
  • src/Models/Options/InformerOptions.cs (1 hunks)
  • src/Models/Options/NHiTSOptions.cs (1 hunks)
  • src/Models/Options/TemporalFusionTransformerOptions.cs (1 hunks)
  • src/TimeSeries/AnomalyDetection/DeepANT.cs (1 hunks)
  • src/TimeSeries/AnomalyDetection/LSTMVAE.cs (1 hunks)
  • src/TimeSeries/ChronosFoundationModel.cs (1 hunks)
  • src/TimeSeries/DeepARModel.cs (1 hunks)
  • src/TimeSeries/InformerModel.cs (1 hunks)
  • src/TimeSeries/NHiTSModel.cs (1 hunks)
  • src/TimeSeries/TemporalFusionTransformer.cs (1 hunks)
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-issue-402-011CUvzc3Fx3a8WuXVKarCzU

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces advanced time series forecasting and anomaly detection models to the AiDotNet library, significantly expanding its capabilities for temporal data analysis.

Key Changes

  • Implementation of 5 state-of-the-art forecasting models: Temporal Fusion Transformer (TFT), N-HiTS, Informer, DeepAR, and Chronos Foundation Model
  • Addition of 2 anomaly detection models: LSTM-VAE and DeepANT
  • Comprehensive configuration options classes for all new models with beginner-friendly documentation

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 50 comments.

Show a summary per file
File Description
src/TimeSeries/TemporalFusionTransformer.cs Implements TFT with attention mechanisms, quantile predictions, and multi-horizon forecasting
src/TimeSeries/NHiTSModel.cs Implements N-HiTS with hierarchical interpolation and multi-rate sampling for long-horizon forecasting
src/TimeSeries/InformerModel.cs Implements efficient Informer model with ProbSparse attention for long-sequence forecasting
src/TimeSeries/DeepARModel.cs Implements probabilistic DeepAR model with LSTM-based autoregressive architecture
src/TimeSeries/ChronosFoundationModel.cs Implements foundation model approach with tokenization for zero-shot forecasting
src/TimeSeries/AnomalyDetection/LSTMVAE.cs Implements LSTM-VAE for anomaly detection using reconstruction error
src/TimeSeries/AnomalyDetection/DeepANT.cs Implements CNN-based DeepANT for unsupervised anomaly detection
src/Models/Options/TemporalFusionTransformerOptions.cs Configuration options for TFT with extensive documentation
src/Models/Options/NHiTSOptions.cs Configuration options for N-HiTS with pooling and interpolation settings
src/Models/Options/InformerOptions.cs Configuration options for Informer with distilling parameters; contains formatting issue
src/Models/Options/DeepAROptions.cs Configuration options for DeepAR with probabilistic forecasting settings

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/// the sequence length of the previous one.
/// </para>
/// </remarks>
public int DistillingFactor { get; set} = 2;
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before closing brace in property accessor. Should be { get; set; } not { get; set} to maintain consistent formatting with the rest of the file.

Suggested change
public int DistillingFactor { get; set} = 2;
public int DistillingFactor { get; set; } = 2;

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +85
if (q <= 0 || q >= 1)
throw new ArgumentException("Quantile levels must be between 0 and 1.");
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation for quantile levels uses an exclusive comparison (q <= 0 || q >= 1), but quantiles of exactly 0 or 1 are valid edge cases representing minimum and maximum values. The condition should be q < 0 || q > 1 instead.

Suggested change
if (q <= 0 || q >= 1)
throw new ArgumentException("Quantile levels must be between 0 and 1.");
if (q < 0 || q > 1)
throw new ArgumentException("Quantile levels must be between 0 and 1 (inclusive).");

Copilot uses AI. Check for mistakes.
Comment on lines +82 to +86
foreach (var q in _options.QuantileLevels)
{
if (q <= 0 || q >= 1)
throw new ArgumentException("Quantile levels must be between 0 and 1.");
}
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This foreach loop implicitly filters its target sequence - consider filtering the sequence explicitly using '.Where(...)'.

Copilot uses AI. Check for mistakes.
Comment on lines +114 to +118
foreach (var error in predictionErrors)
{
T diff = _numOps.Subtract(error, mean);
variance = _numOps.Add(variance, _numOps.Multiply(diff, diff));
}
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This foreach loop immediately maps its iteration variable to another variable - consider mapping the sequence explicitly using '.Select(...)'.

Copilot uses AI. Check for mistakes.
Comment on lines +321 to +327
foreach (var lstm in _lstmLayers)
{
var parameters = lstm.GetParameters();
writer.Write(parameters.Length);
for (int i = 0; i < parameters.Length; i++)
writer.Write(Convert.ToDouble(parameters[i]));
}
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This foreach loop immediately maps its iteration variable to another variable - consider mapping the sequence explicitly using '.Select(...)'.

Copilot uses AI. Check for mistakes.
{
private readonly NHiTSOptions<T> _options;
private readonly INumericOperations<T> _numOps;
private List<NHiTSStack<T>> _stacks;
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field '_stacks' can be 'readonly'.

Suggested change
private List<NHiTSStack<T>> _stacks;
private readonly List<NHiTSStack<T>> _stacks;

Copilot uses AI. Check for mistakes.
private readonly int _hiddenSize;
private readonly int _numLayers;
private readonly int _poolingSize;
private List<Matrix<T>> _weights;
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field '_weights' can be 'readonly'.

Suggested change
private List<Matrix<T>> _weights;
private readonly List<Matrix<T>> _weights;

Copilot uses AI. Check for mistakes.
private readonly int _numLayers;
private readonly int _poolingSize;
private List<Matrix<T>> _weights;
private List<Vector<T>> _biases;
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field '_biases' can be 'readonly'.

Suggested change
private List<Vector<T>> _biases;
private readonly List<Vector<T>> _biases;

Copilot uses AI. Check for mistakes.
private readonly INumericOperations<T> _numOps;

// Model components
private List<Matrix<T>> _weights;
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field '_weights' can be 'readonly'.

Suggested change
private List<Matrix<T>> _weights;
private readonly List<Matrix<T>> _weights;

Copilot uses AI. Check for mistakes.

// Model components
private List<Matrix<T>> _weights;
private List<Vector<T>> _biases;
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field '_biases' can be 'readonly'.

Suggested change
private List<Vector<T>> _biases;
private readonly List<Vector<T>> _biases;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants