'update'
[talweg.git] / pkg / R / J_Neighbors.R
index 58453ea..ceea803 100644 (file)
@@ -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)] )