Commit | Line | Data |
---|---|---|
102bcfda BA |
1 | #' getNeighborsJumpPredict |
2 | #' | |
3 | #' Apply optimized weights on gaps observed on selected neighbors. | |
4 | #' This jump prediction method can only be used in conjunction with the Neighbors | |
5 | #' Forecaster, because it makes use of the optimized parameters to re-apply the weights | |
6 | #' on the jumps observed at days interfaces of the past neighbors. | |
3d69ff21 | 7 | #' |
99f83c9a | 8 | #' @inheritParams computeForecast |
e030a6e3 | 9 | #' @inheritParams getZeroJumpPredict |
546b0cb6 | 10 | #' |
3ddf1c12 | 11 | #' @aliases J_Neighbors |
102bcfda | 12 | #' |
e030a6e3 | 13 | getNeighborsJumpPredict = function(data, today, memory, horizon, params, ...) |
3d69ff21 | 14 | { |
09cf9c19 | 15 | first_day = max(1, today-memory) |
ee8b1b4e | 16 | filter = (params$indices >= first_day) |
e030a6e3 BA |
17 | indices = params$indices[filter] |
18 | weights = params$weights[filter] | |
99f83c9a | 19 | |
09cf9c19 | 20 | if (any(is.na(weights) | is.na(indices))) |
3d69ff21 BA |
21 | return (NA) |
22 | ||
09cf9c19 | 23 | gaps = sapply(indices, function(i) { |
2057c793 | 24 | head( data$getSerie(i+1), 1) - tail( data$getSerie(i), 1) |
3d69ff21 | 25 | }) |
09cf9c19 BA |
26 | scal_product = weights * gaps |
27 | norm_fact = sum( weights[!is.na(scal_product)] ) | |
3d69ff21 BA |
28 | sum(scal_product, na.rm=TRUE) / norm_fact |
29 | } |