first tests for Neighbors2 after debug; TODO: some missing forecasts
[talweg.git] / reports / report.gj
index a9f10d0..aee6ad4 100644 (file)
@@ -1,11 +1,10 @@
 -----
-
-## Introduction
+<h2>Introduction</h2>
 
 J'ai fait quelques essais dans différentes configurations pour la méthode "Neighbors"
-(la seule dont on a parlé).<br>Il semble que le mieux soit
+(la seule dont on a parlé) et sa variante récente appelée pour l'instant "Neighbors2".<br>
 
- * simtype="exo" ou "mix" : similarités exogènes avec/sans endogènes (fenêtre optimisée par VC)
+ * simtype="exo", "endo" ou "mix" : type de similarités (fenêtre optimisée par VC)
  * same_season=FALSE : les indices pour la validation croisée ne tiennent pas compte des saisons
  * mix_strategy="mult" : on multiplie les poids (au lieu d'en éteindre)
 
@@ -22,44 +21,45 @@ lendemains : ce sont donc les voisinages tels qu'utilisés dans l'algorithme.
 list_titles = ['Pollution par chauffage', 'Pollution par épandage', 'Semaine non polluée']
 list_indices = ['indices_ch', 'indices_ep', 'indices_np']
 %>
-
 -----r
-
 library(talweg)
 
+P = ${P} #instant de prévision
+H = ${H} #horizon (en heures)
+
 ts_data = read.csv(system.file("extdata","pm10_mesures_H_loc_report.csv",package="talweg"))
 exo_data = read.csv(system.file("extdata","meteo_extra_noNAs.csv",package="talweg"))
-data = getData(ts_data, exo_data, input_tz = "Europe/Paris", working_tz="Europe/Paris", predict_at=13)
+data = getData(ts_data, exo_data, input_tz = "Europe/Paris", working_tz="Europe/Paris",
+       predict_at=P) #predict from P+1 to P+H included
 
 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")
 indices_np = seq(as.Date("2015-04-26"),as.Date("2015-05-02"),"days")
 
-% for loop in range(3):
-
+% for i in range(3):
 -----
-
-<h2 style="color:blue;font-size:2em">${list_titles[loop]}</h2>
-
+<h2 style="color:blue;font-size:2em">${list_titles[i]}</h2>
 -----r
-p_nn_exo = computeForecast(data, ${list_indices[loop]}, "Neighbors", "Neighbors", simtype="exo", horizon=H)
-p_nn_mix = computeForecast(data, ${list_indices[loop]}, "Neighbors", "Neighbors", simtype="mix", horizon=H)
-p_az = computeForecast(data, ${list_indices[loop]}, "Average", "Zero", horizon=H) #, memory=183)
-p_pz = computeForecast(data, ${list_indices[loop]}, "Persistence", "Zero", horizon=H, same_day=TRUE)
-
+p_nn_exo = computeForecast(data, ${list_indices[i]}, "Neighbors", "Neighbors",
+       horizon=H, simtype="exo")
+p_nn_mix = computeForecast(data, ${list_indices[i]}, "Neighbors", "Neighbors",
+       horizon=H, simtype="mix")
+p_az = computeForecast(data, ${list_indices[i]}, "Average", "Zero",
+       horizon=H)
+p_pz = computeForecast(data, ${list_indices[i]}, "Persistence", "Zero",
+       horizon=${H}, same_day=${'TRUE' if loop.index < 2 else 'FALSE'})
 -----r
-e_nn_exo = computeError(data, p_nn_exo)
-e_nn_mix = computeError(data, p_nn_mix)
-e_az = computeError(data, p_az)
-e_pz = computeError(data, p_pz)
+e_nn_exo = computeError(data, p_nn_exo, H)
+e_nn_mix = computeError(data, p_nn_mix, H)
+e_az = computeError(data, p_az, H)
+e_pz = computeError(data, p_pz, H)
 options(repr.plot.width=9, repr.plot.height=7)
 plotError(list(e_nn_mix, e_pz, e_az, e_nn_exo), cols=c(1,2,colors()[258], 4))
 
-#Noir: neighbors_mix, bleu: neighbors_exo, vert: moyenne, rouge: persistence
+# Noir: neighbors_mix, bleu: neighbors_exo, vert: moyenne, rouge: persistence
 
 i_np = which.min(e_nn_exo$abs$indices)
 i_p = which.max(e_nn_exo$abs$indices)
-
 -----r
 options(repr.plot.width=9, repr.plot.height=4)
 par(mfrow=c(1,2))
@@ -73,8 +73,7 @@ plotPredReal(data, p_nn_mix, i_p); title(paste("PredReal nn mix day",i_p))
 plotPredReal(data, p_az, i_np); title(paste("PredReal az day",i_np))
 plotPredReal(data, p_az, i_p); title(paste("PredReal az day",i_p))
 
-#Bleu: prévue, noir: réalisée
-
+# Bleu: prévue, noir: réalisée
 -----r
 par(mfrow=c(1,2))
 f_np_exo = computeFilaments(data, p_nn_exo, i_np, plot=TRUE); title(paste("Filaments nn exo day",i_np))
@@ -82,7 +81,6 @@ f_p_exo = computeFilaments(data, p_nn_exo, i_p, plot=TRUE); title(paste("Filamen
 
 f_np_mix = computeFilaments(data, p_nn_mix, i_np, plot=TRUE); title(paste("Filaments nn mix day",i_np))
 f_p_mix = computeFilaments(data, p_nn_mix, i_p, plot=TRUE); title(paste("Filaments nn mix day",i_p))
-
 -----r
 par(mfrow=c(1,2))
 plotFilamentsBox(data, f_np_exo); title(paste("FilBox nn exo day",i_np))
@@ -90,7 +88,6 @@ plotFilamentsBox(data, f_p_exo); title(paste("FilBox nn exo day",i_p))
 
 plotFilamentsBox(data, f_np_mix); title(paste("FilBox nn mix day",i_np))
 plotFilamentsBox(data, f_p_mix); title(paste("FilBox nn mix day",i_p))
-
 -----r
 par(mfrow=c(1,2))
 plotRelVar(data, f_np_exo); title(paste("StdDev nn exo day",i_np))
@@ -99,30 +96,26 @@ plotRelVar(data, f_p_exo); title(paste("StdDev nn exo day",i_p))
 plotRelVar(data, f_np_mix); title(paste("StdDev nn mix day",i_np))
 plotRelVar(data, f_p_mix); title(paste("StdDev nn mix day",i_p))
 
-#Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir
-
+# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir
 -----r
 par(mfrow=c(1,2))
 plotSimils(p_nn_exo, i_np); title(paste("Weights nn exo day",i_np))
 plotSimils(p_nn_exo, i_p); title(paste("Weights nn exo day",i_p))
 
 plotSimils(p_nn_mix, i_np); title(paste("Weights nn mix day",i_np))
-plotSimils(p_nn_mix, i_p); title(paste("Weights nn mix day",i_p)
-
-#- pollué à gauche, + pollué à droite
+plotSimils(p_nn_mix, i_p); title(paste("Weights nn mix day",i_p))
 
+# - pollué à gauche, + pollué à droite
 -----r
-#Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite
+# Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite
 p_nn_exo$getParams(i_np)$window
 p_nn_exo$getParams(i_p)$window
 
 p_nn_mix$getParams(i_np)$window
 p_nn_mix$getParams(i_p)$window
-
 % endfor
-
 -----
-## Bilan
+<h2>Bilan</h2>
 
 Problème difficile : on ne fait guère mieux qu'une naïve moyenne des lendemains des jours
 similaires dans le passé, ce qui n'est pas loin de prédire une série constante égale à la