X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FForecaster.R;fp=pkg%2FR%2FForecaster.R;h=71cb667430a94a1a2f91e807c7231bf795f709ae;hb=469529710f56c790ae932b45d13fed2e34bcabf2;hp=0000000000000000000000000000000000000000;hpb=4c59ec9aefef8ea5464723a293b3aa39ee02dc60;p=talweg.git diff --git a/pkg/R/Forecaster.R b/pkg/R/Forecaster.R new file mode 100644 index 0000000..71cb667 --- /dev/null +++ b/pkg/R/Forecaster.R @@ -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 + } + ) +)