Commit | Line | Data |
---|---|---|
25b75559 | 1 | #' Persistence Forecaster |
3d69ff21 | 2 | #' |
c4c329f6 BA |
3 | #' Look for the most recent similar day in the past, and return its corresponding curve. |
4 | #' "Similar day" means "same day in the week". | |
5 | #' | |
6 | #' @format R6 class, inherits Forecaster | |
7 | #' @alias F_Persistence | |
546b0cb6 | 8 | #' |
25b75559 | 9 | PersistenceForecaster = R6::R6Class("PersistenceForecaster", |
a66a84b5 | 10 | inherit = Forecaster, |
3d69ff21 | 11 | |
25b75559 | 12 | public = list( |
98e958ca | 13 | predictShape = function(data, today, memory, horizon, ...) |
3d69ff21 | 14 | { |
e5aa669a | 15 | # Return centered last (similar) day curve, avoiding NAs until memory is run |
09cf9c19 | 16 | first_day = max(1, today-memory) |
e5aa669a BA |
17 | same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE) |
18 | # If 'same_day', get the last known future of similar day: -7 + 1 == -6 | |
19 | index = today - ifelse(same_day,6,0) | |
09cf9c19 BA |
20 | repeat |
21 | { | |
22 | { | |
2057c793 | 23 | last_serie = data$getCenteredSerie(index)[1:horizon] |
e5aa669a | 24 | index = index - ifelse(same_day,7,1) |
09cf9c19 | 25 | }; |
e5aa669a BA |
26 | if (!any(is.na(last_serie))) |
27 | return (last_serie); | |
09cf9c19 BA |
28 | if (index < first_day) |
29 | return (NA) | |
30 | } | |
3d69ff21 BA |
31 | } |
32 | ) | |
33 | ) |