#' \item rt : Regression Tree
#' \item rr : Ridge Regression
#' }
-#' @param experts Vector of experts to consider (names or indices). Default: all of them.
-#' @param stations Vector of stations to consider (names or indices). Default: all of them.
+#' @param stations List of stations dataframes to consider.
+#' @param experts Vector of experts to consider (names).
#' @param ... Additional arguments to be passed to the Algorithm object.
#'
#' @return A list with the following slots
#' \itemize{
#' \item{data : data frame of all forecasts + measures (may contain NAs) + predictions, with date and station indices.}
#' \item{algo : object of class \code{Algorithm} (or sub-class).}
+#' \item{stations : list of dataframes of stations for this run.}
#' \item{experts : character vector of experts for this run.}
-#' \item{stations : character vector of stations for this run.}
#' }
#'
+#' @examples
+#' data(stations)
+#' r = runAlgorithm("ew", list(st[[1]]), c("P","MA3"))
+#' plotCurves(r)
+#' r2 = runAlgorithm("ml", st[c(1,2)], c("MA3","MA10"))
+#' plotError(r2)
#' @export
-runAlgorithm = function(shortAlgoName, experts=expertsArray, stations=stationsArray, ...)
+runAlgorithm = function(shortAlgoName, stations, experts, ...)
{
- #check, sanitize and format provided arguments
+ #very basic input checks
if (! shortAlgoName %in% names(algoNameDictionary))
- stop(paste("Typo in short algo name:", shortAlgoName))
- if (!is.character(experts) && !is.numeric(experts))
- stop("Wrong argument type: experts should be character or integer")
- if (!is.character(stations) && !is.numeric(stations))
- stop("Wrong argument type: stations should be character or integer")
+ stop("Unknown algorithm:")
experts = unique(experts)
- stations = unique(stations)
- Ka = length(expertsArray)
- Sa = length(stationsArray)
- if (length(experts) > Ka)
- stop("Too many experts specified: at least one of them does not exist")
- if (length(stations) > Sa)
- stop("Too many stations specified: at least one of them does not exist")
- if (is.numeric(experts) && any(experts > Ka))
- stop(paste("Some experts indices are higher than the maximum which is", Ka))
- if (is.numeric(stations) && any(stations > Sa))
- stop(paste("Some stations indices are higher than the maximum which is", Sa))
- if (is.character(experts))
- {
- expertsMismatch = (1:Ka)[! experts %in% expertsArray]
- if (length(expertsMismatch) > 0)
- stop(cat(paste("Typo in experts names:", experts[expertsMismatch]), sep="\n"))
- }
- if (is.character(stations))
- {
- stationsMismatch = (1:Sa)[! stations %in% stationsArray]
- if (length(stationsMismatch) > 0)
- stop(cat(paste("Typo in stations names:", stations[stationsMismatch]), sep="\n"))
- }
- if (!is.character(experts))
- experts = expertsArray[experts]
- if (!is.character(stations))
- stations = stationsArray[stations]
#get data == ordered date indices + forecasts + measures + stations indices (would be DB in prod)
- oracleData = getData(experts, stations)
+ oracleData = getData(stations, experts)
#simulate incremental forecasts acquisition + prediction + get measure
algoData = as.data.frame(matrix(nrow=0, ncol=ncol(oracleData)))