work on doc
[talweg.git] / pkg / R / F_Average.R
CommitLineData
25b75559 1#' Average Forecaster
3d69ff21 2#'
c4c329f6
BA
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
546b0cb6 7#'
25b75559 8AverageForecaster = R6::R6Class("AverageForecaster",
a66a84b5 9 inherit = Forecaster,
3d69ff21 10
25b75559 11 public = list(
98e958ca 12 predictShape = function(data, today, memory, horizon, ...)
3d69ff21
BA
13 {
14 avg = rep(0., horizon)
09cf9c19
BA
15 first_day = max(1, today-memory)
16 index = today-7 + 1
17 nb_no_na_series = 0
18 repeat
3d69ff21 19 {
09cf9c19 20 {
98e958ca 21 serie_on_horizon = data$getCenteredSerie(index)[1:horizon]
09cf9c19
BA
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
3d69ff21 31 }
09cf9c19 32 avg / nb_no_na_series
3d69ff21
BA
33 }
34 )
35)