R CMD check OK
[talweg.git] / pkg / R / Forecaster.R
CommitLineData
25b75559 1#' Forecaster
e030a6e3 2#'
102bcfda 3#' Forecaster (abstract class, implemented by all forecasters).
e030a6e3 4#'
102bcfda
BA
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.
a66a84b5 11#'
4e821712 12#' @usage # Forecaster$new(pjump) #warning: predictShape() is unimplemented
689aa1d3 13#'
102bcfda
BA
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:
17#' \itemize{
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.
24#' }
25#' .pjump returns an estimation of the jump after the last observed value.
25b75559 26#'
98e958ca
BA
27#' @section Methods:
28#' \describe{
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,...)}}{
102bcfda
BA
32#' Predict a new serie of \code{horizon} values at day index \code{today} using
33#' \code{memory} days in the past.}
98e958ca 34#' \item{\code{predictShape(today,memory,horizon,...)}}{
102bcfda
BA
35#' Predict a new shape of \code{horizon} values at day index \code{today} using
36#' \code{memory} days in the past.}
98e958ca 37#' \item{\code{getParameters()}}{
546b0cb6
BA
38#' Return (internal) parameters.}
39#' }
40#'
102bcfda
BA
41#' @docType class
42#' @format R6 class
43#'
25b75559
BA
44Forecaster = R6::R6Class("Forecaster",
45 private = list(
a66a84b5 46 .params = list(),
a66a84b5 47 .pjump = NULL
e030a6e3 48 ),
25b75559 49 public = list(
98e958ca 50 initialize = function(pjump)
a66a84b5 51 {
a66a84b5
BA
52 private$.pjump <- pjump
53 invisible(self)
54 },
98e958ca 55 predictSerie = function(data, today, memory, horizon, ...)
a66a84b5
BA
56 {
57 # Parameters (potentially) computed during shape prediction stage
98e958ca
BA
58 predicted_shape = self$predictShape(data, today, memory, horizon, ...)
59 predicted_delta = private$.pjump(data,today,memory,horizon,private$.params,...)
a66a84b5 60 # Predicted shape is aligned it on the end of current day + jump
98e958ca 61 predicted_shape+tail(data$getSerie(today),1)-predicted_shape[1]+predicted_delta
a66a84b5 62 },
98e958ca 63 predictShape = function(data, today, memory, horizon, ...)
5d83d815 64 NULL #empty default implementation: to implement in inherited classes
25b75559 65 ,
e030a6e3 66 getParameters = function()
a66a84b5 67 private$.params
e030a6e3
BA
68 )
69)