hanaml.LTSF is a R wrapper for SAP HANA PAL Long-Term Series Forecasting (LTSF).

hanaml.LTSF(
  data = NULL,
  key = NULL,
  endog = NULL,
  exog = NULL,
  train.length = NULL,
  forecast.length = NULL,
  num.levels = NULL,
  kernel.size = NULL,
  hidden.expansion = NULL,
  batch.size = NULL,
  num.epochs = NULL,
  random.seed = NULL,
  position.encoding = NULL,
  adjust.learning.rate = NULL,
  learning.rate = NULL,
  dropout.prob = NULL,
  model = NULL,
  warm.start = FALSE
)

Arguments

data

DataFrame
DataFrame containting the data.

key

character, optional
Name of the ID column. If not provided, the data is assumed to have no ID column.
No default value.

endog

character, optional
The endogenous variable, i.e. time series.
Defaults to the first non-ID column.

exog

character or list of characters, optional
An optional array of exogenous variables.
Defaults to NULL.

train.length

integer
Length of training series inputted to the network.
Note when warm.start = TRUE, this parameter is not valid.

forecast.length

integer
Length of predictions.
Note when warm.start = TRUE, this parameter is not valid.

num.levels

integer, optional
Number of levels in the network architecture.
Note when warm.start = TRUE, this parameter is not valid.
Defaults to 2.

kernel.size

integer, optional
Kernel size of Conv1d layer.
Note when warm.start = TRUE, this parameter is not valid.
Defaults to 3.

hidden.expansion

integer, optional
NExpands the input channel size of Conv1d layer.
Note when warm.start = TRUE, this parameter is not valid.
Defaults to 3.

batch.size

integer, optional
Number of pieces of data for training in one iteration.
Defaults to 8.

num.epochs

integer, optional
Number of training epochs.
Defaults to 1.

random.seed

integer, optional
0 indicates using machine time as seed.
Defaults to 0.

position.encoding

logical, optional
Position encoding adds extra positional embeddings to the training series.
- FALSE: Do not use.
- TRUE: Use.
Defaults to TRUE.

adjust.learning.rate

logical, optional
Decays the learning rate to its half after every epoch.
- FALSE: Do not use.
- TRUE: Use.
Defaults to TRUE.

learning.rate

numeric, optional
Initinal learning rate for Adam optimizer.
Defaults to 0.005.

dropout.prob

numeric, optional
Dropout probability of Dropout layer.
Defaults to 0.05.

model

DataFrame, optional
The model used for warm start.
Defaults to NULL.

warm.start

logical, optional
When set to TRUE, use the input model to train the provided model with new input data.
If no model is provided, an error will be prompted.
Defaults to FALSE.

Value

Returns an R6 object of class "LTSF", with following attributes and methods:
Attributes

  • loss: DataFrame
    Indicates the information of training loss either batch ID or average batch loss indicator.

  • model: DataFrame
    Trained model content.

Details

Although traditional algorithms are capable of predicting values in the near future, their performance will deteriorate greatly when it comes to long-term series forecasting. With the help of deep learning, this function implements a novel neural network architecture to achieve the state-of-the-art performance among the PAL family.

Examples

Input dataframe is df.fit and invoke hanaml.LTSF():


> lt1 <- hanaml.LTSF(data=df.fit,
                     train.length=32,
                     forecast.length=16,
                     key="TIME_STAMP",
                     endog="TARGET",
                     exog=list("FEAT1", "FEAT2", "FEAT3", "FEAT4"),
                     num.levels=2,
                     kernel.size=3,
                     hidden.expansion=3,
                     batch.size=8,
                     num.epochs=2,
                     position.encoding=TRUE,
                     adjust.learning.rate=TRUE,
                     learning.rate=0.005,
                     dropout.prob=0.2,
                     random.seed=1)

Output:


> print(lt1$loss$Collect())
> print(lt1$model$Collect())

We also provide the continuous training with new training data which uses a parameter warm.start to control. Please provide a trained model when invoke hanaml.LTSF().


> lt2 <- hanaml.LTSF(df.fit2,
                     key="TIME_STAMP",
                     endog="TARGET",
                     exog=list("FEAT1", "FEAT2", "FEAT3", "FEAT4"),
                     num.epochs=1,
                     dropout.prob=0.2,
                     learning.rate=0.002,
                     model=lt1$model,
                     warm.start=TRUE)

Output:


> print(lt2$loss$Collect())
> print(lt2$model$Collect())

See also