3 #' Forecaster (abstract class, implemented by all forecasters).
5 #' A Forecaster object encapsulates parameters (which can be of various kinds, for
6 #' example "Neighbors" method stores informations about the considered neighborhood for
7 #' the current prediction task) and one main function: \code{predictSerie()}. This last
8 #' function (by default) calls \code{predictShape()} to get a forecast of a centered
9 #' serie, and then calls the "jump prediction" function -- see "field" section -- to
10 #' adjust it based on the last observed values.
12 #' @usage # Forecaster$new(pjump) #warning: predictShape() is unimplemented
14 #' @field .params List of computed parameters (if applicable).
15 #' @field .pjump Function: how to predict the jump at day interface? The arguments of
16 #' this function are -- in this order:
18 #' \item data : object output of \code{getData()},
19 #' \item today : index (integer or date) of the last known day in data,
20 #' \item memory : number of days to use in the past (including today),
21 #' \item horizon : number of time steps to predict,
22 #' \item params : optimized parameters in the main method \code{predictShape()},
23 #' \item ... : additional arguments.
25 #' .pjump returns an estimation of the jump after the last observed value.
29 #' \item{\code{initialize(data, pjump)}}{
30 #' Initialize a Forecaster object with a Data object and a jump prediction function.}
31 #' \item{\code{predictSerie(today,memory,horizon,...)}}{
32 #' Predict a new serie of \code{horizon} values at day index \code{today} using
33 #' \code{memory} days in the past.}
34 #' \item{\code{predictShape(today,memory,horizon,...)}}{
35 #' Predict a new shape of \code{horizon} values at day index \code{today} using
36 #' \code{memory} days in the past.}
37 #' \item{\code{getParameters()}}{
38 #' Return (internal) parameters.}
44 Forecaster = R6::R6Class("Forecaster",
50 initialize = function(pjump)
52 private$.pjump <- pjump
55 predictSerie = function(data, today, memory, predict_from, horizon, ...)
57 # Parameters (potentially) computed during shape prediction stage
58 predicted_shape = self$predictShape(data,today,memory,predict_from,horizon,...)
59 predicted_delta = private$.pjump(data, today, memory, predict_from, horizon,
62 # Predicted shape is aligned on the end of current day + jump
63 c( data$getSerie(today)[if (predict_from>=2) 1:(predict_from-1) else c()],
64 predicted_shape - predicted_shape[1] + predicted_delta +
65 ifelse(predict_from>=2,
66 data$getSerie(today)[predict_from-1], tail(data$getSerie(today-1),1)) )
68 predictShape = function(data, today, memory, predict_from, horizon, ...)
69 NULL #empty default implementation: to implement in inherited classes
71 getParameters = function()