Commit | Line | Data |
---|---|---|
e030a6e3 | 1 | #' @include Forecaster.R |
3d69ff21 | 2 | #' |
25b75559 | 3 | #' Persistence Forecaster |
3d69ff21 | 4 | #' |
25b75559 BA |
5 | #' Return the last centered (similar) day curve. |
6 | #' Inherits \code{\link{Forecaster}} | |
546b0cb6 | 7 | #' |
25b75559 | 8 | PersistenceForecaster = R6::R6Class("PersistenceForecaster", |
a66a84b5 | 9 | inherit = Forecaster, |
3d69ff21 | 10 | |
25b75559 | 11 | public = list( |
98e958ca | 12 | predictShape = function(data, today, memory, horizon, ...) |
3d69ff21 | 13 | { |
e5aa669a | 14 | # Return centered last (similar) day curve, avoiding NAs until memory is run |
09cf9c19 | 15 | first_day = max(1, today-memory) |
e5aa669a | 16 | same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE) |
72b9c501 | 17 | realtime = ifelse(hasArg("realtime"), list(...)$realtime, FALSE) |
e5aa669a BA |
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 | { | |
72b9c501 BA |
23 | last_serie = |
24 | data$getCenteredSerie(index,hat=(index==today && realtime))[1:horizon] | |
e5aa669a | 25 | index = index - ifelse(same_day,7,1) |
09cf9c19 | 26 | }; |
e5aa669a BA |
27 | if (!any(is.na(last_serie))) |
28 | return (last_serie); | |
09cf9c19 BA |
29 | if (index < first_day) |
30 | return (NA) | |
31 | } | |
3d69ff21 BA |
32 | } |
33 | ) | |
34 | ) |