Merge branch 'master' of auder.net:talweg
[talweg.git] / R / S_Average.R
... / ...
CommitLineData
1#' @include ShapeForecaster.R
2#'
3#' @title Average Shape Forecaster
4#'
5#' @description Return the (pointwise) average of the all the (similar) centered day curves
6#' in the past. Inherits \code{\link{ShapeForecaster}}
7AverageShapeForecaster = 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)
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)