Skip to content

HMath.TimeSeries.Models

Module index · Numerical conventions

Description

Bounded Double forecasting models. AR fits use checked QR least squares. ARMA/SARIMA minimize conditional sum of squares, with presample observations and innovations set to zero, using analytic innovation derivatives and damped Levenberg--Marquardt. These are local conditional fits, not exact Gaussian maximum likelihood; stationarity/invertibility and prediction intervals are not inferred. Differencing is integrated explicitly when forecasting.

On this page

API Purpose
Smoothing Exponential smoothing: Simple alpha; Holt alpha beta; HoltWinters period alpha beta gamma.
Simple Declaration and type contract below.
Holt Declaration and type contract below.
HoltWinters Declaration and type contract below.
smoothForecast Fitted one-step means and future means.
Decomposition Additive reconstruction is trend+seasonal+remainder at every input index.
Decomposition Declaration and type contract below.
trendComponent Estimated trend values aligned with original observations.
seasonalComponent Estimated seasonal values aligned with original observations.
remainderComponent Residual values after subtracting trend and seasonality.
decompose Classical additive decomposition with local linear trend smoothing and centered phase means.
STLConfig Seasonal period,odd LOESS windows,and inner/robust iteration counts for STL decomposition.
STLConfig Declaration and type contract below.
stlPeriod Positive seasonal cycle length in observations.
stlSeasonalWindow Odd LOESS window for seasonal subseries.
stlTrendWindow Odd LOESS window for trend smoothing.
stlLowPassWindow Odd low-pass LOESS smoothing window.
stlInnerIterations Number of STL seasonal/trend backfitting passes.
stlRobustIterations Number of robust outer reweighting passes; zero disables robust reweighting.
stl Cleveland-style STL reference backfitting: smooth seasonal subseries by degree-one tricube LOESS with one-cycle extrapolation; remove a period, period, three-point moving-average low-pass followed by LOESS, then smooth the deseasonalized trend.
defaultSTLConfig Given seasonal period, construct STL options with seasonal window 7, odd trend window above 2*period, odd low-pass window at/above period, two inner iterations and no robust outer iterations. stl validates the resulting configuration.
ARModel Intercept followed by lag coefficients; observations stored chronologically.
fitAR Given AR order then finite chronological samples, fit intercept and lag coefficients by checked OLS.
arCoefficients Return AR intercept followed by lag-1 through lag-p coefficients.
forecastAR Given horizon in [0,16384] then fitted AR model, recursively forecast future samples from latest observations.
SARIMAOrder Ordinary (p,d,q),seasonal (P,D,Q),and cycle period s. fitSARIMA validates supported order/sample budgets.
SARIMAOrder Declaration and type contract below.
arOrder Ordinary autoregressive order p.
differenceOrder Ordinary differencing order d.
maOrder Ordinary moving-average order q.
seasonalAROrder Seasonal autoregressive order P.
seasonalDifferenceOrder Seasonal differencing order D.
seasonalMAOrder Seasonal moving-average order Q.
seasonalPeriod Seasonal cycle length s used to place seasonal polynomial lags.
ARIMAModel Opaque fitted ARIMA/SARIMA state with differencing,parameters,innovation residuals,and original history for forecasting.
fitARIMA Given optimization options,p,d,q,then finite chronological series, fit nonseasonal ARIMA through fitSARIMA with seasonal orders zero.
fitMA Given optimization options,MA order q,then samples, fit ARIMA(0,0,q).
fitARMA Given optimization options,AR order p,MA order q,then samples, fit ARIMA(p,0,q).
fitSARIMA Parameters are intercept, ordinary AR, ordinary MA, seasonal AR, seasonal MA.
arimaParameters Return fitted intercept,ordinary AR,ordinary MA,seasonal AR,seasonal MA parameters in that order.
arimaResiduals Return fitted innovation residuals in chronological order, on the model's differenced process.
arimaInnovationVariance Return fitted innovation-variance estimate stored in an ARIMA/SARIMA model.
forecastARIMA Given horizon in [0,16384] then fitted ARIMA/SARIMA model, forecast recursively with future innovations set to zero and undo ordinary/seasonal differencing.
VARModel Opaque fitted vector autoregression with intercept/lag coefficients and chronological multivariate history.
fitVAR Given lag order then chronological multivariate rows, fit response-wise OLS with intercept and lag-major features.
varCoefficients Rows are response components, columns are intercept then lag-major predictors.
forecastVAR Given horizon then VAR model, recursively return future multivariate observation rows.
kalmanSeries Reuse the checked Joseph-form linear Kalman update for each complete observation.

