Commit | Line | Data |
---|---|---|
25b75559 | 1 | #' Forecast |
3d69ff21 | 2 | #' |
25b75559 | 3 | #' Forecast encapsulation |
3d69ff21 | 4 | #' |
25b75559 BA |
5 | #' @docType class |
6 | #' @importFrom R6 R6Class | |
7 | #' | |
a66a84b5 BA |
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 | |
13 | #' | |
14 | #' @section Methods: \describe{ | |
15 | #' \item{\code{initialize(dates)}} | |
16 | #' {Initialize a Forecast object with a series of date indices.} | |
5d83d815 BA |
17 | #' \item{\code{getSize()}} |
18 | #' {Return number of individual forecasts.} | |
19 | #' \item{\code{append(new_serie, new_params, new_index_in_data)}} | |
20 | #' {Acquire a new individual forecast, with its (optimized) parameters and the corresponding | |
21 | #' index in the dataset.} | |
22 | #' \item{\code{getDates()}} | |
23 | #' {Get dates where forecast occurs.} | |
24 | #' \item{\code{getSerie(index)}} | |
25 | #' {Get forecasted serie at specified index.} | |
26 | #' \item{\code{getParams(index)}} | |
27 | #' {Get parameters at specified index (for 'Neighbors' method).} | |
28 | #' \item{\code{getIndexInData(index)}} | |
29 | #' {Get index in data which corresponds to current forecast.}} | |
25b75559 BA |
30 | Forecast = R6::R6Class("Forecast", |
31 | private = list( | |
a66a84b5 BA |
32 | .pred = list(), |
33 | .dates = c() | |
3d69ff21 | 34 | ), |
25b75559 BA |
35 | public = list( |
36 | initialize = function(dates) | |
5d83d815 BA |
37 | { |
38 | private$.dates <- dates | |
39 | invisible(self) | |
40 | }, | |
1e20780e | 41 | getSize = function() |
5d83d815 | 42 | length(private$.pred) |
25b75559 | 43 | , |
5d83d815 BA |
44 | append = function(new_serie, new_params, new_index_in_data) |
45 | { | |
46 | private$.pred[[length(private$.pred)+1]] <- | |
47 | list("serie"=new_serie, "params"=new_params, "index_in_data"=new_index_in_data) | |
48 | }, | |
25b75559 | 49 | getDates = function() |
5d83d815 | 50 | private$.dates |
25b75559 | 51 | , |
3d69ff21 | 52 | getSerie = function(index) |
5d83d815 BA |
53 | { |
54 | if (is(index,"Date")) | |
55 | index = match(index, private$.dates) | |
56 | private$.pred[[index]]$serie | |
57 | }, | |
3d69ff21 | 58 | getParams = function(index) |
5d83d815 BA |
59 | { |
60 | if (is(index,"Date")) | |
61 | index = match(index, private$.dates) | |
62 | private$.pred[[index]]$params | |
63 | }, | |
3d69ff21 | 64 | getIndexInData = function(index) |
5d83d815 BA |
65 | { |
66 | if (is(index,"Date")) | |
67 | index = match(index, private$.dates) | |
68 | private$.pred[[index]]$index_in_data | |
69 | } | |
3d69ff21 BA |
70 | ) |
71 | ) |