work on doc
[talweg.git] / pkg / R / Forecast.R
CommitLineData
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...)
98e958ca 11#' \item index_in_data: corresponding index in data object}
a66a84b5
BA
12#' @field .dates vector of day indices where forcast occurs
13#'
98e958ca
BA
14#' @section Methods:
15#' \describe{
16#' \item{\code{initialize(dates)}}{
17#' Initialize a Forecast object with a series of date indices.}
18#' \item{\code{getSize()}}{
19#' Return number of individual forecasts.}
72b9c501
BA
20#' \item{\code{append(forecast, params, index_in_data)}}{
21#' Acquire an individual forecast, with its (optimized) parameters and the
22#' corresponding index in the dataset.}
98e958ca
BA
23#' \item{\code{getDates()}}{
24#' Get dates where forecast occurs.}
72b9c501 25#' \item{\code{getForecast(index)}}{
98e958ca
BA
26#' Get forecasted serie at specified index.}
27#' \item{\code{getParams(index)}}{
28#' Get parameters at specified index (for 'Neighbors' method).}
29#' \item{\code{getIndexInData(index)}}{
30#' Get index in data which corresponds to current forecast.}
31#' }
546b0cb6 32#'
25b75559
BA
33Forecast = R6::R6Class("Forecast",
34 private = list(
a66a84b5 35 .pred = list(),
98e958ca 36 .dates = integer(0) #store dates as integers (from 1970-01-01)
3d69ff21 37 ),
25b75559
BA
38 public = list(
39 initialize = function(dates)
5d83d815
BA
40 {
41 private$.dates <- dates
42 invisible(self)
43 },
1e20780e 44 getSize = function()
5d83d815 45 length(private$.pred)
25b75559 46 ,
72b9c501 47 append = function(forecast, params, index_in_data)
5d83d815
BA
48 {
49 private$.pred[[length(private$.pred)+1]] <-
72b9c501 50 list("forecast"=forecast, "params"=params, "index_in_data"=index_in_data)
5d83d815 51 },
25b75559 52 getDates = function()
98e958ca 53 as.Date( private$.dates, origin="1970-01-01" )
25b75559 54 ,
72b9c501 55 getForecast = function(index)
5d83d815
BA
56 {
57 if (is(index,"Date"))
58 index = match(index, private$.dates)
72b9c501 59 private$.pred[[index]]$forecast
5d83d815 60 },
3d69ff21 61 getParams = function(index)
5d83d815
BA
62 {
63 if (is(index,"Date"))
64 index = match(index, private$.dates)
65 private$.pred[[index]]$params
66 },
3d69ff21 67 getIndexInData = function(index)
5d83d815
BA
68 {
69 if (is(index,"Date"))
70 index = match(index, private$.dates)
71 private$.pred[[index]]$index_in_data
72 }
3d69ff21
BA
73 )
74)