fix F_Neighbors.R
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 29 Mar 2017 20:24:39 +0000 (22:24 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 29 Mar 2017 20:24:39 +0000 (22:24 +0200)
pkg/R/F_Neighbors.R

index 9ba72b8..c9eda05 100644 (file)
@@ -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)