08647e31b113cd2f4c029987419551fde2ecd831
[talweg.git] / R / S_Persistence.R
1 #' @include ShapeForecaster.R
2 #'
3 #' @title Persistence Shape Forecaster
4 #'
5 #' @description Return the last centered last (similar) day curve.
6 #' Inherits \code{\link{ShapeForecaster}}
7 PersistenceShapeForecaster = setRefClass(
8 Class = "PersistenceShapeForecaster",
9 contains = "ShapeForecaster",
10
11 methods = list(
12 initialize = function(...)
13 {
14 callSuper(...)
15 },
16 predict = 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 )