AiDotNet icon indicating copy to clipboard operation
AiDotNet copied to clipboard

Fix issue 402 in AiDotNet

Open ooples opened this issue 2 months ago • 1 comments

…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.

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

ooples avatar Nov 08 '25 20:11 ooples

[!WARNING]

Rate limit exceeded

@ooples has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 10 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 2fb0f8558260641ba3b3ad5b937ae431cc908bfa and 944d70929a1a4091316c9e4be743289778b20983.

📒 Files selected for processing (14)
  • .github/workflows/commitlint.yml (0 hunks)
  • commitlint.config.js (1 hunks)
  • 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)
  • src/WaveletFunctions/CoifletWavelet.cs (1 hunks)

[!NOTE]

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds multiple new time-series forecasting and anomaly-detection models and their option classes: DeepAR, Informer, N‑HiTS, Temporal Fusion Transformer, ChronosFoundation, DeepANT, and LSTMVAE, including model implementations, options with copy constructors, training/inference methods, serialization, and parameter counting.

Changes

Cohort / File(s) Change Summary
Model option classes
src/Models/Options/DeepAROptions.cs, src/Models/Options/InformerOptions.cs, src/Models/Options/NHiTSOptions.cs, src/Models/Options/TemporalFusionTransformerOptions.cs
Added generic options classes (extend TimeSeriesRegressionOptions<T>) with parameterless and copy constructors, many hyperparameter properties with sensible defaults, XML docs, and defensive cloning for arrays where applicable.
DeepAR model & support
src/TimeSeries/DeepARModel.cs, src/Models/Options/DeepAROptions.cs
New DeepARModel<T> implementing LSTM-like cells, distribution heads (Gaussian likelihood), Gaussian NLL training, ForecastWithQuantiles (Monte Carlo sampling), PredictSingle, serialization/deserialization, CreateInstance, and ParameterCount. Options class added.
Informer model & support
src/TimeSeries/InformerModel.cs, src/Models/Options/InformerOptions.cs
New InformerModel<T> with embedding, encoder/decoder layers, ProbSparse attention, distilling, training loop, PredictSingle, multi-step forecasting, (de)serialization for internal blocks, CreateInstance, and ParameterCount. Options class added.
N‑HiTS model & support
src/TimeSeries/NHiTSModel.cs, src/Models/Options/NHiTSOptions.cs
New NHiTSModel<T> and NHiTSOptions<T> implementing multi-stack, multi-rate forecasting with per-stack NHiTSStack<T>, pooling/interpolation modes, option validation, training loop, forecasting aggregation, serialization, and ParameterCount.
Temporal Fusion Transformer model & options
src/TimeSeries/TemporalFusionTransformer.cs, src/Models/Options/TemporalFusionTransformerOptions.cs
New TemporalFusionTransformer<T> and options. Adds attention and quantile outputs, weight/bias initialization, training loop, PredictQuantiles/ForecastWithQuantiles, PredictSingle, (de)serialization, CreateInstance, and ParameterCount.
Chronos foundation model & options
src/TimeSeries/ChronosFoundationModel.cs
New ChronosFoundationModel<T> with ChronosOptions<T>, tokenization/detokenization, token embeddings, internal transformer layers, training loop, ForecastWithQuantiles, PredictSingle, (de)serialization, CreateInstance, and ParameterCount.
Anomaly-detection models
src/TimeSeries/AnomalyDetection/DeepANT.cs, src/TimeSeries/AnomalyDetection/LSTMVAE.cs
Added DeepANT<T> and LSTMVAE<T> plus DeepANTOptions<T> and LSTMVAEOptions<T>. Each includes internal components (ConvLayer, LSTM encoder/decoder), training flows, PredictSingle, DetectAnomalies/ComputeAnomalyScores, serialization/deserialization, GetModelMetadata, CreateInstance, and ParameterCount.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

  • Focus areas:
    • Training loops and numerical/finite-difference update implementations across many models (DeepARModel, InformerModel, NHiTSModel, TemporalFusionTransformer, ChronosFoundation, DeepANT, LSTMVAE).
    • Probabilistic sampling, likelihood implementations, and quantile aggregation (DeepARModel, TemporalFusionTransformer, ChronosFoundation).
    • Serialization/deserialization consistency and versioning for nested components (encoder/decoder/transformer blocks, stacks, embeddings).
    • Correctness and defensive copying in copy constructors and option classes (array cloning).
    • Parameter counting versus actual persisted parameter vectors and downstream CreateInstance behavior.

Poem

🐇 I hopped through windows, layers, and time,
I nudged tokens, stacks, and a tiny rhyme,
I sniffed for odd beats and learned to decode,
I sampled quantiles down a winding road,
A rabbit’s cheer for models now in code.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.82% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The PR title 'Fix issue 402 in AiDotNet' is vague and does not convey the substantial scope of Phase 3 implementation, including foundation models, advanced architectures, and anomaly detection capabilities. Consider a more descriptive title like 'Add Phase 3 time series models: TFT, Chronos, N-HiTS, DeepAR, Informer, and anomaly detection' to better represent the scope.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The PR description is comprehensive and directly related to the changeset, detailing all models, features, and implementation approach for Phase 3 time series capabilities.

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.

coderabbitai[bot] avatar Nov 08 '25 20:11 coderabbitai[bot]