storage by-rows
authorBenjamin Auder <benjamin.auder@somewhere>
Thu, 16 Mar 2017 13:47:53 +0000 (14:47 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Thu, 16 Mar 2017 13:47:53 +0000 (14:47 +0100)
12 files changed:
pkg/DESCRIPTION
pkg/R/Data.R
pkg/R/F_Average.R
pkg/R/F_Neighbors.R
pkg/R/F_Persistence.R
pkg/R/F_Zero.R
pkg/R/Forecast.R
pkg/R/Forecaster.R
pkg/R/J_Neighbors.R
pkg/R/J_Persistence.R
pkg/R/J_Zero.R
pkg/R/utils.R

index e83e31e..7fb20cc 100644 (file)
@@ -21,7 +21,7 @@ Suggests:
 LazyData: yes
 URL: http://git.auder.net/?p=talweg.git
 License: MIT + file LICENSE
-RoxygenNote: 5.0.1
+RoxygenNote: 6.0.1
 Collate:
     'Data.R'
     'Forecaster.R'
index 42e8c69..697da05 100644 (file)
@@ -37,6 +37,7 @@
 #' \item{\code{getExoHat(index)}}{
 #'   Get estimated exogenous variables at specified index.}
 #' }
+#'
 Data = R6::R6Class("Data",
        private = list(
                .data = list()
index 7ec4e90..c28125e 100644 (file)
@@ -4,6 +4,7 @@
 #'
 #' Return the (pointwise) average of the all the (similar) centered day curves
 #' in the past. Inherits \code{\link{Forecaster}}
+#'
 AverageForecaster = R6::R6Class("AverageForecaster",
        inherit = Forecaster,
 
index 202b7e2..a3d44a3 100644 (file)
@@ -4,6 +4,7 @@
 #'
 #' Predict tomorrow as a weighted combination of "futures of the past" days.
 #' Inherits \code{\link{Forecaster}}
+#'
 NeighborsForecaster = R6::R6Class("NeighborsForecaster",
        inherit = Forecaster,
 
@@ -100,17 +101,22 @@ NeighborsForecaster = R6::R6Class("NeighborsForecaster",
                                {
                                        delta = data$getCenteredSerie(today) - data$getCenteredSerie(fdays[i])
                                        # Require at least half of non-NA common values to compute the distance
-                                       if (sum(is.na(delta)) <= 0) #length(delta)/2)
-                                               distances2[i] = mean(delta^2) #, na.rm=TRUE)
+                                       if ( !any( is.na(delta) ) )
+                                               distances2[i] = mean(delta^2)
                                }
 
                                sd_dist = sd(distances2)
                                if (sd_dist < .Machine$double.eps)
+                               {
+                                       warning("All computed distances are very close: stdev too small")
                                        sd_dist = 1 #mostly for tests... FIXME:
+                               }
                                simils_endo =
                                        if (kernel=="Gauss")
                                                exp(-distances2/(sd_dist*h_endo^2))
-                                       else { #Epanechnikov
+                                       else
+                                       {
+                                               # Epanechnikov
                                                u = 1 - distances2/(sd_dist*h_endo^2)
                                                u[abs(u)>1] = 0.
                                                u
@@ -138,10 +144,17 @@ NeighborsForecaster = R6::R6Class("NeighborsForecaster",
                                }
 
                                sd_dist = sd(distances2)
+                               if (sd_dist < .Machine$double.eps)
+                               {
+                                       warning("All computed distances are very close: stdev too small")
+                                       sd_dist = 1 #mostly for tests... FIXME:
+                               }
                                simils_exo =
                                        if (kernel=="Gauss")
                                                exp(-distances2/(sd_dist*h_exo^2))
-                                       else { #Epanechnikov
+                                       else
+                                       {
+                                               # Epanechnikov
                                                u = 1 - distances2/(sd_dist*h_exo^2)
                                                u[abs(u)>1] = 0.
                                                u
@@ -166,13 +179,12 @@ NeighborsForecaster = R6::R6Class("NeighborsForecaster",
                                private$.params$weights <- similarities
                                private$.params$indices <- fdays
                                private$.params$window <-
-                                       if (simtype=="endo") {
+                                       if (simtype=="endo")
                                                h_endo
-                                       } else if (simtype=="exo") {
+                                       else if (simtype=="exo")
                                                h_exo
-                                       } else { #mix
+                                       else #mix
                                                c(h_endo,h_exo)
-                                       }
                        }
 
                        return (prediction)
index 220e04c..1d9fd19 100644 (file)
@@ -4,6 +4,7 @@
 #'
 #' Return the last centered (similar) day curve.
 #' Inherits \code{\link{Forecaster}}
+#'
 PersistenceForecaster = R6::R6Class("PersistenceForecaster",
        inherit = Forecaster,
 
index 4f57ba2..f5d6b89 100644 (file)
@@ -3,6 +3,7 @@
 #' Zero Forecaster
 #'
 #' Return 0 (and then adjust). Inherits \code{\link{Forecaster}}
+#'
 ZeroForecaster = R6::R6Class("ZeroForecaster",
        inherit = Forecaster,
 
index bcafd3a..c64d24f 100644 (file)
@@ -29,6 +29,7 @@
 #' \item{\code{getIndexInData(index)}}{
 #'   Get index in data which corresponds to current forecast.}
 #' }
+#'
 Forecast = R6::R6Class("Forecast",
        private = list(
                .pred = list(),
index da8579b..cedb2b6 100644 (file)
@@ -19,7 +19,9 @@
 #'   Predict a new shape of \code{horizon} values at day index \code{today}
 #'   using \code{memory} days in the past.}
 #' \item{\code{getParameters()}}{
-#'   Return (internal) parameters.}}
+#'   Return (internal) parameters.}
+#' }
+#'
 Forecaster = R6::R6Class("Forecaster",
        private = list(
                .params = list(),
index 33ba00d..3c9bc30 100644 (file)
@@ -2,6 +2,7 @@
 #'
 #' @inheritParams computeForecast
 #' @inheritParams getZeroJumpPredict
+#'
 getNeighborsJumpPredict = function(data, today, memory, horizon, params, ...)
 {
        first_day = max(1, today-memory)
index 7a7daef..5d156cc 100644 (file)
@@ -2,6 +2,7 @@
 #'
 #' @inheritParams computeForecast
 #' @inheritParams getZeroJumpPredict
+#'
 getPersistenceJumpPredict = function(data, today, memory, horizon, params, ...)
 {
        #return gap between end of similar day curve and first day of tomorrow (in the past)
index 3c6af47..d9140a5 100644 (file)
@@ -3,6 +3,7 @@
 #' @inheritParams computeForecast
 #' @param today Index of the current day (predict tomorrow)
 #' @param params Optional parameters computed by the main forecaster
+#'
 getZeroJumpPredict = function(data, today, memory, horizon, params, ...)
 {
        0
index 64c3c0a..3486ee9 100644 (file)
@@ -98,17 +98,6 @@ getSimilarDaysIndices = function(index, limit, same_season)
        return ( days[1:min(limit,length(days))] )
 }
 
-#' getSerie
-#'
-#' Return a time-serie from its centered version + level
-#'
-#' @param data A list as returned by \code{getData}
-#' @param index The index to return
-#'
-#' @export
-getSerie = function(data, index)
-       data[[index]]$centered_serie + data[[index]]$level
-
 #' getNoNA2
 #'
 #' Get indices in data of no-NA series followed by no-NA, within [first,last] range.