From: Benjamin Auder Date: Tue, 30 May 2017 10:58:29 +0000 (+0200) Subject: prepare last changes X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/images/img/doc/css/%24%7BgetWhatsApp%28link%29%7D?a=commitdiff_plain;h=7c4b2952874de1d40a742e72efe51999b99050f5;p=talweg.git prepare last changes --- diff --git a/pkg/R/Data.R b/pkg/R/Data.R index d35c88a..8aa149d 100644 --- a/pkg/R/Data.R +++ b/pkg/R/Data.R @@ -2,19 +2,19 @@ #' #' Data encapsulation, in the form of a few lists (time-series + exogenous variables). #' -#' The private field .tv is a list where each cell contains the hourly variables for a +#' The private field .tvp is a list where each cell contains the hourly variables for a #' period of time of 24 hours, from 1am to next midnight. The other lists contain #' informations on series' levels and exogenous variables (both measured and predicted). #' #' @usage # Data$new() #' -#' @field .tv List of "time-values"; in each cell: +#' @field .tvp List of "time-values"; in each cell: #' \itemize{ #' \item time: vector of times #' \item serie: (measured) serie +#' \item level_hat: predicted level for current day #' } #' @field .level Vector of measured levels -#' @field .level_hat Vector of predicted levels #' @field .exo List of measured exogenous variables, cell = numerical vector. #' @field .exo_hat List of predicted exogenous variables, cell = numerical vector. #' @@ -34,7 +34,7 @@ #' \item{\code{getLevel(index)}}{ #' Measured level at specified index.} #' \item{\code{getLevelHat(index)}}{ -#' Predicted level at specified index.} +#' Predicted level vector at specified index (by hour).} #' \item{\code{getCenteredSerie(index)}}{ #' Centered serie at specified index.} #' \item{\code{getCenteredSeries(indices)}}{ @@ -50,42 +50,40 @@ #' Data = R6::R6Class("Data", private = list( - .tv = list(), + .tvp = list(), .level = vector("double",0), - .level_hat = vector("double",0), .exo = list(), .exo_hat = list() ), public = list( getSize = function() - length(private$.tv) + length(private$.tvp) , append = function(time=NULL, value=NULL, level_hat=NULL, exo=NULL, exo_hat=NULL) { - if (!is.null(time) && !is.null(value)) + if (!is.null(time) && !is.null(value) && !is.null(level_hat)) { - L = length(private$.tv) - if (L == 0 || strftime( tail(private$.tv[[L]]$time,1), + L = length(private$.tvp) + if (L == 0 || strftime( tail(private$.tvp[[L]]$time,1), format="%H:%M:%S", tz="GMT" ) == "00:00:00") { # Append a new cell - private$.tv[[L+1]] <- list("time"=time, "serie"=value) + private$.tvp[[L+1]] <- list("time"=time, "serie"=value, "level_hat"=level_hat) } else { # Complete current cell - private$.tv[[L]]$time = c(private$.tv[[L]]$time, time) - private$.tv[[L]]$serie = c(private$.tv[[L]]$serie, value) + private$.tvp[[L]]$time <- c(private$.tvp[[L]]$time, time) + private$.tvp[[L]]$serie <- c(private$.tvp[[L]]$serie, value) + private$.tvp[[L]]$level_hat <- c(private$.tvp[[L]]$levem_hat, level_hat) } } - if (strftime( tail(private$.tv[[length(private$.tv)]]$time,1), - format="%H:%M:%S", tz="GMT" ) == "00:00:00") + if (strftime( tail(private$.tvp[[length(private$.tvp)]]$time,1), + format="%H:%M:%S", tz="GMT" ) == "00:00:00") { private$.level = c(private$.level, - mean(private$.tv[[length(private$.tv)]]$serie, na.rm=TRUE)) + mean(private$.tvp[[length(private$.tvp)]]$serie, na.rm=TRUE)) } - if (!is.null(level_hat)) - private$.level_hat = c(private$.level_hat, level_hat) if (!is.null(exo)) private$.exo[[length(private$.exo)+1]] = exo if (!is.null(exo_hat)) @@ -94,12 +92,12 @@ Data = R6::R6Class("Data", getTime = function(index) { index = dateIndexToInteger(index, self) - private$.tv[[index]]$time + private$.tvp[[index]]$time }, getSerie = function(index) { index = dateIndexToInteger(index, self) - private$.tv[[index]]$serie + private$.tvp[[index]]$serie }, getSeries = function(indices) sapply(indices, function(i) self$getSerie(i)) @@ -112,12 +110,12 @@ Data = R6::R6Class("Data", getLevelHat = function(index) { index = dateIndexToInteger(index, self) - private$.level_hat[index] + private$.tvp[[index]]$level_hat }, getCenteredSerie = function(index) { index = dateIndexToInteger(index, self) - private$.tv[[index]]$serie - private$.level[index] + private$.tvp[[index]]$serie - private$.level[index] }, getCenteredSeries = function(indices) sapply(indices, function(i) self$getCenteredSerie(i)) diff --git a/pkg/R/F_Neighbors.R b/pkg/R/F_Neighbors.R index eb0dd79..8eb1ddc 100644 --- a/pkg/R/F_Neighbors.R +++ b/pkg/R/F_Neighbors.R @@ -57,8 +57,8 @@ NeighborsForecaster = R6::R6Class("NeighborsForecaster", if (!opera) tdays = setdiff(tdays, today) #always exclude current day - # Shortcut if window is known or local==TRUE && simtype==none - if (hasArg("window") || (local && simtype=="none")) + # Shortcut if window is known #TODO: cross-validation for number of days, on similar (yerste)days + if (hasArg("window")) { return ( private$.predictShapeAux(data, tdays, today, predict_from, horizon, local, list(...)$window, simtype, opera, TRUE) )