R CMD check OK
[talweg.git] / pkg / R / J_Neighbors.R
CommitLineData
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 13getNeighborsJumpPredict = 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 gaps = sapply(indices, function(i) {
c36568fa 21 head( data$getSerie(i+1),1 ) - tail( data$getSerie(i),1 )
3d69ff21 22 })
09cf9c19
BA
23 scal_product = weights * gaps
24 norm_fact = sum( weights[!is.na(scal_product)] )
3d69ff21
BA
25 sum(scal_product, na.rm=TRUE) / norm_fact
26}