R CMD check compliant; TODO: doc, vignette
[talweg.git] / pkg / R / Forecaster.R
CommitLineData
25b75559 1#' Forecaster
e030a6e3 2#'
25b75559 3#' Forecaster (abstract class, implemented by all forecasters)
e030a6e3 4#'
a66a84b5
BA
5#' @docType class
6#' @importFrom R6 R6Class
7#'
98e958ca
BA
8#' @field .params List of computed parameters, for post-run analysis (dev)
9#' @field .pjump Function: how to predict the jump at day interface ?
25b75559 10#'
98e958ca
BA
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}
af3b84f4 17#' using \code{memory} days in the past.}
98e958ca
BA
18#' \item{\code{predictShape(today,memory,horizon,...)}}{
19#' Predict a new shape of \code{horizon} values at day index \code{today}
af3b84f4 20#' using \code{memory} days in the past.}
98e958ca 21#' \item{\code{getParameters()}}{
546b0cb6
BA
22#' Return (internal) parameters.}
23#' }
24#'
25b75559
BA
25Forecaster = R6::R6Class("Forecaster",
26 private = list(
a66a84b5 27 .params = list(),
a66a84b5 28 .pjump = NULL
e030a6e3 29 ),
25b75559 30 public = list(
98e958ca 31 initialize = function(pjump)
a66a84b5 32 {
a66a84b5
BA
33 private$.pjump <- pjump
34 invisible(self)
35 },
98e958ca 36 predictSerie = function(data, today, memory, horizon, ...)
a66a84b5
BA
37 {
38 # Parameters (potentially) computed during shape prediction stage
98e958ca
BA
39 predicted_shape = self$predictShape(data, today, memory, horizon, ...)
40 predicted_delta = private$.pjump(data,today,memory,horizon,private$.params,...)
a66a84b5 41 # Predicted shape is aligned it on the end of current day + jump
98e958ca 42 predicted_shape+tail(data$getSerie(today),1)-predicted_shape[1]+predicted_delta
a66a84b5 43 },
98e958ca 44 predictShape = function(data, today, memory, horizon, ...)
5d83d815 45 NULL #empty default implementation: to implement in inherited classes
25b75559 46 ,
e030a6e3 47 getParameters = function()
a66a84b5 48 private$.params
e030a6e3
BA
49 )
50)