storage by-rows
[talweg.git] / pkg / R / F_Average.R
CommitLineData
e030a6e3 1#' @include Forecaster.R
3d69ff21 2#'
25b75559 3#' Average Forecaster
3d69ff21 4#'
25b75559
BA
5#' Return the (pointwise) average of the all the (similar) centered day curves
6#' in the past. Inherits \code{\link{Forecaster}}
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)