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'
#' \item{\code{getExoHat(index)}}{
#' Get estimated exogenous variables at specified index.}
#' }
+#'
Data = R6::R6Class("Data",
private = list(
.data = list()
#'
#' 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,
#'
#' Predict tomorrow as a weighted combination of "futures of the past" days.
#' Inherits \code{\link{Forecaster}}
+#'
NeighborsForecaster = R6::R6Class("NeighborsForecaster",
inherit = Forecaster,
{
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
}
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
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)
#'
#' Return the last centered (similar) day curve.
#' Inherits \code{\link{Forecaster}}
+#'
PersistenceForecaster = R6::R6Class("PersistenceForecaster",
inherit = Forecaster,
#' Zero Forecaster
#'
#' Return 0 (and then adjust). Inherits \code{\link{Forecaster}}
+#'
ZeroForecaster = R6::R6Class("ZeroForecaster",
inherit = Forecaster,
#' \item{\code{getIndexInData(index)}}{
#' Get index in data which corresponds to current forecast.}
#' }
+#'
Forecast = R6::R6Class("Forecast",
private = list(
.pred = list(),
#' 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(),
#'
#' @inheritParams computeForecast
#' @inheritParams getZeroJumpPredict
+#'
getNeighborsJumpPredict = function(data, today, memory, horizon, params, ...)
{
first_day = max(1, today-memory)
#'
#' @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)
#' @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
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.