reorganize folder
[talweg.git] / pkg / R / Forecaster.R
... / ...
CommitLineData
1#' @title Forecaster (abstract class)
2#'
3#' @description Abstract class to represent a forecaster (they all inherit this)
4#'
5#' @field params List of computed parameters, for post-run analysis (dev)
6#' @field data Dataset, object of class Data
7#' @field pjump Function: how to predict the jump at day interface ?
8Forecaster = setRefClass(
9 Class = "Forecaster",
10
11 fields = list(
12 params = "list",
13 data = "Data",
14 pjump = "function"
15 ),
16
17 methods = list(
18 initialize = function(...)
19 {
20 "Initialize (generic) Forecaster object"
21
22 callSuper(...)
23 if (!hasArg(data))
24 stop("Forecaster must be initialized with a Data object")
25 params <<- list()
26 },
27 predict = function(today, memory, horizon, ...)
28 {
29 "Obtain a new forecasted time-serie"
30
31 # Parameters (potentially) computed during shape prediction stage
32 predicted_shape = predictShape(today, memory, horizon, ...)
33 predicted_delta = pjump(data, today, memory, horizon, params, ...)
34 # Predicted shape is aligned it on the end of current day + jump
35 predicted_shape + tail(data$getSerie(today),1) - predicted_shape[1] + predicted_delta
36 },
37 predictShape = function(today, memory, horizon, ...)
38 {
39 "Shape prediction (centered curve)"
40
41 #empty default implementation: to implement in inherited classes
42 },
43 getParameters = function()
44 {
45 params
46 }
47 )
48)