Commit | Line | Data |
---|---|---|
e030a6e3 | 1 | #' @include Forecaster.R |
3d69ff21 | 2 | #' |
e030a6e3 | 3 | #' @title Persistence Forecaster |
3d69ff21 | 4 | #' |
09cf9c19 | 5 | #' @description Return the last centered last (similar) day curve. |
e030a6e3 BA |
6 | #' Inherits \code{\link{Forecaster}} |
7 | PersistenceForecaster = setRefClass( | |
8 | Class = "PersistenceForecaster", | |
9 | contains = "Forecaster", | |
3d69ff21 BA |
10 | |
11 | methods = list( | |
12 | initialize = function(...) | |
13 | { | |
14 | callSuper(...) | |
15 | }, | |
e030a6e3 | 16 | predictShape = function(today, memory, horizon, ...) |
3d69ff21 | 17 | { |
09cf9c19 BA |
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 | } | |
3d69ff21 BA |
32 | } |
33 | ) | |
34 | ) |