Commit | Line | Data |
---|---|---|
e030a6e3 | 1 | #' @include Forecaster.R |
3d69ff21 | 2 | #' |
e030a6e3 | 3 | #' @title Average Forecaster |
3d69ff21 | 4 | #' |
09cf9c19 | 5 | #' @description Return the (pointwise) average of the all the (similar) centered day curves |
e030a6e3 BA |
6 | #' in the past. Inherits \code{\link{Forecaster}} |
7 | AverageForecaster = setRefClass( | |
8 | Class = "AverageForecaster", | |
9 | contains = "Forecaster", | |
3d69ff21 BA |
10 | |
11 | methods = list( | |
12 | initialize = function(...) | |
13 | { | |
14 | callSuper(...) | |
15 | }, | |
e030a6e3 | 16 | predictShape = function(today, memory, horizon, ...) |
3d69ff21 BA |
17 | { |
18 | avg = rep(0., horizon) | |
09cf9c19 BA |
19 | first_day = max(1, today-memory) |
20 | index = today-7 + 1 | |
21 | nb_no_na_series = 0 | |
22 | repeat | |
3d69ff21 | 23 | { |
09cf9c19 BA |
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 | |
3d69ff21 | 35 | } |
09cf9c19 | 36 | avg / nb_no_na_series |
3d69ff21 BA |
37 | } |
38 | ) | |
39 | ) |