a few simplifications in computeFilaments, prepare markdown report
[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}}
7AverageForecaster = R6::R6Class("AverageForecaster",
a66a84b5 8 inherit = Forecaster,
3d69ff21 9
25b75559 10 public = list(
98e958ca 11 predictShape = function(data, today, memory, horizon, ...)
3d69ff21
BA
12 {
13 avg = rep(0., horizon)
09cf9c19
BA
14 first_day = max(1, today-memory)
15 index = today-7 + 1
16 nb_no_na_series = 0
17 repeat
3d69ff21 18 {
09cf9c19 19 {
98e958ca 20 serie_on_horizon = data$getCenteredSerie(index)[1:horizon]
09cf9c19
BA
21 index = index - 7
22 };
23 if (!any(is.na(serie_on_horizon)))
24 {
25 avg = avg + serie_on_horizon
26 nb_no_na_series = nb_no_na_series + 1
27 };
28 if (index < first_day)
29 break
3d69ff21 30 }
09cf9c19 31 avg / nb_no_na_series
3d69ff21
BA
32 }
33 )
34)