X-Git-Url: https://git.auder.net/?p=talweg.git;a=blobdiff_plain;f=pkg%2FR%2FF_Neighbors.R;fp=pkg%2FR%2FF_Neighbors.R;h=60eb7b791835c5197c8921c5336d5709c517a773;hp=02536ebf164c9634c6bb7a6f23eeb3cf27fbbea9;hb=dca259e4e9c0235cb113b329c27157ac59d7242b;hpb=794d99e9614315f8a280ac70a991619d4cf45f87 diff --git a/pkg/R/F_Neighbors.R b/pkg/R/F_Neighbors.R index 02536eb..60eb7b7 100644 --- a/pkg/R/F_Neighbors.R +++ b/pkg/R/F_Neighbors.R @@ -61,8 +61,8 @@ NeighborsForecaster = R6::R6Class("NeighborsForecaster", if (!opera) tdays = setdiff(tdays, today) #always exclude current day - # Shortcut if window is known - if (hasArg("window")) + # Shortcut if window is known or local==TRUE && simtype==none + if (hasArg("window") || (local && simtype=="none")) { return ( private$.predictShapeAux(data, tdays, today, predict_from, horizon, local, list(...)$window, simtype, opera, TRUE) ) @@ -129,8 +129,8 @@ NeighborsForecaster = R6::R6Class("NeighborsForecaster", if (local) { - # TODO: 60 == magic number - tdays = getSimilarDaysIndices(today, data, limit=60, same_season=TRUE, + # limit=Inf to not censor any day (TODO: finite limit? 60?) + tdays = getSimilarDaysIndices(today, data, limit=Inf, same_season=TRUE, days_in=tdays_cut, operational=opera) # if (length(tdays) <= 1) # return (NA) @@ -146,6 +146,13 @@ NeighborsForecaster = R6::R6Class("NeighborsForecaster", } return ( data$getSerie(tdays[1])[predict_from:horizon] ) } + max_neighbs = 12 #TODO: 12 = arbitrary number + if (length(tdays) > max_neighbs) + { + distances2 <- .computeDistsEndo(data, today, tdays, predict_from) + ordering <- order(distances2) + tdays <- tdays[ ordering[1:max_neighbs] ] + } } else tdays = tdays_cut #no conditioning @@ -156,19 +163,9 @@ NeighborsForecaster = R6::R6Class("NeighborsForecaster", window_endo = ifelse(simtype=="mix", window[1], window) # Distances from last observed day to selected days in the past + # TODO: redundant computation if local==TRUE distances2 <- .computeDistsEndo(data, today, tdays, predict_from) - if (local) - { - max_neighbs = 12 #TODO: 12 = arbitrary number - if (length(distances2) > max_neighbs) - { - ordering <- order(distances2) - tdays <- tdays[ ordering[1:max_neighbs] ] - distances2 <- distances2[ ordering[1:max_neighbs] ] - } - } - simils_endo <- .computeSimils(distances2, window_endo) }