X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FForecaster.R;h=47160b561647cc80c454de929384f41df412166f;hb=5d83d8150dc135347d5ef39e5015b88f33fa9ee3;hp=d5d5280c997a735f59215a09d464c3bdc2bf0eea;hpb=1e20780ee1505fac6c7ed68d340892c497524561;p=talweg.git diff --git a/pkg/R/Forecaster.R b/pkg/R/Forecaster.R index d5d5280..47160b5 100644 --- a/pkg/R/Forecaster.R +++ b/pkg/R/Forecaster.R @@ -1,50 +1,50 @@ -#' @title Forecaster (abstract class) +#' Forecaster #' -#' @description Abstract class to represent a forecaster (they all inherit this) +#' Forecaster (abstract class, implemented by all forecasters) +#' +#' @docType class +#' @importFrom R6 R6Class #' #' @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 ? -Forecaster = setRefClass( - Class = "Forecaster", - - fields = list( - params = "list", - data = "Data", - pjump = "function" +#' +#' @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 ), - - methods = list( - initialize = function(...) + public = list( + initialize = function(data, pjump) { - "Initialize (generic) Forecaster object" - - callSuper(...) - if (!hasArg(data)) - stop("Forecaster must be initialized with a Data object") - params <<- list() + private$.data <- data + private$.pjump <- pjump + invisible(self) }, - predict = function(today, memory, horizon, ...) + predictSerie = function(today, memory, horizon, ...) { - "Obtain a new forecasted time-serie" - # Parameters (potentially) computed during shape prediction stage - predicted_shape = predictShape(today, memory, horizon, ...) - predicted_delta = pjump(data, today, memory, horizon, params, ...) + predicted_shape = self$predictShape(today, memory, horizon, ...) + predicted_delta = private$.pjump(private$.data,today,memory,horizon,private$.params,...) # Predicted shape is aligned it on the end of current day + jump - predicted_shape + tail(data$getSerie(today),1) - predicted_shape[1] + predicted_delta + predicted_shape+tail(private$.data$getSerie(today),1)-predicted_shape[1]+predicted_delta }, predictShape = function(today, memory, horizon, ...) - { - "Shape prediction (centered curve)" - - #empty default implementation: to implement in inherited classes - }, + NULL #empty default implementation: to implement in inherited classes + , getParameters = function() - { - "Get parameters list" - - params - } + private$.params ) )