name instead of year; ipynb generator debugged, with logging
[talweg.git] / pkg / R / J_Neighbors.R
CommitLineData
e030a6e3 1#' Obtain jump forecast by the Neighbors method
3d69ff21 2#'
99f83c9a 3#' @inheritParams computeForecast
e030a6e3
BA
4#' @inheritParams getZeroJumpPredict
5getNeighborsJumpPredict = function(data, today, memory, horizon, params, ...)
3d69ff21 6{
09cf9c19 7 first_day = max(1, today-memory)
e030a6e3
BA
8 filter = params$indices >= first_day
9 indices = params$indices[filter]
10 weights = params$weights[filter]
99f83c9a 11
09cf9c19 12 if (any(is.na(weights) | is.na(indices)))
3d69ff21
BA
13 return (NA)
14
09cf9c19 15 gaps = sapply(indices, function(i) {
3d69ff21
BA
16 data$getSerie(i+1)[1] - tail(data$getSerie(i), 1)
17 })
09cf9c19
BA
18 scal_product = weights * gaps
19 norm_fact = sum( weights[!is.na(scal_product)] )
3d69ff21
BA
20 sum(scal_product, na.rm=TRUE) / norm_fact
21}