fixes and improvements
[talweg.git] / R / S_Persistence.R
CommitLineData
3d69ff21
BA
1#' @include ShapeForecaster.R
2#'
3#' @title Persistence Shape Forecaster
4#'
09cf9c19
BA
5#' @description Return the last centered last (similar) day curve.
6#' Inherits \code{\link{ShapeForecaster}}
3d69ff21
BA
7PersistenceShapeForecaster = 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 {
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)