Commit | Line | Data |
---|---|---|
102bcfda BA |
1 | #' getPersistenceJumpPredict |
2 | #' | |
3 | #' Analog of the PersistenceForecaster: predict the jump after last observed value either | |
4 | #' by re-applying the last jump between similar day and its follower (if argument | |
5 | #' "same_day" is TRUE), or by re-using the very last observed jump (when "same_day" = | |
6 | #' FALSE). | |
3d69ff21 | 7 | #' |
99f83c9a | 8 | #' @inheritParams computeForecast |
e030a6e3 | 9 | #' @inheritParams getZeroJumpPredict |
546b0cb6 | 10 | #' |
3ddf1c12 | 11 | #' @aliases J_Persistence |
102bcfda | 12 | #' |
e030a6e3 | 13 | getPersistenceJumpPredict = function(data, today, memory, horizon, params, ...) |
3d69ff21 | 14 | { |
09cf9c19 BA |
15 | #return gap between end of similar day curve and first day of tomorrow (in the past) |
16 | first_day = max(1, today-memory) | |
e5aa669a BA |
17 | same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE) |
18 | index = today - ifelse(same_day,7,1) | |
09cf9c19 BA |
19 | repeat |
20 | { | |
21 | { | |
e5aa669a | 22 | last_serie_end = tail( data$getSerie(index), 1) |
2057c793 | 23 | last_tomorrow_begin = head( data$getSerie(index+1), 1) |
e5aa669a | 24 | index = index - ifelse(same_day,7,1) |
09cf9c19 | 25 | }; |
e5aa669a BA |
26 | if (!is.na(last_serie_end) && !is.na(last_tomorrow_begin)) |
27 | return (last_tomorrow_begin - last_serie_end); | |
09cf9c19 BA |
28 | if (index < first_day) |
29 | return (NA) | |
30 | } | |
3d69ff21 | 31 | } |