varmlp: Artificial Neural Network VAR (Vector Auto-Regressive) model...

View source: R/modules.R

varmlpR Documentation

Artificial Neural Network VAR (Vector Auto-Regressive) model using a MultiLayer Perceptron, with the sigmoid activation function. The optimization algorithm is based on the stochastic gradient descent.

Description

Artificial Neural Network VAR (Vector Auto-Regressive) model using a MultiLayer Perceptron, with the sigmoid activation function. The optimization algorithm is based on the stochastic gradient descent.

Usage

varmlp(
  df,
  lag,
  sizeOfHLayers,
  iters = 50,
  learningRate = 0.01,
  algo = "sgd",
  batch_size = 10,
  bias = TRUE,
  seed = 5,
  activations = vector()
)

Arguments

df

A numerical dataframe

lag

The lag parameter.

sizeOfHLayers

Integer vector that contains the size of hidden layers, where the length of this vector is the number of hidden layers, and the i-th element is the number of neurons in the i-th hidden layer.

iters

The number of iterations.

learningRate

The learning rate to use, O.1 by default, and if Adam algorithm is used, then it is the initial learning rate.

algo

A string specifying the optimization algorithm: "sgd" (default) or "adam".

batch_size

An integer specifying the number of samples processed before the model's internal parameters are updated during backpropagation.

bias

Logical, true if the bias have to be used in the network.

seed

An integer to initialize the random number generator for weight initialization. Setting seed = 0 uses the system clock for a non-deterministic seed.

activations

String vector for the activations functions to use (in choice ["sigmoid", "relu", "tanh"]). The length of this vector is the number of hidden layers plus one (the output layer). By default, the relu activation function is used in hidden layers, and the sigmoid in the last layer.

Details

Constructs the model and returns a model object. The resulting object is designed for generating forecasts and supports incremental updates as new data becomes available.

Value

fit (df, iterations, batch_size): fit/update the weights of the model from the dataframe df.

forecast (df): A dataframe containing the model's predictions. Each row is forecasted based on the preceding "p" (lag) observations, with the final row representing the out-of-sample forecast for the period immediately following the input data.

save (filename): save the model in a text file.

load (filename): load the model from a text file.

Examples

library (timeSeries) # to extract time series
library (NlinTS)
#load data
data = LPP2005REC
# Predict the last row of the data
train_data = data[1:(nrow (data) - 1), ]
model = varmlp (train_data, 1, c(10), 50, 0.01, "sgd", 30, TRUE, 0);
predictions = model$forecast (train_data)
print (predictions[nrow (predictions),])

NlinTS documentation built on March 23, 2026, 5:07 p.m.