Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions src/Models/Options/DeepAROptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
using System;

namespace AiDotNet.Models.Options;

/// <summary>
/// Configuration options for the DeepAR (Deep Autoregressive) model.
/// </summary>
/// <typeparam name="T">The numeric type used for calculations (typically double or float).</typeparam>
/// <remarks>
/// <para>
/// DeepAR is a probabilistic forecasting methodology based on autoregressive recurrent neural networks.
/// Unlike traditional methods that provide point forecasts, DeepAR produces probabilistic forecasts
/// that include prediction intervals. It's particularly effective for:
/// - Handling multiple related time series simultaneously
/// - Cold-start problems (forecasting for new items with limited history)
/// - Capturing complex seasonal patterns and trends
/// - Quantifying forecast uncertainty
/// </para>
/// <para><b>For Beginners:</b> DeepAR is an advanced forecasting model that not only predicts
/// what will happen, but also how confident it is in those predictions. Instead of saying
/// "sales will be exactly 100 units," it might say "sales will likely be between 80 and 120 units,
/// with 100 being most probable."
///
/// This is especially useful when:
/// - You need to plan for worst-case and best-case scenarios
/// - You have many related time series (e.g., sales across many stores)
/// - You have some series with very little historical data
///
/// The "autoregressive" part means it uses its own predictions as inputs for future predictions,
/// and "deep" refers to the use of deep neural networks (specifically, LSTM networks).
/// </para>
/// </remarks>
public class DeepAROptions<T> : TimeSeriesRegressionOptions<T>
{
/// <summary>
/// Initializes a new instance of the <see cref="DeepAROptions{T}"/> class.
/// </summary>
public DeepAROptions()
{
}

/// <summary>
/// Initializes a new instance by copying from another instance.
/// </summary>
public DeepAROptions(DeepAROptions<T> other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));

LookbackWindow = other.LookbackWindow;
ForecastHorizon = other.ForecastHorizon;
HiddenSize = other.HiddenSize;
NumLayers = other.NumLayers;
DropoutRate = other.DropoutRate;
LearningRate = other.LearningRate;
Epochs = other.Epochs;
BatchSize = other.BatchSize;
NumSamples = other.NumSamples;
LikelihoodType = other.LikelihoodType;
CovariateSize = other.CovariateSize;
EmbeddingDimension = other.EmbeddingDimension;
}

/// <summary>
/// Gets or sets the lookback window size (context length).
/// </summary>
/// <value>The lookback window, defaulting to 30.</value>
/// <remarks>
/// <para><b>For Beginners:</b> How many past time steps the model looks at before
/// making a prediction. For daily data, 30 would mean looking at the past month.
/// </para>
/// </remarks>
public int LookbackWindow { get; set; } = 30;

/// <summary>
/// Gets or sets the forecast horizon (prediction length).
/// </summary>
/// <value>The forecast horizon, defaulting to 7.</value>
public int ForecastHorizon { get; set; } = 7;

/// <summary>
/// Gets or sets the hidden state size of the LSTM layers.
/// </summary>
/// <value>The hidden size, defaulting to 40.</value>
/// <remarks>
/// <para><b>For Beginners:</b> The capacity of the model's memory. Larger values
/// allow the model to remember more complex patterns but require more training data.
/// </para>
/// </remarks>
public int HiddenSize { get; set; } = 40;

/// <summary>
/// Gets or sets the number of LSTM layers.
/// </summary>
/// <value>The number of layers, defaulting to 2.</value>
public int NumLayers { get; set; } = 2;

/// <summary>
/// Gets or sets the dropout rate for regularization.
/// </summary>
/// <value>The dropout rate, defaulting to 0.1.</value>
/// <remarks>
/// <para><b>For Beginners:</b> Dropout helps prevent overfitting by randomly
/// ignoring some neurons during training. A value of 0.1 means 10% are ignored.
/// </para>
/// </remarks>
public double DropoutRate { get; set; } = 0.1;

/// <summary>
/// Gets or sets the learning rate for training.
/// </summary>
/// <value>The learning rate, defaulting to 0.001.</value>
public double LearningRate { get; set; } = 0.001;

/// <summary>
/// Gets or sets the number of training epochs.
/// </summary>
/// <value>The number of epochs, defaulting to 100.</value>
public int Epochs { get; set; } = 100;

/// <summary>
/// Gets or sets the batch size for training.
/// </summary>
/// <value>The batch size, defaulting to 32.</value>
public int BatchSize { get; set; } = 32;

/// <summary>
/// Gets or sets the number of samples to draw for probabilistic forecasts.
/// </summary>
/// <value>The number of samples, defaulting to 100.</value>
/// <remarks>
/// <para><b>For Beginners:</b> DeepAR generates multiple possible futures (samples)
/// to create prediction intervals. More samples give more accurate probability
/// estimates but take longer to compute. 100 is a good balance.
/// </para>
/// </remarks>
public int NumSamples { get; set; } = 100;

