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 BA |
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+1 until P+H, where P+1 is taken right | |
7 | #' after the end of the period designated by \code{getIndexInData()}. In other terms, | |
8 | #' \code{forecast$getForecast(i)} return forecasts for \code{data$getSerie(i+1)}. | |
9 | #' Each cell .pred[[i]] is itself a list containing three slots, as described in the | |
10 | #' 'field' section. | |
25b75559 | 11 | #' |
689aa1d3 BA |
12 | #' @usage f <- Forecast$new(dates) |
13 | #' | |
102bcfda BA |
14 | #' @field .pred List with |
15 | #' \itemize{ | |
16 | #' \item serie: the forecasted serie | |
a66a84b5 | 17 | #' \item params: corresponding list of parameters (weights, neighbors...) |
102bcfda BA |
18 | #' \item index_in_data: corresponding index in data object |
19 | #' } | |
20 | #' @field .dates vector of (integer) day indices where forecast occurs | |
a66a84b5 | 21 | #' |
98e958ca BA |
22 | #' @section Methods: |
23 | #' \describe{ | |
24 | #' \item{\code{initialize(dates)}}{ | |
25 | #' Initialize a Forecast object with a series of date indices.} | |
26 | #' \item{\code{getSize()}}{ | |
27 | #' Return number of individual forecasts.} | |
72b9c501 BA |
28 | #' \item{\code{append(forecast, params, index_in_data)}}{ |
29 | #' Acquire an individual forecast, with its (optimized) parameters and the | |
30 | #' corresponding index in the dataset.} | |
98e958ca BA |
31 | #' \item{\code{getDates()}}{ |
32 | #' Get dates where forecast occurs.} | |
72b9c501 | 33 | #' \item{\code{getForecast(index)}}{ |
98e958ca BA |
34 | #' Get forecasted serie at specified index.} |
35 | #' \item{\code{getParams(index)}}{ | |
36 | #' Get parameters at specified index (for 'Neighbors' method).} | |
37 | #' \item{\code{getIndexInData(index)}}{ | |
38 | #' Get index in data which corresponds to current forecast.} | |
39 | #' } | |
546b0cb6 | 40 | #' |
102bcfda BA |
41 | #' @docType class |
42 | #' @format R6 class | |
43 | #' | |
25b75559 BA |
44 | Forecast = R6::R6Class("Forecast", |
45 | private = list( | |
a66a84b5 | 46 | .pred = list(), |
98e958ca | 47 | .dates = integer(0) #store dates as integers (from 1970-01-01) |
3d69ff21 | 48 | ), |
25b75559 BA |
49 | public = list( |
50 | initialize = function(dates) | |
5d83d815 BA |
51 | { |
52 | private$.dates <- dates | |
53 | invisible(self) | |
54 | }, | |
1e20780e | 55 | getSize = function() |
5d83d815 | 56 | length(private$.pred) |
25b75559 | 57 | , |
72b9c501 | 58 | append = function(forecast, params, index_in_data) |
5d83d815 BA |
59 | { |
60 | private$.pred[[length(private$.pred)+1]] <- | |
72b9c501 | 61 | list("forecast"=forecast, "params"=params, "index_in_data"=index_in_data) |
5d83d815 | 62 | }, |
25b75559 | 63 | getDates = function() |
98e958ca | 64 | as.Date( private$.dates, origin="1970-01-01" ) |
25b75559 | 65 | , |
72b9c501 | 66 | getForecast = function(index) |
5d83d815 BA |
67 | { |
68 | if (is(index,"Date")) | |
69 | index = match(index, private$.dates) | |
72b9c501 | 70 | private$.pred[[index]]$forecast |
5d83d815 | 71 | }, |
3d69ff21 | 72 | getParams = function(index) |
5d83d815 BA |
73 | { |
74 | if (is(index,"Date")) | |
75 | index = match(index, private$.dates) | |
76 | private$.pred[[index]]$params | |
77 | }, | |
3d69ff21 | 78 | getIndexInData = function(index) |
5d83d815 BA |
79 | { |
80 | if (is(index,"Date")) | |
81 | index = match(index, private$.dates) | |
82 | private$.pred[[index]]$index_in_data | |
83 | } | |
3d69ff21 BA |
84 | ) |
85 | ) |