X-Git-Url: https://git.auder.net/?p=talweg.git;a=blobdiff_plain;f=R%2FF_Neighbors.R;fp=R%2FS_Neighbors.R;h=f1aecb5ccb637a581e1984f444564786ce561ff6;hp=b8e32cc9df784852099e8596452e6cd60190981c;hb=e030a6e31232332b73187eda25870e843152c174;hpb=31f7d913d4a99d0a4db9bcfe40e31cebf90b22e6 diff --git a/R/S_Neighbors.R b/R/F_Neighbors.R similarity index 88% rename from R/S_Neighbors.R rename to R/F_Neighbors.R index b8e32cc..f1aecb5 100644 --- a/R/S_Neighbors.R +++ b/R/F_Neighbors.R @@ -1,19 +1,19 @@ -#' @include ShapeForecaster.R +#' @include Forecaster.R #' -#' @title Neighbors Shape Forecaster +#' @title Neighbors Forecaster #' #' @description Predict tomorrow as a weighted combination of "futures of the past" days. -#' Inherits \code{\link{ShapeForecaster}} -NeighborsShapeForecaster = setRefClass( - Class = "NeighborsShapeForecaster", - contains = "ShapeForecaster", +#' Inherits \code{\link{Forecaster}} +NeighborsForecaster = setRefClass( + Class = "NeighborsForecaster", + contains = "Forecaster", methods = list( initialize = function(...) { callSuper(...) }, - predict = function(today, memory, horizon, ...) + predictShape = function(today, memory, horizon, ...) { # (re)initialize computed parameters params <<- list("weights"=NA, "indices"=NA, "window"=NA) @@ -67,8 +67,8 @@ NeighborsShapeForecaster = setRefClass( mix_strategy = ifelse(hasArg("mix_strategy"), list(...)$mix_strategy, "neighb") #or "mult" same_season = ifelse(hasArg("same_season"), list(...)$same_season, TRUE) if (hasArg(h_window)) - return (.predictAux(fdays_indices, today, horizon, list(...)$h_window, kernel, simtype, - simthresh, mix_strategy, FALSE)) + return (.predictShapeAux(fdays_indices, today, horizon, list(...)$h_window, kernel, + simtype, simthresh, mix_strategy, FALSE)) #END GET # Indices for cross-validation; TODO: 45 = magic number @@ -87,8 +87,8 @@ NeighborsShapeForecaster = setRefClass( { nb_jours = nb_jours + 1 # mix_strategy is never used here (simtype != "mix"), therefore left blank - prediction = .predictAux(fdays_indices, i, horizon, h, kernel, simtype, simthresh, - "", FALSE) + prediction = .predictShapeAux(fdays_indices, i, horizon, h, kernel, simtype, + simthresh, "", FALSE) if (!is.na(prediction[1])) error = error + mean((data$getCenteredSerie(i+1)[1:horizon] - prediction)^2) } @@ -110,22 +110,22 @@ NeighborsShapeForecaster = setRefClass( if (simtype == "endo") { - return (.predictAux(fdays_indices, today, horizon, h_best_endo, kernel, "endo", + return (.predictShapeAux(fdays_indices, today, horizon, h_best_endo, kernel, "endo", simthresh, "", TRUE)) } if (simtype == "exo") { - return (.predictAux(fdays_indices, today, horizon, h_best_exo, kernel, "exo", + return (.predictShapeAux(fdays_indices, today, horizon, h_best_exo, kernel, "exo", simthresh, "", TRUE)) } if (simtype == "mix") { - return (.predictAux(fdays_indices, today, horizon, c(h_best_endo,h_best_exo), kernel, - "mix", simthresh, mix_strategy, TRUE)) + return (.predictShapeAux(fdays_indices, today, horizon, c(h_best_endo,h_best_exo), + kernel, "mix", simthresh, mix_strategy, TRUE)) } }, # Precondition: "today" is full (no NAs) - .predictAux = function(fdays_indices, today, horizon, h, kernel, simtype, simthresh, + .predictShapeAux = function(fdays_indices, today, horizon, h, kernel, simtype, simthresh, mix_strategy, final_call) { dat = data$data #HACK: faster this way...