Commit | Line | Data |
---|---|---|
e030a6e3 BA |
1 | #' @include Forecaster.R |
2 | #' | |
3 | #' @title Level Forecaster | |
4 | #' | |
5 | #' @description Return flat serie of last observed level (on similar day). | |
6 | #' Inherits \code{\link{ShapeForecaster}} | |
7 | LevelForecaster = setRefClass( | |
8 | Class = "LevelForecaster", | |
9 | contains = "Forecaster", | |
10 | ||
11 | methods = list( | |
12 | initialize = function(...) | |
13 | { | |
14 | callSuper(...) | |
15 | }, | |
16 | predict = function(today, memory, horizon, all_memory=TRUE, ...) | |
17 | { | |
18 | #return last (similar) day level, or on all memory if all_memory==TRUE | |
19 | first_day = max(1, today-memory) | |
20 | index = today-7 + 1 | |
21 | if (all_memory) | |
22 | { | |
23 | sum_level = 0. | |
24 | nb_series = 0 | |
25 | } | |
26 | repeat | |
27 | { | |
28 | { | |
29 | last_similar_serie = data$getSerie(index)[1:horizon] | |
30 | index = index - 7 | |
31 | }; | |
32 | #TODO: next test is too strict | |
33 | if (!any(is.na(last_similar_serie))) | |
34 | { | |
35 | if (all_memory) | |
36 | { | |
37 | sum_level = sum_level + mean(last_similar_serie) | |
38 | nb_series = nb_series + 1 | |
39 | } | |
40 | else | |
41 | return (rep(mean(last_similar_serie), horizon)) | |
42 | }; | |
43 | if (index < first_day) | |
44 | { | |
45 | if (all_memory) | |
46 | return (rep(sum_level / nb_series, horizon)) | |
47 | return (NA) | |
48 | } | |
49 | } | |
50 | } | |
51 | ) | |
52 | ) |