da8579b7312bfcc520d8e2a8504202bb68ff2cbd
[talweg.git] / pkg / R / Forecaster.R
1 #' Forecaster
2 #'
3 #' Forecaster (abstract class, implemented by all forecasters)
4 #'
5 #' @docType class
6 #' @importFrom R6 R6Class
7 #'
8 #' @field .params List of computed parameters, for post-run analysis (dev)
9 #' @field .pjump Function: how to predict the jump at day interface ?
10 #'
11 #' @section Methods:
12 #' \describe{
13 #' \item{\code{initialize(data, pjump)}}{
14 #' Initialize a Forecaster object with a Data object and a jump prediction function.}
15 #' \item{\code{predictSerie(today,memory,horizon,...)}}{
16 #' Predict a new serie of \code{horizon} values at day index \code{today}
17 #' using \code{memory} days in the past.}
18 #' \item{\code{predictShape(today,memory,horizon,...)}}{
19 #' Predict a new shape of \code{horizon} values at day index \code{today}
20 #' using \code{memory} days in the past.}
21 #' \item{\code{getParameters()}}{
22 #' Return (internal) parameters.}}
23 Forecaster = R6::R6Class("Forecaster",
24 private = list(
25 .params = list(),
26 .pjump = NULL
27 ),
28 public = list(
29 initialize = function(pjump)
30 {
31 private$.pjump <- pjump
32 invisible(self)
33 },
34 predictSerie = function(data, today, memory, horizon, ...)
35 {
36 # Parameters (potentially) computed during shape prediction stage
37 predicted_shape = self$predictShape(data, today, memory, horizon, ...)
38 predicted_delta = private$.pjump(data,today,memory,horizon,private$.params,...)
39 # Predicted shape is aligned it on the end of current day + jump
40 predicted_shape+tail(data$getSerie(today),1)-predicted_shape[1]+predicted_delta
41 },
42 predictShape = function(data, today, memory, horizon, ...)
43 NULL #empty default implementation: to implement in inherited classes
44 ,
45 getParameters = function()
46 private$.params
47 )
48 )