3 #' Forecast encapsulation
5 #' @field pred List with
7 #' \item serie: forecasted serie
8 #' \item params: corresponding list of parameters (weights, neighbors...)
9 #' \item index: corresponding index in data object
13 #' @importFrom R6 R6Class
16 Forecast = R6::R6Class("Forecast",
22 initialize = function(dates)
23 initialize(self, private, dates)
28 append = function(new_serie, new_params, new_index)
29 append(private, new_serie, new_params, new_index)
34 getSerie = function(index)
35 getSerie(private, index)
37 getParams = function(index)
38 getParams(private, index)
40 getIndexInData = function(index)
41 getIndexInData(private, index)
45 #' Initialize empty Forecast object
47 #' @param o Object of class Forecast
48 #' @param private List of private members in o
49 #' @param dates vector of dates where forecast occurs
50 initialize = function(o, private, dates)
52 private$.dates <<- dates
53 private$.pred <<- list()
57 #' Number of individual forecasts"
59 #' @inheritParams initialize
60 getSize = function(private)
63 #' Obtain a new pair (serie, params)"
65 #' @inheritParams initialize
66 append = function(new_serie, new_params, new_index_in_data)
68 private$.pred[[length(private$.pred)+1]] <<-
69 list("serie"=new_serie, "params"=new_params, "index_in_data"=new_index_in_data)
72 #' Dates where prediction occurs
74 #' inheritParams initialize
75 getDates = function(private)
78 #' Serie values at specified index"
80 #' @inheritParams initialize
81 #' @param index Return value at this index
82 getSerie = function(index)
85 index = match(index, private$.dates)
86 private$.pred[[index]]$serie
89 #' Params at specified index"
91 #' @inheritParams getSerie
92 getParams = function(index)
95 index = match(index, private$.dates)
96 private$.pred[[index]]$params
99 #' (day) Index in data where prediction took place"
101 #' @inheritParams getSerie
102 getIndexInData = function(index)
104 if (is(index,"Date"))
105 index = match(index, private$.dates)
106 private$.pred[[index]]$index_in_data