work on doc
[talweg.git] / pkg / R / F_Average.R
1 #' Average Forecaster
2 #'
3 #' Pointwise average of all series of the same (day of week) days in the past.
4 #'
5 #' @format R6 class, inherits Forecaster
6 #' @alias F_Average
7 #'
8 AverageForecaster = R6::R6Class("AverageForecaster",
9 inherit = Forecaster,
10
11 public = list(
12 predictShape = function(data, today, memory, horizon, ...)
13 {
14 avg = rep(0., horizon)
15 first_day = max(1, today-memory)
16 index = today-7 + 1
17 nb_no_na_series = 0
18 repeat
19 {
20 {
21 serie_on_horizon = data$getCenteredSerie(index)[1:horizon]
22 index = index - 7
23 };
24 if (!any(is.na(serie_on_horizon)))
25 {
26 avg = avg + serie_on_horizon
27 nb_no_na_series = nb_no_na_series + 1
28 };
29 if (index < first_day)
30 break
31 }
32 avg / nb_no_na_series
33 }
34 )
35 )