Table of Contents

Class NeuralNetworkARIMAModel<T>

Namespace
AiDotNet.TimeSeries
Assembly
AiDotNet.dll

Represents a Neural Network ARIMA (Autoregressive Integrated Moving Average) model for time series forecasting.

public class NeuralNetworkARIMAModel<T> : TimeSeriesModelBase<T>, ITimeSeriesModel<T>, IFullModel<T, Matrix<T>, Vector<T>>, IModel<Matrix<T>, Vector<T>, ModelMetadata<T>>, IModelSerializer, ICheckpointableModel, IParameterizable<T, Matrix<T>, Vector<T>>, IFeatureAware, IFeatureImportance<T>, ICloneable<IFullModel<T, Matrix<T>, Vector<T>>>, IGradientComputable<T, Matrix<T>, Vector<T>>, IJitCompilable<T>

Type Parameters

T

The numeric type used for calculations, typically float or double.

Inheritance
NeuralNetworkARIMAModel<T>
Implements
IFullModel<T, Matrix<T>, Vector<T>>
IModel<Matrix<T>, Vector<T>, ModelMetadata<T>>
IParameterizable<T, Matrix<T>, Vector<T>>
ICloneable<IFullModel<T, Matrix<T>, Vector<T>>>
IGradientComputable<T, Matrix<T>, Vector<T>>
Inherited Members
Extension Methods

Remarks

This class combines traditional ARIMA modeling with neural networks to create a hybrid model for time series forecasting. It incorporates both linear (ARIMA) and non-linear (neural network) components to capture complex patterns in the data.

For Beginners: This model is like a super-powered crystal ball for predicting future values in a sequence of data.

Imagine you're trying to predict tomorrow's temperature:

  • The ARIMA part looks at recent temperatures and how they've been changing.
  • The Neural Network part can spot complex patterns, like how weekends or holidays might affect temperature.

By combining these two approaches, this model can make more accurate predictions than either method alone. It's especially useful for data that changes over time, like stock prices, weather patterns, or sales figures.

Constructors

NeuralNetworkARIMAModel(NeuralNetworkARIMAOptions<T>?)

Initializes a new instance of the NeuralNetworkARIMAModel<T> class.

public NeuralNetworkARIMAModel(NeuralNetworkARIMAOptions<T>? options = null)

Parameters

options NeuralNetworkARIMAOptions<T>

The options for configuring the Neural Network ARIMA model. If null, default options are used.

Remarks

This constructor sets up the Neural Network ARIMA model with the specified options or default values. It initializes the optimizer, neural network, and other necessary components for the model.

For Beginners: This is like setting up your prediction tool before you start using it.

You can customize how the model works by providing options, or let it use default settings:

  • It prepares the mathematical tools (optimizer) that help the model learn from data.
  • It sets up the neural network, which is like the "brain" of the model.
  • It initializes empty containers to store important information as the model learns.

Think of it as assembling and configuring your crystal ball before you start making predictions.

Properties

IsOptimized

Gets whether parameter optimization succeeded during the most recent training run.

public bool IsOptimized { get; }

Property Value

bool

Remarks

When OptimizeParameters is disabled or optimization fails, this value is false.

SupportsJitCompilation

Gets whether this model supports JIT compilation.

public override bool SupportsJitCompilation { get; }

Property Value

bool

Returns true when the model has valid AR/MA parameters. JIT compilation combines ARIMA linear terms with average neural network contribution.

Remarks

For Beginners: This hybrid model can be JIT compiled by: 1. Representing ARIMA as a linear combination (weights @ lags) 2. Adding the average neural network contribution The approximation is suitable for inference speedup.

Methods

ApplyParameters(Vector<T>)

Applies the provided parameters to the model.

protected override void ApplyParameters(Vector<T> parameters)

Parameters

parameters Vector<T>

The vector of parameters to apply.

Remarks

This method applies the provided parameter values to the model, updating its internal state to reflect the new parameters. The implementation is model-specific and should be overridden by derived classes as needed.

For Beginners: This method updates the model's internal parameters with new values. It's the counterpart to GetParameters and should understand the parameter vector in exactly the same way.

For example, if the first 5 elements of the parameters vector represent lag coefficients, this method should apply them as lag coefficients in the model's internal structure.

Exceptions

ArgumentException

Thrown when the parameters vector is invalid.

CreateInstance()

Creates a new instance of the Neural Network ARIMA model with the same configuration.

protected override IFullModel<T, Matrix<T>, Vector<T>> CreateInstance()

Returns

IFullModel<T, Matrix<T>, Vector<T>>

A new instance of the Neural Network ARIMA model.

Remarks

This method creates a clone of the model with the same configuration but without any trained parameters. It's useful for creating multiple models with the same structure for ensembling or cross-validation.

For Beginners: This creates a fresh copy of your model.

Think of it like making a photocopy of a blank form:

  • It has the same structure and fields as your original
  • But it doesn't have any of the information filled in

This is useful when you want to train several similar models with different data, or when you want to start over without changing your model's basic setup.

DeserializeCore(BinaryReader)

Deserializes the core components of the model from a binary reader.

protected override void DeserializeCore(BinaryReader reader)

Parameters

reader BinaryReader

The binary reader to read the serialized data from.

Remarks

This method reconstructs the model from saved data: - Reads AR and MA parameters - Reconstructs the neural network - Restores model configuration options After this process, the model is ready to make predictions, just as it was before serialization.

For Beginners: This method is like unpacking and rebuilding your model from storage.

