+ fdays = fdays[same_pollution]
+ max_neighbs = 12
+ if (nb_neighbs > max_neighbs)
+ {
+ # Keep only max_neighbs closest neighbors
+ fdays = fdays[
+ sort(distances[same_pollution],index.return=TRUE)$ix[1:max_neighbs] ]
+ }
+ if (length(fdays) == 1) #the other extreme...
+ {
+ if (final_call)
+ {
+ private$.params$weights <- 1
+ private$.params$indices <- fdays
+ private$.params$window <- 1
+ }
+ return ( data$getSerie(fdays[1])[1:horizon] ) #what else?!
+ }
+ }
+ else
+ fdays = fdays_cut #no conditioning
+
+ if (simtype == "endo" || simtype == "mix")
+ {
+ # Compute endogen similarities using given window
+ window_endo = ifelse(simtype=="mix", window[1], window)
+
+ # Distances from last observed day to days in the past
+ serieToday = data$getSerie(today)
+ distances2 = sapply(fdays, function(i) {
+ delta = serieToday - data$getSerie(i)
+ mean(delta^2)
+ })