X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FcomputeError.R;h=7da103288805fa64d84feecdad8689b60e55de66;hb=2057c793ad9929ed5bef8663ea28b896c84df0fc;hp=af4109fcfd8f1bdac215dd6dc46cf473acfc6c74;hpb=99f83c9af27492f6fb9b10f51fb8704ed588f5c1;p=talweg.git diff --git a/pkg/R/computeError.R b/pkg/R/computeError.R index af4109f..7da1032 100644 --- a/pkg/R/computeError.R +++ b/pkg/R/computeError.R @@ -1,15 +1,16 @@ -#' @title Get error +#' Compute error #' -#' @description Obtain the errors between forecast and data +#' Obtain the errors between forecast and data #' #' @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 pred Forecast object, 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) #' #' @export -computeError = function(data, forecast, horizon=data$getStdHorizon()) +computeError = function(data, pred, horizon=data$getStdHorizon()) { L = forecast$getSize() mape_day = rep(0, horizon) @@ -22,15 +23,15 @@ computeError = function(data, forecast, horizon=data$getStdHorizon()) { index = forecast$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)