X-Git-Url: https://git.auder.net/?p=talweg.git;a=blobdiff_plain;f=pkg%2FR%2FJ_Neighbors.R;h=58453ea8da2d460fcefd566f13bcefa6a8213f1c;hp=40341d9eb9cf77df34226a8c0f6f78180d6226ac;hb=d2ab47a744d8fb29c03a76a7ca2368dae53f9a57;hpb=4d376294a6286ca1548d978055731dac175ffa3a diff --git a/pkg/R/J_Neighbors.R b/pkg/R/J_Neighbors.R index 40341d9..58453ea 100644 --- a/pkg/R/J_Neighbors.R +++ b/pkg/R/J_Neighbors.R @@ -10,7 +10,8 @@ #' #' @aliases J_Neighbors #' -getNeighborsJumpPredict = function(data, today, memory, horizon, params, ...) +getNeighborsJumpPredict = function(data, today, memory, predict_from, horizon, + params, ...) { first_day = max(1, today-memory) filter = (params$indices >= first_day) @@ -18,7 +19,10 @@ getNeighborsJumpPredict = function(data, today, memory, horizon, params, ...) weights = params$weights[filter] gaps = sapply(indices, function(i) { - head( data$getSerie(i+1),1 ) - tail( data$getSerie(i),1 ) + if (predict_from >= 2) + data$getSerie(i+1)[predict_from] - data$getSerie(i+1)[predict_from-1] + else + head(data$getSerie(i+1),1) - tail(data$getSerie(i),1) }) scal_product = weights * gaps norm_fact = sum( weights[!is.na(scal_product)] )