RNNTestForecasting

scalation.modeling.autograd.RNNTestForecasting

The RNNTestForecasting object provides a suite of time–series utilities and forecasting experiments using Autograd–based recurrent neural networks. It includes:

  • lagged–window matrix builders (buildMatrix4TS, buildMatrix4TSX)
  • batch construction utilities for sequence models (makeBatches)
  • demonstration tests for RNN and GRU models on: • synthetic sequences • COVID–19 new-deaths data • ILI (Influenza-Like Illness) data
  • chronological train/test splits
  • rolling / walk–forward validation These tests verify correctness of data pipelines, shape handling, training loops, scaling transformations, and forecasting performance.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def buildMatrix4TS(y: VectorD, lags: Int, hh: Int, backcast: Boolean = ...): (MatrixD, MatrixD)

Build lagged feature matrix and horizon-ahead target matrix for univariate time–series forecasting.

Build lagged feature matrix and horizon-ahead target matrix for univariate time–series forecasting.

Value parameters

backcast

if true, constructs backward windows for reconstruction tests

hh

forecast horizon (steps ahead)

lags

number of past time steps used as model input

y

the raw input series

Attributes

Returns

a tuple (x, yy) where: - x is the lagged matrix (windows × features) - yy is the horizon-matrix aligned with x

def buildMatrix4TSX(y: VectorD, xe: MatrixD, lags: Int, hh: Int, backcast: Boolean = ..., isTest: Boolean = ...): (MatrixD, MatrixD)

Build lagged feature matrix for time-series with exogenous inputs.

Build lagged feature matrix for time-series with exogenous inputs.

Value parameters

backcast

whether to generate backward windows

hh

forecast horizon

isTest

if true, skip alignment trimming

lags

number of lagged steps to include

xe

exogenous variables (matrix)

y

endogenous (target) series

Attributes

Returns

(x_trim, yy_trim) aligned lagged feature + horizon matrices

def gruCovidTest(): Unit

Forecast COVID-19 new deaths using a single-layer GRU.

Forecast COVID-19 new deaths using a single-layer GRU.

Run:

runMain scalation.modeling.autograd.gruCovidTest

Attributes

def gruCovidTest2(): Unit

GRU forecasting with chronological split on either COVID or ILI datasets. Uses:

GRU forecasting with chronological split on either COVID or ILI datasets. Uses:

  • log transform + scaling
  • validation-based LR scheduling (ReduceLROnPlateau)
  • truncated backprop (TBPTT) option in GRU.forward
  • full diagnostics and plots for predictions Run:

runMain scalation.modeling.autograd.gruCovidTest2

Attributes

def gruSineTest(): Unit

GRU toy example trained on a noisy sine wave. Demonstrates:

GRU toy example trained on a noisy sine wave. Demonstrates:

  • GRUCell correctness in forecasting a smooth periodic signal
  • batching, training, clipping, plotting Run:

runMain scalation.modeling.autograd.gruSineTest

Attributes

def makeBatches(xSeq: MatrixD, ySeq: MatrixD, batchSize: Int, nFeatures: Int = ...): IndexedSeq[(IndexedSeq[Variabl], Variabl)]

Convert lagged matrices into mini-batches suitable for RNN/GRU models. Splits the dataset into batches, converts each window into an ordered input sequence (X_t0, X_t1, ..., X_tn) and attaches the corresponding target tensor for supervised sequence forecasting.

Convert lagged matrices into mini-batches suitable for RNN/GRU models. Splits the dataset into batches, converts each window into an ordered input sequence (X_t0, X_t1, ..., X_tn) and attaches the corresponding target tensor for supervised sequence forecasting.

Value parameters

batchSize

batch size for training

nFeatures

number of features at each time step (default = 1)

xSeq

full lagged input matrix

ySeq

horizon target matrix

Attributes

Returns

an indexed sequence of (inputSeq, target) batch pairs

def rnnCovidTest(): Unit

Forecast COVID-19 weekly new deaths using a single-layer RNN. Pipeline: 1. load + scale the dataset 2. convert into lagged windows 3. batch for RNN input 4. train with Adam + StepLR 5. compute QoF metrics (R², SMAPE, MAE, RMSE) 6. plot predictions & training loss Run:

Forecast COVID-19 weekly new deaths using a single-layer RNN. Pipeline: 1. load + scale the dataset 2. convert into lagged windows 3. batch for RNN input 4. train with Adam + StepLR 5. compute QoF metrics (R², SMAPE, MAE, RMSE) 6. plot predictions & training loss Run:

runMain scalation.modeling.autograd.rnnCovidTest

Attributes

def rnnCovidTest1(): Unit

Chronological (or Temporal) train/test split forecasting using RNN. Features:

Chronological (or Temporal) train/test split forecasting using RNN. Features:

  • Temporal holdout (e.g., first 80% train, remaining test)
  • adaptive learning rate via ReduceLROnPlateau
  • early stopping
  • rescaling predictions back to original space
  • complete QoF metrics for train & test Run:

runMain scalation.modeling.autograd.rnnCovidTest1

Attributes

def rnnCovidTest2(): Unit

Chronological split forecasting with:

Chronological split forecasting with:

  • log → scale → train → unscale → exp transform pipeline
  • validation set carved out of training windows
  • ReduceLROnPlateau for LR scheduling
  • early stopping based on validation loss Supports both COVID and ILI depending on loaded dataset. Run:

runMain scalation.modeling.autograd.rnnCovidTest2

Attributes

def rnnCovidTestRollVal(): Unit

Walk-forward (rolling) validation: 1-step-ahead forecasting. Each fold:

Walk-forward (rolling) validation: 1-step-ahead forecasting. Each fold:

  • trains (or reuses) the RNN on all available data up to time t
  • predicts the next point t+1
  • logs QoF metrics Supports growing or rolling windows and periodic retraining. Run:

runMain scalation.modeling.autograd.rnnCovidTestRollVal

Attributes

def rnnILITest(): Unit

Forecast ILI (Influenza-Like Illness) incidence using a single-layer RNN. Similar to the COVID test but uses a longer lag window (21 weeks). Includes scaling, batching, training with Adam + StepLR, diagnostics and plots. Run:

Forecast ILI (Influenza-Like Illness) incidence using a single-layer RNN. Similar to the COVID test but uses a longer lag window (21 weeks). Includes scaling, batching, training with Adam + StepLR, diagnostics and plots. Run:

runMain scalation.modeling.autograd.rnnILITest

Attributes

def rnnUtilityTest(): Unit

Test utility functions used for RNN forecasting:

Test utility functions used for RNN forecasting:

  • lag construction
  • horizon matrix construction
  • batch formatting into proper RNN tensors Demonstrates window creation for a simple synthetic series. Run using:

runMain scalation.modeling.autograd.rnnUtilityTest

Attributes