X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FForecaster.R;h=2efa9ba10c91e9fcdabee8e24cc194b396eb72a0;hb=102bcfda4afbb5cfee885cbee0f55545624168fd;hp=2bd2e4ea0a4dae7ed32b4f695d1a17ae425e39ac;hpb=a66a84b56467194852f2faee15f4725759b24158;p=talweg.git diff --git a/pkg/R/Forecaster.R b/pkg/R/Forecaster.R index 2bd2e4e..2efa9ba 100644 --- a/pkg/R/Forecaster.R +++ b/pkg/R/Forecaster.R @@ -1,48 +1,65 @@ #' Forecaster #' -#' Forecaster (abstract class, implemented by all forecasters) +#' Forecaster (abstract class, implemented by all forecasters). #' -#' @docType class -#' @importFrom R6 R6Class +#' A Forecaster object encapsulates parameters (which can be of various kinds, for +#' example "Neighbors" method stores informations about the considered neighborhood for +#' the current prediction task) and one main function: \code{predictSerie()}. This last +#' function (by default) calls \code{predictShape()} to get a forecast of a centered +#' serie, and then calls the "jump prediction" function -- see "field" section -- to +#' adjust it based on the last observed values. +#' +#' @field .params List of computed parameters (if applicable). +#' @field .pjump Function: how to predict the jump at day interface? The arguments of +#' this function are -- in this order: +#' \itemize{ +#' \item data : object output of \code{getData()}, +#' \item today : index (integer or date) of the last known day in data, +#' \item memory : number of days to use in the past (including today), +#' \item horizon : number of time steps to predict, +#' \item params : optimized parameters in the main method \code{predictShape()}, +#' \item ... : additional arguments. +#' } +#' .pjump returns an estimation of the jump after the last observed value. #' -#' @field params List of computed parameters, for post-run analysis (dev) -#' @field data Dataset, object of class Data -#' @field pjump Function: how to predict the jump at day interface ? +#' @section Methods: +#' \describe{ +#' \item{\code{initialize(data, pjump)}}{ +#' Initialize a Forecaster object with a Data object and a jump prediction function.} +#' \item{\code{predictSerie(today,memory,horizon,...)}}{ +#' Predict a new serie of \code{horizon} values at day index \code{today} using +#' \code{memory} days in the past.} +#' \item{\code{predictShape(today,memory,horizon,...)}}{ +#' Predict a new shape of \code{horizon} values at day index \code{today} using +#' \code{memory} days in the past.} +#' \item{\code{getParameters()}}{ +#' Return (internal) parameters.} +#' } +#' +#' @docType class +#' @format R6 class #' -#' @section Methods: \describe{ -#' \item{\code{initialize(data, pjump)}} -#' {Initialize a Forecaster object with a Data object and a jump prediction function.} -#' \item{\code{predictSerie(today,memory,horizon,...)}} -#' {Predict a new serie of \code{horizon} values at day index \code{today} using \code{memory} -#' days in the past.} -#' \item{\code{predictShape(today,memory,horizon,...)}} -#' {Predict a new shape of \code{horizon} values at day index \code{today} using \code{memory} -#' days in the past.} -#' \item{\code{getParameters()}} -#' {Return (internal) parameters.} } Forecaster = R6::R6Class("Forecaster", private = list( .params = list(), - .data = NULL, .pjump = NULL ), public = list( - initialize = function(data, pjump) + initialize = function(pjump) { - private$.data <- data private$.pjump <- pjump invisible(self) }, - predictSerie = function(today, memory, horizon, ...) + predictSerie = function(data, today, memory, horizon, ...) { # Parameters (potentially) computed during shape prediction stage - predicted_shape = o$predictShape(today, memory, horizon, ...) - predicted_delta = private$.pjump(private$.data,today,memory,horizon,private$.params,...) + predicted_shape = self$predictShape(data, today, memory, horizon, ...) + predicted_delta = private$.pjump(data,today,memory,horizon,private$.params,...) # Predicted shape is aligned it on the end of current day + jump - predicted_shape+tail(private$.data$getSerie(today),1)-predicted_shape[1]+predicted_delta + predicted_shape+tail(data$getSerie(today),1)-predicted_shape[1]+predicted_delta }, - predictShape = function(today, memory, horizon, ...) - #empty default implementation: to implement in inherited classes + predictShape = function(data, today, memory, horizon, ...) + NULL #empty default implementation: to implement in inherited classes , getParameters = function() private$.params