X-Git-Url: https://git.auder.net/?p=talweg.git;a=blobdiff_plain;f=R%2FS_Persistence.R;h=08647e31b113cd2f4c029987419551fde2ecd831;hp=017402f3ca53e4eeebfe00d7f02b0f3c80a8724f;hb=09cf9c19b5c6a04bc23c58b7ac8a4bbae2c6827d;hpb=3d69ff21e577fc7bb082257280661b64536c20e8 diff --git a/R/S_Persistence.R b/R/S_Persistence.R index 017402f..08647e3 100644 --- a/R/S_Persistence.R +++ b/R/S_Persistence.R @@ -2,8 +2,8 @@ #' #' @title Persistence Shape Forecaster #' -#' @description Return the last centered last (similar) day curve (may be a lot of NAs, -#' but we cannot do better). Inherits \code{\link{ShapeForecaster}} +#' @description Return the last centered last (similar) day curve. +#' Inherits \code{\link{ShapeForecaster}} PersistenceShapeForecaster = setRefClass( Class = "PersistenceShapeForecaster", contains = "ShapeForecaster", @@ -15,11 +15,20 @@ PersistenceShapeForecaster = setRefClass( }, predict = function(today, memory, horizon, ...) { - #return centered last (similar) day curve (may be a lot of NAs, but we cannot do better) - last_similar_serie = data$getCenteredSerie(today-6)[1:horizon] - if (any(is.na(last_similar_serie))) #TODO: - return (NA) - last_similar_serie + #return centered last (similar) day curve, avoiding NAs until memory is run + first_day = max(1, today-memory) + index = today-7 + 1 + repeat + { + { + last_similar_serie = data$getCenteredSerie(index)[1:horizon] + index = index - 7 + }; + if (!any(is.na(last_similar_serie))) + return (last_similar_serie); + if (index < first_day) + return (NA) + } } ) )