X-Git-Url: https://git.auder.net/?p=talweg.git;a=blobdiff_plain;f=pkg%2FR%2FForecast.R;h=f1b92ce7d6f46bb0d9f59d2ff924cc0711c3c0af;hp=b68b6c97f765071e3462c73996f269c5b89e74a2;hb=a66a84b56467194852f2faee15f4725759b24158;hpb=25b75559e2d9bf84e2de35b851d93fefdae36e17 diff --git a/pkg/R/Forecast.R b/pkg/R/Forecast.R index b68b6c9..f1b92ce 100644 --- a/pkg/R/Forecast.R +++ b/pkg/R/Forecast.R @@ -2,43 +2,52 @@ #' #' Forecast encapsulation #' -#' @field pred List with -#' \itemize{ -#' \item serie: forecasted serie -#' \item params: corresponding list of parameters (weights, neighbors...) -#' \item index: corresponding index in data object -#' } -#' #' @docType class #' @importFrom R6 R6Class #' -#' @export +#' @field .pred List with \itemize{ +#' \item serie: forecasted serie +#' \item params: corresponding list of parameters (weights, neighbors...) +#' \item index: corresponding index in data object} +#' @field .dates vector of day indices where forcast occurs +#' +#' @section Methods: \describe{ +#' \item{\code{initialize(dates)}} +#' {Initialize a Forecast object with a series of date indices.} +#' \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.} TODO: continue ####################################### +#' \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.} } Forecast = R6::R6Class("Forecast", private = list( - .pred = "list", - .dates = "Date" + .pred = list(), + .dates = c() ), public = list( initialize = function(dates) - initialize(self, private, dates) + initializeForecast(self, private, dates) , getSize = function() - getSize(private) + getSizeForecast(private) , append = function(new_serie, new_params, new_index) - append(private, new_serie, new_params, new_index) + appendForecast(private, new_serie, new_params, new_index) , getDates = function() - getDates(private) + getDatesForecast(private) , getSerie = function(index) - getSerie(private, index) + getSerieForecast(private, index) , getParams = function(index) - getParams(private, index) + getParamsForecast(private, index) , getIndexInData = function(index) - getIndexInData(private, index) + getIndexInDataForecast(private, index) ) ) @@ -47,39 +56,41 @@ Forecast = R6::R6Class("Forecast", #' @param o Object of class Forecast #' @param private List of private members in o #' @param dates vector of dates where forecast occurs -initialize = function(o, private, dates) +initializeForecast = function(o, private, dates) { - private$.dates <<- dates - private$.pred <<- list() + private$.dates <- dates invisible(o) } #' Number of individual forecasts" #' -#' @inheritParams initialize -getSize = function(private) +#' @inheritParams initializeForecast +getSizeForecast = function(private) length(private$.pred) #' Obtain a new pair (serie, params)" #' -#' @inheritParams initialize -append = function(new_serie, new_params, new_index_in_data) +#' @inheritParams initializeForecast +#' @param new_serie Values of a new serie +#' @param new_params Associated (optimized) parameters +#' @param new_index_in_data Corresponding index in data +appendForecast = function(private, new_serie, new_params, new_index_in_data) { - private$.pred[[length(private$.pred)+1]] <<- + private$.pred[[length(private$.pred)+1]] <- list("serie"=new_serie, "params"=new_params, "index_in_data"=new_index_in_data) } #' Dates where prediction occurs #' -#' inheritParams initialize -getDates = function(private) +#' inheritParams initializeForecast +getDatesForecast = function(private) private$.dates #' Serie values at specified index" #' -#' @inheritParams initialize +#' @inheritParams initializeForecast #' @param index Return value at this index -getSerie = function(index) +getSerieForecast = function(index) { if (is(index,"Date")) index = match(index, private$.dates) @@ -88,8 +99,8 @@ getSerie = function(index) #' Params at specified index" #' -#' @inheritParams getSerie -getParams = function(index) +#' @inheritParams getSerieForecast +getParamsForecast = function(index) { if (is(index,"Date")) index = match(index, private$.dates) @@ -98,8 +109,8 @@ getParams = function(index) #' (day) Index in data where prediction took place" #' -#' @inheritParams getSerie -getIndexInData = function(index) +#' @inheritParams getSerieForecast +getIndexInDataForecast = function(index) { if (is(index,"Date")) index = match(index, private$.dates)