Documentation

Smoothing

data Smoothing Source #

Exponential smoothing: Simple alpha; Holt alpha beta; HoltWinters period alpha beta gamma. Rates lie in [0,1] and seasonal fitting requires complete initial cycles.

Instances

Instances details
Show Smoothing Source # 
Instance details

Defined in HMath.TimeSeries.Models

Eq Smoothing Source # 
Instance details

Defined in HMath.TimeSeries.Models

smoothForecast

smoothForecast :: Smoothing -> Int -> [Double] -> Either MathError ([Double], [Double]) Source #

Fitted one-step means and future means. Simple/Holt initialize from the first sample/first difference. Additive Holt--Winters initializes the level and seasonal indices from a complete first cycle, and the trend from the difference between the first two cycle means. Initial fitted cycle is the initializer, not an out-of-sample prediction.

Decomposition

data Decomposition Source #

Additive reconstruction is trend+seasonal+remainder at every input index.

Constructors

Decomposition 

Fields

Instances

Instances details
Show Decomposition Source # 
Instance details

Defined in HMath.TimeSeries.Models

Eq Decomposition Source # 
Instance details

Defined in HMath.TimeSeries.Models

decompose

decompose :: Int -> [Double] -> Either MathError Decomposition Source #

Classical additive decomposition with local linear trend smoothing and centered phase means. Requires at least two complete periods.

STLConfig

data STLConfig Source #

Seasonal period,odd LOESS windows,and inner/robust iteration counts for STL decomposition. Use defaultSTLConfig then checked record updates.

Constructors

STLConfig 

Fields

Instances

Instances details
Show STLConfig Source # 
Instance details

Defined in HMath.TimeSeries.Models

Eq STLConfig Source # 
Instance details

Defined in HMath.TimeSeries.Models

stl

stl :: STLConfig -> [Double] -> Either MathError Decomposition Source #

Cleveland-style STL reference backfitting: smooth seasonal subseries by degree-one tricube LOESS with one-cycle extrapolation; remove a period, period, three-point moving-average low-pass followed by LOESS, then smooth the deseasonalized trend. Optional bisquare robust outer iterations use six times median absolute residual. Every index is evaluated (no jump shortcut). See https://search.r-project.org/R/refmans/stats/html/stl.html .

defaultSTLConfig

defaultSTLConfig :: Int -> STLConfig Source #

Given seasonal period, construct STL options with seasonal window 7, odd trend window above 2*period, odd low-pass window at/above period, two inner iterations and no robust outer iterations. stl validates the resulting configuration.

ARModel

data ARModel Source #

Intercept followed by lag coefficients; observations stored chronologically.

Instances

Instances details
Show ARModel Source # 
Instance details

Defined in HMath.TimeSeries.Models

Eq ARModel Source # 
Instance details

Defined in HMath.TimeSeries.Models

Methods

(==) :: ARModel -> ARModel -> Bool #

(/=) :: ARModel -> ARModel -> Bool #

fitAR

fitAR :: Int -> [Double] -> Either MathError ARModel Source #

Given AR order then finite chronological samples, fit intercept and lag coefficients by checked OLS. Require order in [0,64], <=4096 samples and more than 2*order+1 observations; invalid/ill-conditioned fits fail.

arCoefficients

arCoefficients :: ARModel -> [Double] Source #

Return AR intercept followed by lag-1 through lag-p coefficients. The model retains observations chronologically for forecastAR.

forecastAR

forecastAR :: Int -> ARModel -> Either MathError [Double] Source #

Given horizon in [0,16384] then fitted AR model, recursively forecast future samples from latest observations. Zero horizon returns []; invalid horizon or non-finite predictions fail.

SARIMAOrder

data SARIMAOrder Source #

Ordinary (p,d,q),seasonal (P,D,Q),and cycle period s. fitSARIMA validates supported order/sample budgets.

