1 #' @include Forecaster.R
3 #' @title Average Forecaster
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",
12 initialize = function(...)
16 predict = function(today, memory, horizon, ...)
18 predicted_shape = predictShape(today, memory, horizon, ...)
19 #Take care of never passing same_day==FALSE (when pjump == Persistence)
21 if (#as.character(substitute(pjump))=="Persistence" && #TODO: doesn't work
22 hasArg("same_day") && list(...)$same_day==FALSE)
26 do.call(pjump, append(list("today"=today,"memory"=memory,"horizon"=horizon), args))
29 pjump(data, today, memory, horizon, params, ...)
30 predicted_shape + tail(data$getSerie(today),1) - predicted_shape[1] + predicted_delta
32 predictShape = function(today, memory, horizon, ...)
34 avg = rep(0., horizon)
35 first_day = max(1, today-memory)
41 serie_on_horizon = data$getCenteredSerie(index)[1:horizon]
44 if (!any(is.na(serie_on_horizon)))
46 avg = avg + serie_on_horizon
47 nb_no_na_series = nb_no_na_series + 1
49 if (index < first_day)