fix tests
[talweg.git] / pkg / R / J_Neighbors.R
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.
7 #'
8 #' @inheritParams computeForecast
9 #' @inheritParams getZeroJumpPredict
10 #'
11 #' @aliases J_Neighbors
12 #'
13 getNeighborsJumpPredict = function(data, today, memory, horizon, params, ...)
14 {
15 first_day = max(1, today-memory)
16 filter = (params$indices >= first_day)
17 indices = params$indices[filter]
18 weights = params$weights[filter]
19
20 gaps = sapply(indices, function(i) {
21 head( data$getSerie(i+1),1 ) - tail( data$getSerie(i),1 )
22 })
23 scal_product = weights * gaps
24 norm_fact = sum( weights[!is.na(scal_product)] )
25 sum(scal_product, na.rm=TRUE) / norm_fact
26 }