Constructors

SARIMAOrder 

Fields

Instances

Instances details
Show SARIMAOrder Source # 
Instance details

Defined in HMath.TimeSeries.Models

Eq SARIMAOrder Source # 
Instance details

Defined in HMath.TimeSeries.Models

ARIMAModel

data ARIMAModel Source #

Opaque fitted ARIMA/SARIMA state with differencing,parameters,innovation residuals,and original history for forecasting.

Instances

Instances details
Show ARIMAModel Source # 
Instance details

Defined in HMath.TimeSeries.Models

Eq ARIMAModel Source # 
Instance details

Defined in HMath.TimeSeries.Models

fitARIMA

fitARIMA :: OptimizeOptions -> Int -> Int -> Int -> [Double] -> Either MathError ARIMAModel Source #

Given optimization options,p,d,q,then finite chronological series, fit nonseasonal ARIMA through fitSARIMA with seasonal orders zero. Invalid order/sample bounds, unstable or nonconvergent/ill-conditioned fit returns Left MathError.

fitMA

fitMA :: OptimizeOptions -> Int -> [Double] -> Either MathError ARIMAModel Source #

Given optimization options,MA order q,then samples, fit ARIMA(0,0,q). Ordersampleoptimization errors propagate from fitARIMA.

fitARMA

fitARMA :: OptimizeOptions -> Int -> Int -> [Double] -> Either MathError ARIMAModel Source #

Given optimization options,AR order p,MA order q,then samples, fit ARIMA(p,0,q). Invalid or nonconvergent fits return Left MathError.

fitSARIMA

fitSARIMA :: OptimizeOptions -> SARIMAOrder -> [Double] -> Either MathError ARIMAModel Source #

Parameters are intercept, ordinary AR, ordinary MA, seasonal AR, seasonal MA. Multiplicative seasonal polynomials include cross-lag interactions. Intercept always belongs to the differenced process. Caller supplies fit budgets; exhausted or ill-conditioned fits return MathError.

arimaParameters

arimaParameters :: ARIMAModel -> [Double] Source #

Return fitted intercept,ordinary AR,ordinary MA,seasonal AR,seasonal MA parameters in that order. Intercept belongs to the differenced process.

arimaResiduals

arimaResiduals :: ARIMAModel -> [Double] Source #

Return fitted innovation residuals in chronological order, on the model's differenced process.

arimaInnovationVariance

arimaInnovationVariance :: ARIMAModel -> Double Source #

Return fitted innovation-variance estimate stored in an ARIMA/SARIMA model.

forecastARIMA

forecastARIMA :: Int -> ARIMAModel -> Either MathError [Double] Source #

Given horizon in [0,16384] then fitted ARIMA/SARIMA model, forecast recursively with future innovations set to zero and undo ordinary/seasonal differencing. Invalid horizon or non-finite predictions fail.

VARModel

data VARModel Source #

Opaque fitted vector autoregression with intercept/lag coefficients and chronological multivariate history.

Instances

Instances details
Show VARModel Source # 
Instance details

Defined in HMath.TimeSeries.Models

Eq VARModel Source # 
Instance details

Defined in HMath.TimeSeries.Models

fitVAR

fitVAR :: Int -> [[Double]] -> Either MathError VARModel Source #

Given lag order then chronological multivariate rows, fit response-wise OLS with intercept and lag-major features. Require finite rectangular data, dimensions<=16, rows<=2048, order in [1,16], sufficient samples and <=20000000 fitting work. Invalid/ill-conditioned fits fail.

varCoefficients

varCoefficients :: VARModel -> [[Double]] Source #

Rows are response components, columns are intercept then lag-major predictors.

forecastVAR

forecastVAR :: Int -> VARModel -> Either MathError [[Double]] Source #

Given horizon then VAR model, recursively return future multivariate observation rows. Require horizon in [0,16384] and horizon*components<=262144; invalid bounds or non-finite predictions fail.

kalmanSeries

kalmanSeries :: [[Double]] -> [[Double]] -> [[Double]] -> [[Double]] -> GaussianState -> [[Double]] -> Either MathError [GaussianState] Source #

Reuse the checked Joseph-form linear Kalman update for each complete observation. Returns posterior states, excluding the caller's initial state.