reorganize folder
[talweg.git] / pkg / R / F_Average.R
1 #' @include Forecaster.R
2 #'
3 #' @title Average Forecaster
4 #'
5 #' @description Return the (pointwise) average of the all the (similar) centered day curves
6 #' in the past. Inherits \code{\link{Forecaster}}
7 AverageForecaster = setRefClass(
8 Class = "AverageForecaster",
9 contains = "Forecaster",
10
11 methods = list(
12 initialize = function(...)
13 {
14 callSuper(...)
15 },
16 predictShape = function(today, memory, horizon, ...)
17 {
18 avg = rep(0., horizon)
19 first_day = max(1, today-memory)
20 index = today-7 + 1
21 nb_no_na_series = 0
22 repeat
23 {
24 {
25 serie_on_horizon = data$getCenteredSerie(index)[1:horizon]
26 index = index - 7
27 };
28 if (!any(is.na(serie_on_horizon)))
29 {
30 avg = avg + serie_on_horizon
31 nb_no_na_series = nb_no_na_series + 1
32 };
33 if (index < first_day)
34 break
35 }
36 avg / nb_no_na_series
37 }
38 )
39 )