revise package structure: always predict from 1am to horizon, dataset not cut at...
[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#'
d2ab47a7
BA
13getNeighborsJumpPredict = function(data, today, memory, predict_from, horizon,
14 params, ...)
3d69ff21 15{
09cf9c19 16 first_day = max(1, today-memory)
ee8b1b4e 17 filter = (params$indices >= first_day)
e030a6e3
BA
18 indices = params$indices[filter]
19 weights = params$weights[filter]
99f83c9a 20
09cf9c19 21 gaps = sapply(indices, function(i) {
d2ab47a7
BA
22 if (predict_from >= 2)
23 data$getSerie(i+1)[predict_from] - data$getSerie(i+1)[predict_from-1]
24 else
25 head(data$getSerie(i+1),1) - tail(data$getSerie(i),1)
3d69ff21 26 })
09cf9c19
BA
27 scal_product = weights * gaps
28 norm_fact = sum( weights[!is.na(scal_product)] )
3d69ff21
BA
29 sum(scal_product, na.rm=TRUE) / norm_fact
30}