some last fixes; results still not good...
[talweg.git] / pkg / R / J_Neighbors.R
... / ...
CommitLineData
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#'
13getNeighborsJumpPredict = function(data, today, memory, predict_from, horizon,
14 params, ...)
15{
16 first_day = max(1, today-memory)
17 filter = (params$indices >= first_day)
18 indices = params$indices[filter]
19 weights = params$weights[filter]
20
21 gaps = sapply(indices, function(i) {
22 if (predict_from >= 2)
23 data$getSerie(i)[predict_from] - data$getSerie(i)[predict_from-1]
24 else
25 head(data$getSerie(i),1) - tail(data$getSerie(i-1),1)
26 })
27 scal_product = weights * gaps
28 norm_fact = sum( weights[!is.na(scal_product)] )
29 sum(scal_product, na.rm=TRUE) / norm_fact
30}