new version, persistence -7 days
[talweg.git] / R / F_Persistence.R
1 #' @include Forecaster.R
2 #'
3 #' @title Persistence Forecaster
4 #'
5 #' @description Return the last centered last (similar) day curve.
6 #' Inherits \code{\link{Forecaster}}
7 PersistenceForecaster = setRefClass(
8 Class = "PersistenceForecaster",
9 contains = "Forecaster",
10
11 methods = list(
12 initialize = function(...)
13 {
14 callSuper(...)
15 },
16 predictShape = function(today, memory, horizon, ...)
17 {
18 #return centered last (similar) day curve, avoiding NAs until memory is run
19 first_day = max(1, today-memory)
20 index = today-7 + 1
21 repeat
22 {
23 {
24 last_similar_serie = data$getCenteredSerie(index)[1:horizon]
25 index = index - 7
26 };
27 if (!any(is.na(last_similar_serie)))
28 return (last_similar_serie);
29 if (index < first_day)
30 return (NA)
31 }
32 }
33 )
34 )