X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FJ_Neighbors.R;h=ceea8037267ee610ef3f09f1ef75bf75b8a8223e;hb=8ab6420267542d34b7428f978aa76ba939b9754b;hp=58453ea8da2d460fcefd566f13bcefa6a8213f1c;hpb=d2ab47a744d8fb29c03a76a7ca2368dae53f9a57;p=talweg.git diff --git a/pkg/R/J_Neighbors.R b/pkg/R/J_Neighbors.R index 58453ea..ceea803 100644 --- a/pkg/R/J_Neighbors.R +++ b/pkg/R/J_Neighbors.R @@ -18,11 +18,14 @@ getNeighborsJumpPredict = function(data, today, memory, predict_from, horizon, indices = params$indices[filter] weights = params$weights[filter] + if (is.na(indices[1])) + return (NA) + gaps = sapply(indices, function(i) { if (predict_from >= 2) - data$getSerie(i+1)[predict_from] - data$getSerie(i+1)[predict_from-1] + data$getSerie(i)[predict_from] - data$getSerie(i)[predict_from-1] else - head(data$getSerie(i+1),1) - tail(data$getSerie(i),1) + head(data$getSerie(i),1) - tail(data$getSerie(i-1),1) }) scal_product = weights * gaps norm_fact = sum( weights[!is.na(scal_product)] )