3 #' Forecast encapsulation as a list (days where prediction occur) of lists (components).
5 #' The private field .pred is a list where each cell contains the predicted variables for
6 #' a period of time of H<=24 hours, from hour P until P+H-1, where P == predict_from.
7 #' \code{forecast$getForecast(i)} output forecasts for
8 #' \code{data$getSerie(forecast$getIndexInData(i))}.
10 #' @usage # Forecast$new(dates)
12 #' @field .pred List with
14 #' \item serie: the forecasted serie
15 #' \item params: corresponding list of parameters (weights, neighbors...)
16 #' \item index_in_data: corresponding index in data object
18 #' @field .dates vector of (integer) day indices where forecast occurs
22 #' \item{\code{initialize(dates)}}{
23 #' Initialize a Forecast object with a series of date indices.}
24 #' \item{\code{getSize()}}{
25 #' Return number of individual forecasts.}
26 #' \item{\code{append(forecast, params, index_in_data)}}{
27 #' Acquire an individual forecast, with its (optimized) parameters and the
28 #' corresponding index in the dataset.}
29 #' \item{\code{getDates()}}{
30 #' Get dates where forecast occurs.}
31 #' \item{\code{getForecast(index)}}{
32 #' Get forecasted serie at specified index.}
33 #' \item{\code{getParams(index)}}{
34 #' Get parameters at specified index (for 'Neighbors' method).}
35 #' \item{\code{getIndexInData(index)}}{
36 #' Get index in data which corresponds to current forecast.}
42 Forecast = R6::R6Class("Forecast",
45 .dates = integer(0) #store dates as integers (from 1970-01-01)
48 initialize = function(dates)
50 private$.dates <- dates
56 append = function(forecast, params, index_in_data)
58 private$.pred[[length(private$.pred)+1]] <-
59 list("forecast"=forecast, "params"=params, "index_in_data"=index_in_data)
62 as.Date( private$.dates, origin="1970-01-01" )
64 getForecast = function(index)
67 index = match(index, private$.dates)
68 private$.pred[[index]]$forecast
70 getParams = function(index)
73 index = match(index, private$.dates)
74 private$.pred[[index]]$params
76 getIndexInData = function(index)
79 index = match(index, private$.dates)
80 private$.pred[[index]]$index_in_data