X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FcomputeError.R;h=3aa028fb88282b41a4f55b92545f1de030e8dd94;hb=c8ef2ddb2d1f28b8356a6c0aa7c8495406226a32;hp=b57e60732e6ad42b7241bf165354eb27ab142fde;hpb=af3b84f4cacade7d83221ca0249b546c50ddf340;p=talweg.git diff --git a/pkg/R/computeError.R b/pkg/R/computeError.R index b57e607..3aa028f 100644 --- a/pkg/R/computeError.R +++ b/pkg/R/computeError.R @@ -1,17 +1,21 @@ #' Compute error #' -#' Obtain the errors between forecast and data +#' Compute the errors between forecasted and measured series. #' -#' @param data Dataset, object of class \code{Data} output of \code{getData} -#' @param forecast Forecast object, class \code{Forecast} output of \code{computeForecast} -#' @param horizon Horizon where to compute the error (<= horizon used in \code{computeForecast}) +#' @param data Object of class \code{Data} output of \code{getData} +#' @param pred Object of class \code{Forecast} output of \code{computeForecast} +#' @param horizon Horizon where to compute the error +#' (<= horizon used in \code{computeForecast}) #' -#' @return A list (abs,MAPE) of lists (day,indices) +#' @return A list (abs,MAPE) of lists (day,indices). The "indices" slots contain series +#' of size L where L is the number of predicted days; i-th value is the averaged error +#' (absolute or MAPE) on day i. The "day" slots contain curves of errors, for each time +#' step, averaged on the L forecasting days. #' #' @export -computeError = function(data, forecast, horizon=data$getStdHorizon()) +computeError = function(data, pred, horizon=data$getStdHorizon()) { - L = forecast$getSize() + L = pred$getSize() mape_day = rep(0, horizon) abs_day = rep(0, horizon) mape_indices = rep(NA, L) @@ -20,17 +24,17 @@ computeError = function(data, forecast, horizon=data$getStdHorizon()) nb_no_NA_data = 0 for (i in seq_len(L)) { - index = forecast$getIndexInData(i) + index = pred$getIndexInData(i) serie = data$getSerie(index+1)[1:horizon] - pred = forecast$getSerie(i)[1:horizon] - if (!any(is.na(serie)) && !any(is.na(pred))) + forecast = pred$getForecast(i)[1:horizon] + if (!any(is.na(serie)) && !any(is.na(forecast))) { nb_no_NA_data = nb_no_NA_data + 1 - mape_increment = abs(serie - pred) / serie + mape_increment = abs(serie - forecast) / serie mape_increment[is.nan(mape_increment)] = 0. # 0 / 0 mape_increment[!is.finite(mape_increment)] = 1. # >0 / 0 mape_day = mape_day + mape_increment - abs_increment = abs(serie - pred) + abs_increment = abs(serie - forecast) abs_day = abs_day + abs_increment mape_indices[i] = mean(mape_increment) abs_indices[i] = mean(abs_increment)