Table of Contents

Class TimeSeriesHelper<T>

Namespace
AiDotNet.Helpers
Assembly
AiDotNet.dll

Provides helper methods for time series analysis and forecasting.

public static class TimeSeriesHelper<T>

Type Parameters

T

The numeric type used in calculations (e.g., double, float).

Inheritance
TimeSeriesHelper<T>
Inherited Members

Remarks

For Beginners: Time series analysis is a technique used to analyze data points collected over time to identify patterns and predict future values. This is commonly used for forecasting trends like stock prices, weather patterns, or sales data.

Methods

CalculateARResiduals(Vector<T>, Vector<T>)

Calculates the residuals (errors) of an Autoregressive (AR) model.

public static Vector<T> CalculateARResiduals(Vector<T> y, Vector<T> arCoefficients)

Parameters

y Vector<T>

The original time series data.

arCoefficients Vector<T>

The AR model coefficients.

Returns

Vector<T>

The residuals (differences between actual and predicted values).

Remarks

For Beginners: Residuals are the differences between what your model predicted and what actually happened. They tell you how accurate your model is. Small residuals mean your model is making good predictions. Analyzing residuals can help you improve your model or detect patterns your model missed.

CalculateAutoCorrelation(Vector<T>, int)

Calculates the autocorrelation of a time series at a specific lag.

public static T CalculateAutoCorrelation(Vector<T> y, int lag)

Parameters

y Vector<T>

The time series data.

lag int

The lag (time shift) to calculate autocorrelation for.

Returns

T

The autocorrelation value at the specified lag.

Remarks

For Beginners: Autocorrelation measures how similar a time series is to a delayed version of itself. A high autocorrelation at lag=1 means that if today's value is high, tomorrow's value is likely to be high too. This helps identify patterns in your data. For example, temperature readings often have high autocorrelation at lag=24 hours because temperatures follow a daily cycle.

CalculateMultipleAutoCorrelation(Vector<T>, int)

Calculates the autocorrelation function (ACF) of a time series for lags 0 through maxLag.

public static Vector<T> CalculateMultipleAutoCorrelation(Vector<T> y, int maxLag)

Parameters

y Vector<T>

The time series data.

maxLag int

The maximum lag to calculate autocorrelation for.

Returns

Vector<T>

A vector of autocorrelation values for lags 0 through maxLag.

Remarks

For Beginners: The autocorrelation function shows how similar a time series is to time-shifted versions of itself. This helps identify patterns like trends or seasonality. For example, daily temperature data might show high autocorrelation at lag=24 hours, indicating a daily cycle in temperatures.

DifferenceSeries(Vector<T>, int)

Computes the differences between consecutive values in a time series.

public static Vector<T> DifferenceSeries(Vector<T> y, int d)

Parameters

y Vector<T>

The original time series data.

d int

The order of differencing (how many times to apply the difference operation).

Returns

Vector<T>

The differenced time series.

Remarks

For Beginners: Differencing helps make a time series stationary by removing trends or seasonal patterns. First-order differencing (d=1) calculates the change between consecutive values. For example, if your data is [10, 13, 15, 19], first-order differencing gives [3, 2, 4], representing how much each value increased from the previous one.

EstimateARCoefficients(Vector<T>, int, MatrixDecompositionType)

Estimates the coefficients for an Autoregressive (AR) model.

public static Vector<T> EstimateARCoefficients(Vector<T> y, int p, MatrixDecompositionType decompositionType)

Parameters

y Vector<T>

The time series data.

p int

The order of the AR model (number of past values to consider).

decompositionType MatrixDecompositionType

The matrix decomposition method to use for solving the system.

Returns

Vector<T>

The estimated AR coefficients.

Remarks

For Beginners: An Autoregressive (AR) model predicts future values based on past values. The parameter 'p' determines how many past values to consider. For example, with p=2, we use the previous two values to predict the next value. The coefficients tell us how much weight to give each past value in our prediction. This is like saying "tomorrow's temperature depends 70% on today's temperature and 30% on yesterday's temperature."

EstimateMACoefficients(Vector<T>, int)

Estimates the coefficients for a Moving Average (MA) model.

public static Vector<T> EstimateMACoefficients(Vector<T> residuals, int q)

Parameters

residuals Vector<T>

The residuals from a previous model (often an AR model).

q int

The order of the MA model (number of past errors to consider).

Returns

Vector<T>

The estimated MA coefficients.

Remarks

For Beginners: A Moving Average (MA) model predicts future values based on past prediction errors. While AR models use past actual values, MA models use past mistakes in predictions. The parameter 'q' determines how many past errors to consider. This helps capture random shocks or unexpected events in your data that might affect future values.