3 #' Pointwise average of all the series of the same day of week in the past.
5 #' For example, if the current day (argument "today") is a tuesday, then all series
6 #' corresponding to wednesdays in the past (until the beginning or memory limit) are
7 #' averaged to provide a smooth prediction. This forecast will most of the time be wrong,
8 #' but will also look plausible enough.
10 #' @usage # AverageForecaster$new(pjump)
13 #' @format R6 class, inherits Forecaster
16 AverageForecaster = R6::R6Class("AverageForecaster",
20 predictShape = function(data, today, memory, predict_from, horizon, ...)
22 avg = rep(0., (horizon-predict_from+1))
23 first_day = max(1, today-memory)
26 opera = ifelse(hasArg("opera"), list(...)$opera, FALSE)
30 if (index < first_day)
32 serie_on_horizon = data$getCenteredSerie(index)[predict_from:horizon]
33 if (!any(is.na(serie_on_horizon)))
35 avg = avg + serie_on_horizon
36 nb_no_na_series = nb_no_na_series + 1
41 # The same, in the future
46 if (index > data$getSize())
48 serie_on_horizon = data$getCenteredSerie(index)[predict_from:horizon]
49 if (!any(is.na(serie_on_horizon)))
51 avg = avg + serie_on_horizon
52 nb_no_na_series = nb_no_na_series + 1