Continuing the LEGO analogy:

  1. You read the list of pieces you used (AR and MA parameters)
  2. You look at the saved picture to rebuild the structure (neural network parameters)
  3. You follow the special instructions to set it up correctly (configuration options)

After this process, your model is back to its original state, ready to make predictions again.

EvaluateModel(Matrix<T>, Vector<T>)

Evaluates the model's performance using various metrics.

public override Dictionary<string, T> EvaluateModel(Matrix<T> xTest, Vector<T> yTest)

Parameters

xTest Matrix<T>

The input matrix for testing.

yTest Vector<T>

The actual output vector for testing.

Returns

Dictionary<string, T>

A dictionary containing various performance metrics.

Remarks

This method calculates several common metrics to assess the model's prediction accuracy: - Mean Absolute Error (MAE) - Mean Squared Error (MSE) - Root Mean Squared Error (RMSE) - R-squared (R2) These metrics provide different perspectives on how well the model's predictions match the actual values.

For Beginners: This method is like giving your model a report card.

It calculates different ways to measure how accurate your predictions are:

  • MAE: On average, how far off are your predictions? (Like missing the bullseye by 2 inches on average)
  • MSE: Similar to MAE, but punishes big mistakes more (Like squaring the distance from the bullseye)
  • RMSE: The square root of MSE, making it easier to interpret (Back to inches from the bullseye)
  • R2: How much of the data's variation does your model explain? (Perfect is 1, terrible is 0)

These numbers help you understand if your model is doing a good job and compare it to other models.

ExportComputationGraph(List<ComputationNode<T>>)

Exports the Neural Network ARIMA model as a computation graph for JIT compilation.

public override ComputationNode<T> ExportComputationGraph(List<ComputationNode<T>> inputNodes)

Parameters

inputNodes List<ComputationNode<T>>

A list to which input nodes will be added.

Returns

ComputationNode<T>

The output computation node representing the forecast.

Remarks

The computation graph represents: forecast = AR_weights @ lags + MA_weights @ residuals + avg_nn_contribution

GetModelMetadata()

Gets metadata about the model, including type, parameters, and configuration.

public override ModelMetadata<T> GetModelMetadata()

Returns

ModelMetadata<T>

A ModelMetaData object containing information about the model.

Remarks

This method provides information about the model's configuration and state. It includes details such as the model type, parameters, and training status.

For Beginners: This provides a summary or "fact sheet" about your model.

It tells you important information about your model, such as:

  • What type of model it is
  • What parameters it's using
  • Whether it's been trained yet
  • How it's configured

It's like getting a specification sheet for a car, telling you its make, model, engine size, and features.

Predict(Matrix<T>)

Predicts values for the given input data.

public override Vector<T> Predict(Matrix<T> input)

Parameters

input Matrix<T>

The input matrix containing features or past values.

Returns

Vector<T>

A vector of predicted values.

Remarks

This method generates predictions for each row in the input matrix. It uses both the ARIMA components and the neural network to make predictions.

For Beginners: This is where your model makes its predictions.

For each set of input data:

  1. The model looks at the input (like today's weather for predicting tomorrow's)
  2. It uses its learned patterns (from ARIMA and the neural network) to make a guess
  3. It adds this guess to a list of predictions

At the end, you get a list of predictions, one for each input set you provided. It's like a weather forecaster making predictions for each day of the coming week.

PredictSingle(Vector<T>)

Predicts a single value for the given input vector.

public override T PredictSingle(Vector<T> input)

Parameters

input Vector<T>

The input vector containing features or past values.

Returns

T

A single predicted value.

Remarks

This method generates a single prediction based on the input vector. It uses both the ARIMA components and the neural network to make the prediction.

For Beginners: This is a simplified way to get just one prediction.

Instead of providing a whole table of inputs and getting many predictions back, you provide just one row of inputs and get back a single prediction.

It's like asking the weather forecaster for just tomorrow's forecast instead of the whole week's weather outlook.

SerializeCore(BinaryWriter)

Serializes the core components of the model to a binary writer.

protected override void SerializeCore(BinaryWriter writer)

Parameters

writer BinaryWriter

The binary writer to write the serialized data to.

Remarks

This method saves the essential parts of the model: - AR and MA parameters - Neural network parameters - Model configuration options This allows the model to be saved and later reconstructed exactly as it was.

For Beginners: This method is like packing up your model for storage or travel.

Imagine you've built a complex LEGO structure and want to store it:

  1. You write down the exact pieces you used (AR and MA parameters)
  2. You save a picture of how it's put together (neural network parameters)
  3. You note any special instructions for rebuilding it (configuration options)

This way, you or someone else can rebuild the exact same model later, even on a different computer.

SetParameters(Vector<T>)

Sets the parameters for this model.

public override void SetParameters(Vector<T> parameters)

Parameters

parameters Vector<T>

A vector containing the model parameters.

TrainCore(Matrix<T>, Vector<T>)

Core implementation of the training process for the Neural Network ARIMA model.

protected override void TrainCore(Matrix<T> x, Vector<T> y)

Parameters

x Matrix<T>

The input matrix containing features or past values.

y Vector<T>

The target vector containing the values to be predicted.

Remarks

This is the internal implementation of the model training process, handling the details of parameter initialization, optimization, and residual computation.

For Beginners: This is the engine room of the training process.

While the public Train method handles validation and setup, this method does the actual work:

  1. It saves the target values for later use
  2. It sets up the initial parameters
  3. It runs the optimization process to find the best parameters
  4. It computes how much error the model still has after training

It's like the detailed instruction manual for building a complex model, while the public Train method is the simplified overview.