Commit | Line | Data |
---|---|---|
3d69ff21 BA |
1 | #' @include ShapeForecaster.R |
2 | #' | |
3 | #' @title Average Shape Forecaster | |
4 | #' | |
09cf9c19 BA |
5 | #' @description Return the (pointwise) average of the all the (similar) centered day curves |
6 | #' in the past. Inherits \code{\link{ShapeForecaster}} | |
3d69ff21 BA |
7 | AverageShapeForecaster = setRefClass( |
8 | Class = "AverageShapeForecaster", | |
9 | contains = "ShapeForecaster", | |
10 | ||
11 | methods = list( | |
12 | initialize = function(...) | |
13 | { | |
14 | callSuper(...) | |
15 | }, | |
16 | predict = function(today, memory, horizon, ...) | |
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 | ) |