inherit = Forecaster,
public = list(
-# predictSerie = function(data, today, memory, horizon, ...)
-# {
-# # Parameters (potentially) computed during shape prediction stage
-# predicted_shape = self$predictShape(data, today, memory, horizon, ...)
-## predicted_delta = private$.pjump(data,today,memory,horizon,private$.params,...)
-# # Predicted shape is aligned it on the end of current day + jump
-## predicted_shape+tail(data$getSerie(today),1)-predicted_shape[1]+predicted_delta
-# predicted_shape
-# },
+ predictSerie = function(data, today, memory, horizon, ...)
+ {
+ # This method predict shape + level at the same time, all in next call
+ self$predictShape(data, today, memory, horizon, ...)
+ },
predictShape = function(data, today, memory, horizon, ...)
{
# (re)initialize computed parameters
}
# Indices of similar days for cross-validation; TODO: 45 = magic number
- sdays = getSimilarDaysIndices(today, limit=45, same_season=FALSE)
+ sdays = getSimilarDaysIndices(today, data, limit=45, same_season=FALSE)
cv_days = intersect(fdays,sdays)
# Limit to 20 most recent matching days (TODO: 20 == magic number)
{
fdays = fdays[ fdays < today ]
# TODO: 3 = magic number
- if (length(fdays) < 1)
+ if (length(fdays) < 3)
return (NA)
# Neighbors: days in "same season"
- sdays = getSimilarDaysIndices(today, limit=45, same_season=TRUE, data)
+ sdays = getSimilarDaysIndices(today, data, limit=45, same_season=TRUE)
indices = intersect(fdays,sdays)
+ if (length(indices) <= 1)
+ return (NA)
levelToday = data$getLevel(today)
distances = sapply(indices, function(i) abs(data$getLevel(i)-levelToday))
+ # 2 and 5 below == magic numbers (determined by Bruno & Michel)
same_pollution = (distances <= 2)
- if (sum(same_pollution) < 1) #TODO: 3 == magic number
+ if (sum(same_pollution) == 0)
{
same_pollution = (distances <= 5)
- if (sum(same_pollution) < 1)
+ if (sum(same_pollution) == 0)
return (NA)
}
indices = indices[same_pollution]
-
- #TODO: we shouldn't need that block
if (length(indices) == 1)
{
if (final_call)
M[i+1,] = c( data$getLevel(indices[i]), as.double(data$getExo(indices[i])) )
sigma = cov(M) #NOTE: robust covariance is way too slow
-# sigma_inv = solve(sigma) #TODO: use pseudo-inverse if needed?
- sigma_inv = MASS::ginv(sigma)
+ # TODO: 10 == magic number; more robust way == det, or always ginv()
+ sigma_inv =
+ if (length(indices) > 10)
+ solve(sigma)
+ else
+ MASS::ginv(sigma)
# Distances from last observed day to days in the past
distances2 = sapply(seq_along(indices), function(i) {