X-Git-Url: https://git.auder.net/game/current/git-logo.png?a=blobdiff_plain;f=pkg%2FR%2FcomputeForecast.R;h=e50e63dc950ef13679bd8e8ed4962b008bd5663a;hb=HEAD;hp=c778d66f16043327b0f5fade15fc29d5c77c5ae3;hpb=4f3fdbb8e2ac4bd57a4e27539a58ef0e7ec2304c;p=talweg.git diff --git a/pkg/R/computeForecast.R b/pkg/R/computeForecast.R index c778d66..e50e63d 100644 --- a/pkg/R/computeForecast.R +++ b/pkg/R/computeForecast.R @@ -3,6 +3,8 @@ #' Predict time-series curves ("today" from predict_from to horizon) at the selected days #' indices ("today" from 1am to predict_from-1). This function just runs a loop over all #' requested indices, and stores the individual forecasts into a Forecast object. +#' Note: in training stage ts_hat(day+1) = f(ts(day), exo(day+1)), +#' and in production ts_hat(day+1) = f(ts(day), exo_hat(day+1)) #' #' @param data Object of class Data, output of \code{getData()}. #' @param indices Indices where to forecast (the day after); integers relative to the @@ -19,23 +21,23 @@ #' \itemize{ #' \item Persistence : use last (similar) day #' \item Neighbors: re-use the weights from F_Neighbors -#' \item Zero: just output 0 (no adjustment) +#' \item LastValue: start serie with last observed value +#' \item Zero: no adjustment => use shape prediction only #' } -#' If pjump=NULL, then no adjustment is performed (output of \code{predictShape()} is -#' used directly). #' @param predict_from First time step to predict. #' @param memory Data depth (in days) to be used for prediction. #' @param horizon Last time step to predict. #' @param ncores Number of cores for parallel execution (1 to disable). +#' @param verbose TRUE to print basic traces (runs beginnings) #' @param ... Additional parameters for the forecasting models. #' #' @return An object of class Forecast #' #' @examples -#' ts_data <- system.file("extdata","pm10_mesures_H_loc.csv",package="talweg") -#' exo_data <- system.file("extdata","meteo_extra_noNAs.csv",package="talweg") -#' data <- getData(ts_data, exo_data, limit=200) -#' pred <- computeForecast(data, 100:130, "Persistence", "Zero", +#' ts_data <- system.file("extdata","intraday_measures.csv",package="talweg") +#' exo_data <- system.file("extdata","daily_exogenous.csv",package="talweg") +#' data <- getData(ts_data, exo_data, date_format="%Y-%m-%d %H:%M:%S", limit=200) +#' pred <- computeForecast(data, 100:130, "Persistence", "LastValue", #' predict_from=8, memory=50, horizon=12, ncores=1) #' \dontrun{ #' #Sketch for real-time mode: @@ -60,7 +62,7 @@ #' } } #' @export computeForecast = function(data, indices, forecaster, pjump, predict_from, - memory=Inf, horizon=length(data$getSerie(1)), ncores=3, ...) + memory=Inf, horizon=length(data$getSerie(1)), ncores=3, verbose=FALSE, ...) { # (basic) Arguments sanity checks predict_from = as.integer(predict_from)[1] @@ -76,19 +78,20 @@ computeForecast = function(data, indices, forecaster, pjump, predict_from, stop("Indices out of range") if (!is.character(forecaster)) stop("forecaster (name): character") - if (!is.null(pjump) && !is.character(pjump)) - stop("pjump (function): character or NULL") + if (!is.character(pjump)) + stop("pjump (function): character") pred = Forecast$new( sapply(indices, function(i) integerIndexToDate(i,data)) ) forecaster_class_name = getFromNamespace( paste(forecaster,"Forecaster",sep=""), "talweg") - if (!is.null(pjump)) - pjump <- getFromNamespace(paste("get",pjump,"JumpPredict",sep=""), "talweg") + pjump <- getFromNamespace(paste("get",pjump,"JumpPredict",sep=""), "talweg") forecaster = forecaster_class_name$new(pjump) computeOneForecast <- function(i) { + if (verbose) + print(paste("Index",i)) list( "forecast" = forecaster$predictSerie(data,i,memory,predict_from,horizon,...), "params" = forecaster$getParameters(),