Initial commit
[talweg.git] / R / D_Neighbors.R
1 #' Obtain delta forecast by the Neighbors method
2 #'
3 #' @inheritParams getForecast
4 #' @inheritParams getZeroDeltaForecast
5 getNeighborsDeltaForecast = function(data, today, memory, horizon, shape_params, ...)
6 {
7 if (any(is.na(shape_params$weights) | is.na(shape_params$indices)))
8 return (NA)
9
10 gaps = sapply(shape_params$indices, function(i) {
11 data$getSerie(i+1)[1] - tail(data$getSerie(i), 1)
12 })
13
14 scal_product = shape_params$weights * gaps
15 norm_fact = sum( shape_params$weights[!is.na(scal_product)] )
16 sum(scal_product, na.rm=TRUE) / norm_fact
17 }