reorganize folder
[talweg.git] / pkg / R / F_Persistence.R
CommitLineData
e030a6e3 1#' @include Forecaster.R
3d69ff21 2#'
e030a6e3 3#' @title Persistence Forecaster
3d69ff21 4#'
e5aa669a 5#' @description Return the last centered (similar) day curve.
e030a6e3
BA
6#' Inherits \code{\link{Forecaster}}
7PersistenceForecaster = 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 {
e5aa669a 18 # Return centered last (similar) day curve, avoiding NAs until memory is run
09cf9c19 19 first_day = max(1, today-memory)
e5aa669a
BA
20 same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE)
21 # If 'same_day', get the last known future of similar day: -7 + 1 == -6
22 index = today - ifelse(same_day,6,0)
09cf9c19
BA
23 repeat
24 {
25 {
e5aa669a
BA
26 last_serie = data$getCenteredSerie(index)[1:horizon]
27 index = index - ifelse(same_day,7,1)
09cf9c19 28 };
e5aa669a
BA
29 if (!any(is.na(last_serie)))
30 return (last_serie);
09cf9c19
BA
31 if (index < first_day)
32 return (NA)
33 }
3d69ff21
BA
34 }
35 )
36)