Commit | Line | Data |
---|---|---|
25b75559 | 1 | #' Forecast |
3d69ff21 | 2 | #' |
102bcfda | 3 | #' Forecast encapsulation as a list (days where prediction occur) of lists (components). |
3d69ff21 | 4 | #' |
102bcfda | 5 | #' The private field .pred is a list where each cell contains the predicted variables for |
4f3fdbb8 | 6 | #' a period of time of H-P+1<=24 hours, from hour P until H, where P == predict_from. |
d2ab47a7 BA |
7 | #' \code{forecast$getForecast(i)} output forecasts for |
8 | #' \code{data$getSerie(forecast$getIndexInData(i))}. | |
25b75559 | 9 | #' |
4e821712 | 10 | #' @usage # Forecast$new(dates) |
689aa1d3 | 11 | #' |
102bcfda BA |
12 | #' @field .pred List with |
13 | #' \itemize{ | |
14 | #' \item serie: the forecasted serie | |
a66a84b5 | 15 | #' \item params: corresponding list of parameters (weights, neighbors...) |
102bcfda BA |
16 | #' \item index_in_data: corresponding index in data object |
17 | #' } | |
18 | #' @field .dates vector of (integer) day indices where forecast occurs | |
a66a84b5 | 19 | #' |
98e958ca BA |
20 | #' @section Methods: |
21 | #' \describe{ | |
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.} | |
72b9c501 BA |
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.} | |
98e958ca BA |
29 | #' \item{\code{getDates()}}{ |
30 | #' Get dates where forecast occurs.} | |
72b9c501 | 31 | #' \item{\code{getForecast(index)}}{ |
98e958ca BA |
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.} | |
37 | #' } | |
546b0cb6 | 38 | #' |
102bcfda BA |
39 | #' @docType class |
40 | #' @format R6 class | |
41 | #' | |
25b75559 BA |
42 | Forecast = R6::R6Class("Forecast", |
43 | private = list( | |
a66a84b5 | 44 | .pred = list(), |
98e958ca | 45 | .dates = integer(0) #store dates as integers (from 1970-01-01) |
3d69ff21 | 46 | ), |
25b75559 BA |
47 | public = list( |
48 | initialize = function(dates) | |
5d83d815 BA |
49 | { |
50 | private$.dates <- dates | |
51 | invisible(self) | |
52 | }, | |
1e20780e | 53 | getSize = function() |
5d83d815 | 54 | length(private$.pred) |
25b75559 | 55 | , |
72b9c501 | 56 | append = function(forecast, params, index_in_data) |
5d83d815 BA |
57 | { |
58 | private$.pred[[length(private$.pred)+1]] <- | |
72b9c501 | 59 | list("forecast"=forecast, "params"=params, "index_in_data"=index_in_data) |
5d83d815 | 60 | }, |
25b75559 | 61 | getDates = function() |
98e958ca | 62 | as.Date( private$.dates, origin="1970-01-01" ) |
25b75559 | 63 | , |
72b9c501 | 64 | getForecast = function(index) |
5d83d815 BA |
65 | { |
66 | if (is(index,"Date")) | |
67 | index = match(index, private$.dates) | |
72b9c501 | 68 | private$.pred[[index]]$forecast |
5d83d815 | 69 | }, |
3d69ff21 | 70 | getParams = function(index) |
5d83d815 BA |
71 | { |
72 | if (is(index,"Date")) | |
73 | index = match(index, private$.dates) | |
74 | private$.pred[[index]]$params | |
75 | }, | |
3d69ff21 | 76 | getIndexInData = function(index) |
5d83d815 BA |
77 | { |
78 | if (is(index,"Date")) | |
79 | index = match(index, private$.dates) | |
80 | private$.pred[[index]]$index_in_data | |
81 | } | |
3d69ff21 BA |
82 | ) |
83 | ) |