3 #' Forecast encapsulation
6 #' @importFrom R6 R6Class
8 #' @field .pred List with \itemize{
9 #' \item serie: forecasted serie
10 #' \item params: corresponding list of parameters (weights, neighbors...)
11 #' \item index: corresponding index in data object}
12 #' @field .dates vector of day indices where forcast occurs
14 #' @section Methods: \describe{
15 #' \item{\code{initialize(dates)}}
16 #' {Initialize a Forecast object with a series of date indices.}
17 #' \item{\code{predictSerie(today,memory,horizon,...)}}
18 #' {Predict a new serie of \code{horizon} values at day index \code{today} using \code{memory}
19 #' days in the past.} TODO: continue #######################################
20 #' \item{\code{predictShape(today,memory,horizon,...)}}
21 #' {Predict a new shape of \code{horizon} values at day index \code{today} using \code{memory}
23 #' \item{\code{getParameters()}}
24 #' {Return (internal) parameters.} }
25 Forecast = R6::R6Class("Forecast",
31 initialize = function(dates)
32 initializeForecast(self, private, dates)
35 getSizeForecast(private)
37 append = function(new_serie, new_params, new_index)
38 appendForecast(private, new_serie, new_params, new_index)
41 getDatesForecast(private)
43 getSerie = function(index)
44 getSerieForecast(private, index)
46 getParams = function(index)
47 getParamsForecast(private, index)
49 getIndexInData = function(index)
50 getIndexInDataForecast(private, index)
54 #' Initialize empty Forecast object
56 #' @param o Object of class Forecast
57 #' @param private List of private members in o
58 #' @param dates vector of dates where forecast occurs
59 initializeForecast = function(o, private, dates)
61 private$.dates <- dates
65 #' Number of individual forecasts"
67 #' @inheritParams initializeForecast
68 getSizeForecast = function(private)
71 #' Obtain a new pair (serie, params)"
73 #' @inheritParams initializeForecast
74 #' @param new_serie Values of a new serie
75 #' @param new_params Associated (optimized) parameters
76 #' @param new_index_in_data Corresponding index in data
77 appendForecast = function(private, new_serie, new_params, new_index_in_data)
79 private$.pred[[length(private$.pred)+1]] <-
80 list("serie"=new_serie, "params"=new_params, "index_in_data"=new_index_in_data)
83 #' Dates where prediction occurs
85 #' inheritParams initializeForecast
86 getDatesForecast = function(private)
89 #' Serie values at specified index"
91 #' @inheritParams initializeForecast
92 #' @param index Return value at this index
93 getSerieForecast = function(index)
96 index = match(index, private$.dates)
97 private$.pred[[index]]$serie
100 #' Params at specified index"
102 #' @inheritParams getSerieForecast
103 getParamsForecast = function(index)
105 if (is(index,"Date"))
106 index = match(index, private$.dates)
107 private$.pred[[index]]$params
110 #' (day) Index in data where prediction took place"
112 #' @inheritParams getSerieForecast
113 getIndexInDataForecast = function(index)
115 if (is(index,"Date"))
116 index = match(index, private$.dates)
117 private$.pred[[index]]$index_in_data