Commit | Line | Data |
---|---|---|
e030a6e3 | 1 | #' Obtain jump forecast by the Neighbors method |
3d69ff21 | 2 | #' |
99f83c9a | 3 | #' @inheritParams computeForecast |
e030a6e3 | 4 | #' @inheritParams getZeroJumpPredict |
546b0cb6 | 5 | #' |
e030a6e3 | 6 | getNeighborsJumpPredict = function(data, today, memory, horizon, params, ...) |
3d69ff21 | 7 | { |
09cf9c19 | 8 | first_day = max(1, today-memory) |
ee8b1b4e | 9 | filter = (params$indices >= first_day) |
e030a6e3 BA |
10 | indices = params$indices[filter] |
11 | weights = params$weights[filter] | |
99f83c9a | 12 | |
09cf9c19 | 13 | if (any(is.na(weights) | is.na(indices))) |
3d69ff21 BA |
14 | return (NA) |
15 | ||
09cf9c19 | 16 | gaps = sapply(indices, function(i) { |
2057c793 | 17 | head( data$getSerie(i+1), 1) - tail( data$getSerie(i), 1) |
3d69ff21 | 18 | }) |
09cf9c19 BA |
19 | scal_product = weights * gaps |
20 | norm_fact = sum( weights[!is.na(scal_product)] ) | |
3d69ff21 BA |
21 | sum(scal_product, na.rm=TRUE) / norm_fact |
22 | } |