From: Benjamin Auder Date: Wed, 29 Mar 2017 20:24:39 +0000 (+0200) Subject: fix F_Neighbors.R X-Git-Url: https://git.auder.net/images/assets/doc/html/css/index.css?a=commitdiff_plain;h=eef545170c5a76b710184db6b695c15b20759177;p=talweg.git fix F_Neighbors.R --- diff --git a/pkg/R/F_Neighbors.R b/pkg/R/F_Neighbors.R index 9ba72b8..c9eda05 100644 --- a/pkg/R/F_Neighbors.R +++ b/pkg/R/F_Neighbors.R @@ -55,32 +55,29 @@ NeighborsForecaster = R6::R6Class("NeighborsForecaster", } # TODO: 7 == magic number - if (simtype != "endo") - { - best_window_exo = optimize( - errorOnLastNdays, c(0,7), simtype="exo")$minimum - } - if (simtype != "exo") + if (simtype=="endo" || simtype=="mix") { best_window_endo = optimize( errorOnLastNdays, c(0,7), simtype="endo")$minimum } - - if (simtype == "endo") - { - return (private$.predictShapeAux(data, fdays, today, horizon, local, - best_window_endo, "endo", TRUE)) - } - if (simtype == "exo") + if (simtype=="exo" || simtype=="mix") { - return (private$.predictShapeAux(data, fdays, today, horizon, local, - best_window_exo, "exo", TRUE)) - } - if (simtype == "mix") - { - return(private$.predictShapeAux(data, fdays, today, horizon, local, - c(best_window_endo,best_window_exo), "mix", TRUE)) + best_window_exo = optimize( + errorOnLastNdays, c(0,7), simtype="exo")$minimum } + + best_window = + if (simtype == "endo") + best_window_endo + else if (simtype == "exo") + best_window_exo + else if (simtype == "mix") + c(best_window_endo,best_window_exo) + else #none: value doesn't matter + 1 + + return(private$.predictShapeAux(data, fdays, today, horizon, local, + best_window, simtype, TRUE)) } ), private = list( @@ -212,8 +209,10 @@ NeighborsForecaster = R6::R6Class("NeighborsForecaster", window_endo else if (simtype=="exo") window_exo - else #mix + else if (simtype=="mix") c(window_endo,window_exo) + else #none + 1 } return (prediction)