reorganize folder
[talweg.git] / pkg / R / Forecaster.R
diff --git a/pkg/R/Forecaster.R b/pkg/R/Forecaster.R
new file mode 100644 (file)
index 0000000..71cb667
--- /dev/null
@@ -0,0 +1,48 @@
+#' @title Forecaster (abstract class)
+#'
+#' @description Abstract class to represent a forecaster (they all inherit this)
+#'
+#' @field params List of computed parameters, for post-run analysis (dev)
+#' @field data Dataset, object of class Data
+#' @field pjump Function: how to predict the jump at day interface ?
+Forecaster = setRefClass(
+       Class = "Forecaster",
+
+       fields = list(
+               params = "list",
+               data = "Data",
+               pjump = "function"
+       ),
+
+       methods = list(
+               initialize = function(...)
+               {
+                       "Initialize (generic) Forecaster object"
+
+                       callSuper(...)
+                       if (!hasArg(data))
+                               stop("Forecaster must be initialized with a Data object")
+                       params <<- list()
+               },
+               predict = function(today, memory, horizon, ...)
+               {
+                       "Obtain a new forecasted time-serie"
+
+                       # Parameters (potentially) computed during shape prediction stage
+                       predicted_shape = predictShape(today, memory, horizon, ...)
+                       predicted_delta = pjump(data, today, memory, horizon, params, ...)
+                       # Predicted shape is aligned it on the end of current day + jump
+                       predicted_shape + tail(data$getSerie(today),1) - predicted_shape[1] + predicted_delta
+               },
+               predictShape = function(today, memory, horizon, ...)
+               {
+                       "Shape prediction (centered curve)"
+
+                       #empty default implementation: to implement in inherited classes
+               },
+               getParameters = function()
+               {
+                       params
+               }
+       )
+)