From eef545170c5a76b710184db6b695c15b20759177 Mon Sep 17 00:00:00 2001 From: Benjamin Auder <benjamin.auder@somewhere> Date: Wed, 29 Mar 2017 22:24:39 +0200 Subject: [PATCH] fix F_Neighbors.R --- pkg/R/F_Neighbors.R | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) 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) -- 2.44.0