/// <summary>
/// Gets or sets the likelihood distribution type.
/// </summary>
/// <value>The likelihood type, defaulting to "Gaussian".</value>
/// <remarks>
/// <para>
/// Supported values: "Gaussian", "StudentT", "NegativeBinomial"
/// - Gaussian: For continuous data that can be negative (e.g., temperature, stock returns)
/// - StudentT: For continuous data with heavy tails (outliers)
/// - NegativeBinomial: For count data (e.g., number of sales, website visits)
/// </para>
/// <para><b>For Beginners:</b> This determines what kind of randomness the model assumes
/// in your data. Choose based on your data type:
/// - Gaussian (Normal): Most common, works for temperatures, prices, etc.
/// - StudentT: When you have occasional extreme outliers
/// - NegativeBinomial: When counting things (must be non-negative integers)
/// </para>
/// </remarks>
public string LikelihoodType { get; set; } = "Gaussian";

/// <summary>
/// Gets or sets the number of covariates (external features).
/// </summary>
/// <value>The covariate size, defaulting to 0.</value>
/// <remarks>
/// <para><b>For Beginners:</b> Covariates are additional features that might influence
/// your forecast, like holidays, promotions, weather, etc. Set this to the number
/// of such features you want to include.
/// </para>
/// </remarks>
public int CovariateSize { get; set; } = 0;

/// <summary>
/// Gets or sets the embedding dimension for categorical features.
/// </summary>
/// <value>The embedding dimension, defaulting to 10.</value>
/// <remarks>
/// <para><b>For Beginners:</b> If you have categorical features (like store ID,
/// product category), embeddings convert them into numerical representations
/// that the model can understand. This sets how many dimensions to use.
/// </para>
/// </remarks>
public int EmbeddingDimension { get; set; } = 10;
}
104 changes: 104 additions & 0 deletions src/Models/Options/InformerOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;

namespace AiDotNet.Models.Options;

/// <summary>
/// Configuration options for the Informer model (Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting).
/// </summary>
/// <typeparam name="T">The numeric type used for calculations (typically double or float).</typeparam>
/// <remarks>
/// <para>
/// Informer addresses the computational complexity challenges of vanilla Transformers for long-sequence forecasting.
/// Key innovations include:
/// - ProbSparse self-attention mechanism (O(L log L) complexity instead of O(L²))
/// - Self-attention distilling for efficient stacking
/// - Generative style decoder for one-forward prediction
/// </para>
/// <para><b>For Beginners:</b> Informer is an efficient version of the Transformer architecture
/// designed specifically for long time series. Traditional transformers become very slow with long sequences,
/// but Informer uses smart tricks to be much faster while maintaining accuracy. It's particularly
/// good for forecasting that requires looking far back in history (like predicting next month based on
/// the past year).
/// </para>
/// </remarks>
public class InformerOptions<T> : TimeSeriesRegressionOptions<T>
{
public InformerOptions() { }

public InformerOptions(InformerOptions<T> other)
{
if (other == null) throw new ArgumentNullException(nameof(other));
LookbackWindow = other.LookbackWindow;
ForecastHorizon = other.ForecastHorizon;
EmbeddingDim = other.EmbeddingDim;
NumEncoderLayers = other.NumEncoderLayers;
NumDecoderLayers = other.NumDecoderLayers;
NumAttentionHeads = other.NumAttentionHeads;
DropoutRate = other.DropoutRate;
LearningRate = other.LearningRate;
Epochs = other.Epochs;
BatchSize = other.BatchSize;
DistillingFactor = other.DistillingFactor;
}

/// <summary>
/// Gets or sets the lookback window (encoder input length).
/// </summary>
public int LookbackWindow { get; set; } = 96;

/// <summary>
/// Gets or sets the forecast horizon (decoder output length).
/// </summary>
public int ForecastHorizon { get; set; } = 24;

/// <summary>
/// Gets or sets the embedding dimension.
/// </summary>
public int EmbeddingDim { get; set; } = 512;

/// <summary>
/// Gets or sets the number of encoder layers.
/// </summary>
public int NumEncoderLayers { get; set; } = 2;

/// <summary>
/// Gets or sets the number of decoder layers.
/// </summary>
public int NumDecoderLayers { get; set; } = 1;

/// <summary>
/// Gets or sets the number of attention heads.
/// </summary>
public int NumAttentionHeads { get; set; } = 8;

/// <summary>
/// Gets or sets the dropout rate.
/// </summary>
public double DropoutRate { get; set; } = 0.05;

/// <summary>
/// Gets or sets the learning rate.
/// </summary>
public double LearningRate { get; set; } = 0.0001;

/// <summary>
/// Gets or sets the number of training epochs.
/// </summary>
public int Epochs { get; set; } = 100;

/// <summary>
/// Gets or sets the batch size.
/// </summary>
public int BatchSize { get; set; } = 32;

/// <summary>
/// Gets or sets the distilling factor for self-attention distilling.
/// </summary>
/// <remarks>
/// <para><b>For Beginners:</b> This controls how much the model compresses
/// information between layers. A factor of 2 means each layer has half
/// the sequence length of the previous one.
/// </para>
/// </remarks>
public int DistillingFactor { get; set} = 2;

Check failure on line 103 in src/Models/Options/InformerOptions.cs

View workflow job for this annotation

GitHub Actions / Build All Frameworks

{ or ; or => expected

Check failure on line 103 in src/Models/Options/InformerOptions.cs

View workflow job for this annotation

GitHub Actions / Publish Size Analysis

{ or ; or => expected

Check failure on line 103 in src/Models/Options/InformerOptions.cs

View workflow job for this annotation

GitHub Actions / Publish Size Analysis

{ or ; or => expected
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.
}
Loading
Loading