forecaster = forecaster_class_name$new( #.pjump =
getFromNamespace(paste("get",pjump,"JumpPredict",sep=""), "talweg"))
- if (ncores > 1 && requireNamespace("parallel",quietly=TRUE))
+ computeOneForecast <- function(i)
{
- p <- parallel::mclapply(seq_along(integer_indices), function(i) {
- list(
- "forecast" = forecaster$predictSerie(
- data, integer_indices[i], memory, predict_from, horizon, ...),
- "params"= forecaster$getParameters(),
- "index" = integer_indices[i] )
- }, mc.cores=ncores)
- }
- else
- {
- p <- lapply(seq_along(integer_indices), function(i) {
- list(
- "forecast" = forecaster$predictSerie(
- data, integer_indices[i], memory, predict_from, horizon, ...),
- "params"= forecaster$getParameters(),
- "index" = integer_indices[i] )
- })
+ list(
+ "forecast" = forecaster$predictSerie(data,i,memory,predict_from,horizon,...),
+ "params" = forecaster$getParameters(),
+ "index" = i )
}
+ p <-
+ if (ncores > 1 && requireNamespace("parallel",quietly=TRUE))
+ parallel::mclapply(integer_indices, computeOneForecast, mc.cores=ncores)
+ else
+ lapply(integer_indices, computeOneForecast)
+
# TODO: find a way to fill pred in //...
for (i in seq_along(integer_indices))
{
# Résultats numériques
Cette partie montre les résultats obtenus avec des variantes de l'algorithme décrit au
-chapitre , en utilisant le package présenté à la section 3. Cet algorithme est
-systématiquement comparé à deux approches naïves :
+à la section 4, en utilisant le package présenté au chapitre précédent. Cet
+algorithme est systématiquement comparé à deux approches naïves :
* la moyenne des lendemains des jours "similaires" dans tout le passé, c'est-à-dire
prédiction = moyenne de tous les mardis passés si le jour courant est un lundi.
-----r
library(talweg)
-P = ${P} #instant de prévision
-H = ${H} #horizon (en heures)
+P = ${P} #première heure de prévision
+H = ${H} #dernière heure de prévision
ts_data = read.csv(system.file("extdata","pm10_mesures_H_loc_report.csv",
package="talweg"))
package="talweg"))
# NOTE: 'GMT' because DST gaps are filled and multiple values merged in
# above dataset. Prediction from P+1 to P+H included.
-data = getData(ts_data, exo_data, input_tz = "GMT", working_tz="GMT",
- predict_at=P)
+data = getData(ts_data, exo_data)
indices_ch = seq(as.Date("2015-01-18"),as.Date("2015-01-24"),"days")
indices_ep = seq(as.Date("2015-03-15"),as.Date("2015-03-21"),"days")
##<h2 style="color:blue;font-size:2em">${list_titles[i]}</h2>
${"##"} ${list_titles[i]}
-----r
-p1 = computeForecast(data, ${list_indices[i]}, "Neighbors", "Neighbors", horizon=H,
- simtype="mix", local=FALSE)
-p2 = computeForecast(data, ${list_indices[i]}, "Neighbors", "Neighbors", horizon=H,
- simtype="endo", local=TRUE)
-p3 = computeForecast(data, ${list_indices[i]}, "Neighbors", "Zero", horizon=H,
- simtype="none", local=TRUE)
-p4 = computeForecast(data, ${list_indices[i]}, "Average", "Zero", horizon=H)
-p5 = computeForecast(data, ${list_indices[i]}, "Persistence", "Zero", horizon=H,
- same_day=${'TRUE' if loop.index < 2 else 'FALSE'})
+p1 = computeForecast(data, ${list_indices[i]}, "Neighbors", "Neighbors", predict_from=P,
+ horizon=H, simtype="mix", local=FALSE)
+p2 = computeForecast(data, ${list_indices[i]}, "Neighbors", "Neighbors", predict_from=P,
+ horizon=H, simtype="endo", local=TRUE)
+p3 = computeForecast(data, ${list_indices[i]}, "Neighbors", "Zero", predict_from=P,
+ horizon=H, simtype="none", local=TRUE)
+p4 = computeForecast(data, ${list_indices[i]}, "Average", "Zero", predict_from=P,
+ horizon=H)
+p5 = computeForecast(data, ${list_indices[i]}, "Persistence", "Zero", predict_from=P,
+ horizon=H, same_day=${'TRUE' if loop.index < 2 else 'FALSE'})
-----r
-e1 = computeError(data, p1, H)
-e2 = computeError(data, p2, H)
-e3 = computeError(data, p3, H)
-e4 = computeError(data, p4, H)
-e5 = computeError(data, p5, H)
+e1 = computeError(data, p1, P, H)
+e2 = computeError(data, p2, P, H)
+e3 = computeError(data, p3, P, H)
+e4 = computeError(data, p4, P, H)
+e5 = computeError(data, p5, P, H)
options(repr.plot.width=9, repr.plot.height=7)
plotError(list(e1, e5, e4, e2, e3), cols=c(1,2,colors()[258],4,6))
% endif
-----r
par(mfrow=c(1,2))
-f_np1 = computeFilaments(data, p1, i_np, plot=TRUE)
+f_np1 = computeFilaments(data, p1, i_np, predict_from=P, plot=TRUE)
title(paste("Filaments p1 day",i_np))
-f_p1 = computeFilaments(data, p1, i_p, plot=TRUE)
+f_p1 = computeFilaments(data, p1, i_p, predict_from=P, plot=TRUE)
title(paste("Filaments p1 day",i_p))
-f_np2 = computeFilaments(data, p2, i_np, plot=TRUE)
+f_np2 = computeFilaments(data, p2, i_np, predict_from=P, plot=TRUE)
title(paste("Filaments p2 day",i_np))
-f_p2 = computeFilaments(data, p2, i_p, plot=TRUE)
+f_p2 = computeFilaments(data, p2, i_p, predict_from=P, plot=TRUE)
title(paste("Filaments p2 day",i_p))
-----
% if i == 0:
% endif
-----r
par(mfrow=c(1,2))
-plotFilamentsBox(data, f_np1); title(paste("FilBox p1 day",i_np))
-plotFilamentsBox(data, f_p1); title(paste("FilBox p1 day",i_p))
+plotFilamentsBox(data, f_np1, predict_from=P); title(paste("FilBox p1 day",i_np))
+plotFilamentsBox(data, f_p1, predict_from=P); title(paste("FilBox p1 day",i_p))
# En pointillés la courbe du jour courant + lendemain (à prédire)
-----
% endif
-----r
par(mfrow=c(1,2))
-plotRelVar(data, f_np1); title(paste("StdDev p1 day",i_np))
-plotRelVar(data, f_p1); title(paste("StdDev p1 day",i_p))
+plotRelVar(data, f_np1, predict_from=P); title(paste("StdDev p1 day",i_np))
+plotRelVar(data, f_p1, predict_from=P); title(paste("StdDev p1 day",i_p))
-plotRelVar(data, f_np2); title(paste("StdDev p2 day",i_np))
-plotRelVar(data, f_p2); title(paste("StdDev p2 day",i_p))
+plotRelVar(data, f_np2, predict_from=P); title(paste("StdDev p2 day",i_np))
+plotRelVar(data, f_p2, preidct_from=P); title(paste("StdDev p2 day",i_p))
# Variabilité globale en rouge ; sur les voisins (+ lendemains) en noir
-----