X-Git-Url: https://git.auder.net/?p=talweg.git;a=blobdiff_plain;f=R%2FF_Persistence.R;h=19cf2e410e3e255ddabcc57326321cc1ef510679;hp=f0784840ec6ac74d6db81713cad32cff02d626ae;hb=e5aa669afc0b71278d1a864fb0d4e2aff8032ef1;hpb=e030a6e31232332b73187eda25870e843152c174 diff --git a/R/F_Persistence.R b/R/F_Persistence.R index f078484..19cf2e4 100644 --- a/R/F_Persistence.R +++ b/R/F_Persistence.R @@ -2,7 +2,7 @@ #' #' @title Persistence Forecaster #' -#' @description Return the last centered last (similar) day curve. +#' @description Return the last centered (similar) day curve. #' Inherits \code{\link{Forecaster}} PersistenceForecaster = setRefClass( Class = "PersistenceForecaster", @@ -15,17 +15,19 @@ PersistenceForecaster = setRefClass( }, predictShape = function(today, memory, horizon, ...) { - #return centered last (similar) day curve, avoiding NAs until memory is run + # Return centered last (similar) day curve, avoiding NAs until memory is run first_day = max(1, today-memory) - index = today-7 + 1 + same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE) + # If 'same_day', get the last known future of similar day: -7 + 1 == -6 + index = today - ifelse(same_day,6,0) repeat { { - last_similar_serie = data$getCenteredSerie(index)[1:horizon] - index = index - 7 + last_serie = data$getCenteredSerie(index)[1:horizon] + index = index - ifelse(same_day,7,1) }; - if (!any(is.na(last_similar_serie))) - return (last_similar_serie); + if (!any(is.na(last_serie))) + return (last_serie); if (index < first_day) return (NA) }