47160b561647cc80c454de929384f41df412166f
[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 data Dataset, object of class Data
10 #' @field pjump Function: how to predict the jump at day interface ?
11 #'
12 #' @section Methods: \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} using \code{memory}
17 #' 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} using \code{memory}
20 #' days in the past.}
21 #' \item{\code{getParameters()}}
22 #' {Return (internal) parameters.}}
23 Forecaster = R6::R6Class("Forecaster",
24 private = list(
25 .params = list(),
26 .data = NULL,
27 .pjump = NULL
28 ),
29 public = list(
30 initialize = function(data, pjump)
31 {
32 private$.data <- data
33 private$.pjump <- pjump
34 invisible(self)
35 },
36 predictSerie = function(today, memory, horizon, ...)
37 {
38 # Parameters (potentially) computed during shape prediction stage
39 predicted_shape = self$predictShape(today, memory, horizon, ...)
40 predicted_delta = private$.pjump(private$.data,today,memory,horizon,private$.params,...)
41 # Predicted shape is aligned it on the end of current day + jump
42 predicted_shape+tail(private$.data$getSerie(today),1)-predicted_shape[1]+predicted_delta
43 },
44 predictShape = function(today, memory, horizon, ...)
45 NULL #empty default implementation: to implement in inherited classes
46 ,
47 getParameters = function()
48 private$.params
49 )
50 )