Commit | Line | Data |
---|---|---|
af3b84f4 | 1 | #' Compute error |
3d69ff21 | 2 | #' |
af3b84f4 | 3 | #' Obtain the errors between forecast and data |
3d69ff21 BA |
4 | #' |
5 | #' @param data Dataset, object of class \code{Data} output of \code{getData} | |
72b9c501 | 6 | #' @param pred Forecast object, class \code{Forecast} output of \code{computeForecast} |
2057c793 BA |
7 | #' @param horizon Horizon where to compute the error |
8 | #' (<= horizon used in \code{computeForecast}) | |
3d69ff21 BA |
9 | #' |
10 | #' @return A list (abs,MAPE) of lists (day,indices) | |
11 | #' | |
12 | #' @export | |
72b9c501 | 13 | computeError = function(data, pred, horizon=data$getStdHorizon()) |
3d69ff21 BA |
14 | { |
15 | L = forecast$getSize() | |
16 | mape_day = rep(0, horizon) | |
17 | abs_day = rep(0, horizon) | |
18 | mape_indices = rep(NA, L) | |
19 | abs_indices = rep(NA, L) | |
20 | ||
21 | nb_no_NA_data = 0 | |
22 | for (i in seq_len(L)) | |
23 | { | |
24 | index = forecast$getIndexInData(i) | |
25 | serie = data$getSerie(index+1)[1:horizon] | |
72b9c501 BA |
26 | forecast = pred$getForecast(i)[1:horizon] |
27 | if (!any(is.na(serie)) && !any(is.na(forecast))) | |
3d69ff21 BA |
28 | { |
29 | nb_no_NA_data = nb_no_NA_data + 1 | |
72b9c501 | 30 | mape_increment = abs(serie - forecast) / serie |
3d69ff21 BA |
31 | mape_increment[is.nan(mape_increment)] = 0. # 0 / 0 |
32 | mape_increment[!is.finite(mape_increment)] = 1. # >0 / 0 | |
33 | mape_day = mape_day + mape_increment | |
72b9c501 | 34 | abs_increment = abs(serie - forecast) |
3d69ff21 BA |
35 | abs_day = abs_day + abs_increment |
36 | mape_indices[i] = mean(mape_increment) | |
37 | abs_indices[i] = mean(abs_increment) | |
38 | } | |
39 | } | |
40 | ||
41 | list( | |
42 | "abs" = list( | |
43 | "day" = abs_day / nb_no_NA_data, | |
44 | "indices" = abs_indices), | |
45 | "MAPE" = list( | |
46 | "day" = mape_day / nb_no_NA_data, | |
47 | "indices" = mape_indices) ) | |
48 | } |