4 "cell_type": "markdown",
12 "<h2>Introduction</h2>\n",
14 "J'ai fait quelques essais dans différentes configurations pour la méthode \"Neighbors\"\n",
15 "(la seule dont on a parlé) et sa variante récente appelée pour l'instant \"Neighbors2\",\n",
16 "avec simtype=\"mix\" : deux types de similarités prises en compte, puis multiplication des poids.\n",
17 "Pour Neighbors on prédit le saut (par la moyenne pondérée des sauts passés), et pour Neighbors2\n",
18 "on n'effectue aucun raccordement (prévision directe).\n",
20 "J'ai systématiquement comparé à une approche naïve : la moyenne des lendemains des jours\n",
21 "\"similaires\" dans tout le passé, ainsi qu'à la persistence -- reproduisant le jour courant ou\n",
22 "allant chercher le futur similaire une semaine avant.\n",
24 "Ensuite j'affiche les erreurs, quelques courbes prévues/mesurées, quelques filaments puis les\n",
25 "histogrammes de quelques poids. Concernant les graphes de filaments, la moitié gauche du graphe\n",
26 "correspond aux jours similaires au jour courant, tandis que la moitié droite affiche les\n",
27 "lendemains : ce sont donc les voisinages tels qu'utilisés dans l'algorithme.\n",
33 "execution_count": null,
43 "P = 7 #instant de prévision\n",
44 "H = 17 #horizon (en heures)\n",
46 "ts_data = read.csv(system.file(\"extdata\",\"pm10_mesures_H_loc_report.csv\",package=\"talweg\"))\n",
47 "exo_data = read.csv(system.file(\"extdata\",\"meteo_extra_noNAs.csv\",package=\"talweg\"))\n",
48 "# NOTE: 'GMT' because DST gaps are filled and multiple values merged in above dataset.\n",
49 "# Prediction from P+1 to P+H included.\n",
50 "data = getData(ts_data, exo_data, input_tz = \"GMT\", working_tz=\"GMT\", predict_at=P)\n",
52 "indices_ch = seq(as.Date(\"2015-01-18\"),as.Date(\"2015-01-24\"),\"days\")\n",
53 "indices_ep = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n",
54 "indices_np = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")\n"
58 "cell_type": "markdown",
66 "<h2 style=\"color:blue;font-size:2em\">Pollution par chauffage</h2>"
71 "execution_count": null,
79 "reload(\"../pkg\")\n",
80 "p_nn = computeForecast(data, indices_ch, \"Neighbors\", \"Neighbors\", horizon=H)\n",
81 "p_nn2 = computeForecast(data, indices_ch, \"Neighbors2\", \"Neighbors\", horizon=H)\n",
82 "p_az = computeForecast(data, indices_ch, \"Average\", \"Zero\", horizon=H)\n",
83 "p_pz = computeForecast(data, indices_ch, \"Persistence\", \"Zero\", horizon=H, same_day=TRUE)"
88 "execution_count": null,
94 "p_nn2$getParams(5)$weights"
99 "execution_count": null,
107 "e_nn = computeError(data, p_nn, H)\n",
108 "e_nn2 = computeError(data, p_nn2, H)\n",
109 "e_az = computeError(data, p_az, H)\n",
110 "e_pz = computeError(data, p_pz, H)\n",
111 "options(repr.plot.width=9, repr.plot.height=7)\n",
112 "plotError(list(e_nn, e_pz, e_az, e_nn2), cols=c(1,2,colors()[258], 4))\n",
114 "# Noir: Neighbors, bleu: Neighbors2, vert: moyenne, rouge: persistence\n",
116 "i_np = which.min(e_nn$abs$indices)\n",
117 "i_p = which.max(e_nn$abs$indices)"
122 "execution_count": null,
130 "options(repr.plot.width=9, repr.plot.height=4)\n",
131 "par(mfrow=c(1,2))\n",
133 "plotPredReal(data, p_nn, i_np); title(paste(\"PredReal nn day\",i_np))\n",
134 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn day\",i_p))\n",
136 "plotPredReal(data, p_nn2, i_np); title(paste(\"PredReal nn2 day\",i_np))\n",
137 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn2 day\",i_p))\n",
139 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
140 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
142 "# Bleu: prévue, noir: réalisée"
147 "execution_count": null,
155 "par(mfrow=c(1,2))\n",
156 "f_np = computeFilaments(data, p_nn, i_np, plot=TRUE); title(paste(\"Filaments nn day\",i_np))\n",
157 "f_p = computeFilaments(data, p_nn, i_p, plot=TRUE); title(paste(\"Filaments nn day\",i_p))\n",
159 "f_np2 = computeFilaments(data, p_nn2, i_np, plot=TRUE); title(paste(\"Filaments nn2 day\",i_np))\n",
160 "f_p2 = computeFilaments(data, p_nn2, i_p, plot=TRUE); title(paste(\"Filaments nn2 day\",i_p))"
165 "execution_count": null,
173 "par(mfrow=c(1,2))\n",
174 "plotFilamentsBox(data, f_np); title(paste(\"FilBox nn day\",i_np))\n",
175 "plotFilamentsBox(data, f_p); title(paste(\"FilBox nn day\",i_p))\n",
177 "plotFilamentsBox(data, f_np2); title(paste(\"FilBox nn2 day\",i_np))\n",
178 "plotFilamentsBox(data, f_p2); title(paste(\"FilBox nn2 day\",i_p))"
183 "execution_count": null,
191 "par(mfrow=c(1,2))\n",
192 "plotRelVar(data, f_np); title(paste(\"StdDev nn day\",i_np))\n",
193 "plotRelVar(data, f_p); title(paste(\"StdDev nn day\",i_p))\n",
195 "plotRelVar(data, f_np2); title(paste(\"StdDev nn2 day\",i_np))\n",
196 "plotRelVar(data, f_p2); title(paste(\"StdDev nn2 day\",i_p))\n",
198 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
203 "execution_count": null,
211 "par(mfrow=c(1,2))\n",
212 "plotSimils(p_nn, i_np); title(paste(\"Weights nn day\",i_np))\n",
213 "plotSimils(p_nn, i_p); title(paste(\"Weights nn day\",i_p))\n",
215 "plotSimils(p_nn2, i_np); title(paste(\"Weights nn2 day\",i_np))\n",
216 "plotSimils(p_nn2, i_p); title(paste(\"Weights nn2 day\",i_p))\n",
218 "# - pollué à gauche, + pollué à droite"
223 "execution_count": null,
231 "# Fenêtres sélectionnées dans ]0,7] / nn à gauche, nn2 à droite\n",
232 "p_nn$getParams(i_np)$window\n",
233 "p_nn$getParams(i_p)$window\n",
235 "p_nn2$getParams(i_np)$window\n",
236 "p_nn2$getParams(i_p)$window"
240 "cell_type": "markdown",
248 "<h2 style=\"color:blue;font-size:2em\">Pollution par épandage</h2>"
253 "execution_count": null,
261 "p_nn = computeForecast(data, indices_ep, \"Neighbors\", \"Neighbors\", horizon=H)\n",
262 "p_nn2 = computeForecast(data, indices_ep, \"Neighbors2\", \"Zero\", horizon=H)\n",
263 "p_az = computeForecast(data, indices_ep, \"Average\", \"Zero\", horizon=H)\n",
264 "p_pz = computeForecast(data, indices_ep, \"Persistence\", \"Zero\", horizon=H, same_day=TRUE)"
269 "execution_count": null,
277 "e_nn = computeError(data, p_nn, H)\n",
278 "e_nn2 = computeError(data, p_nn2, H)\n",
279 "e_az = computeError(data, p_az, H)\n",
280 "e_pz = computeError(data, p_pz, H)\n",
281 "options(repr.plot.width=9, repr.plot.height=7)\n",
282 "plotError(list(e_nn, e_pz, e_az, e_nn2), cols=c(1,2,colors()[258], 4))\n",
284 "# Noir: Neighbors, bleu: Neighbors2, vert: moyenne, rouge: persistence\n",
286 "i_np = which.min(e_nn$abs$indices)\n",
287 "i_p = which.max(e_nn$abs$indices)"
292 "execution_count": null,
300 "options(repr.plot.width=9, repr.plot.height=4)\n",
301 "par(mfrow=c(1,2))\n",
303 "plotPredReal(data, p_nn, i_np); title(paste(\"PredReal nn day\",i_np))\n",
304 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn day\",i_p))\n",
306 "plotPredReal(data, p_nn2, i_np); title(paste(\"PredReal nn2 day\",i_np))\n",
307 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn2 day\",i_p))\n",
309 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
310 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
312 "# Bleu: prévue, noir: réalisée"
317 "execution_count": null,
325 "par(mfrow=c(1,2))\n",
326 "f_np = computeFilaments(data, p_nn, i_np, plot=TRUE); title(paste(\"Filaments nn day\",i_np))\n",
327 "f_p = computeFilaments(data, p_nn, i_p, plot=TRUE); title(paste(\"Filaments nn day\",i_p))\n",
329 "f_np2 = computeFilaments(data, p_nn2, i_np, plot=TRUE); title(paste(\"Filaments nn2 day\",i_np))\n",
330 "f_p2 = computeFilaments(data, p_nn2, i_p, plot=TRUE); title(paste(\"Filaments nn2 day\",i_p))"
335 "execution_count": null,
343 "par(mfrow=c(1,2))\n",
344 "plotFilamentsBox(data, f_np); title(paste(\"FilBox nn day\",i_np))\n",
345 "plotFilamentsBox(data, f_p); title(paste(\"FilBox nn day\",i_p))\n",
347 "plotFilamentsBox(data, f_np2); title(paste(\"FilBox nn2 day\",i_np))\n",
348 "plotFilamentsBox(data, f_p2); title(paste(\"FilBox nn2 day\",i_p))"
353 "execution_count": null,
361 "par(mfrow=c(1,2))\n",
362 "plotRelVar(data, f_np); title(paste(\"StdDev nn day\",i_np))\n",
363 "plotRelVar(data, f_p); title(paste(\"StdDev nn day\",i_p))\n",
365 "plotRelVar(data, f_np2); title(paste(\"StdDev nn2 day\",i_np))\n",
366 "plotRelVar(data, f_p2); title(paste(\"StdDev nn2 day\",i_p))\n",
368 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
373 "execution_count": null,
381 "par(mfrow=c(1,2))\n",
382 "plotSimils(p_nn, i_np); title(paste(\"Weights nn day\",i_np))\n",
383 "plotSimils(p_nn, i_p); title(paste(\"Weights nn day\",i_p))\n",
385 "plotSimils(p_nn2, i_np); title(paste(\"Weights nn2 day\",i_np))\n",
386 "plotSimils(p_nn2, i_p); title(paste(\"Weights nn2 day\",i_p))\n",
388 "# - pollué à gauche, + pollué à droite"
393 "execution_count": null,
401 "# Fenêtres sélectionnées dans ]0,7] / nn à gauche, nn2 à droite\n",
402 "p_nn$getParams(i_np)$window\n",
403 "p_nn$getParams(i_p)$window\n",
405 "p_nn2$getParams(i_np)$window\n",
406 "p_nn2$getParams(i_p)$window"
410 "cell_type": "markdown",
418 "<h2 style=\"color:blue;font-size:2em\">Semaine non polluée</h2>"
423 "execution_count": null,
431 "p_nn = computeForecast(data, indices_np, \"Neighbors\", \"Neighbors\", horizon=H)\n",
432 "p_nn2 = computeForecast(data, indices_np, \"Neighbors2\", \"Zero\", horizon=H)\n",
433 "p_az = computeForecast(data, indices_np, \"Average\", \"Zero\", horizon=H)\n",
434 "p_pz = computeForecast(data, indices_np, \"Persistence\", \"Zero\", horizon=H, same_day=FALSE)"
439 "execution_count": null,
447 "e_nn = computeError(data, p_nn, H)\n",
448 "e_nn2 = computeError(data, p_nn2, H)\n",
449 "e_az = computeError(data, p_az, H)\n",
450 "e_pz = computeError(data, p_pz, H)\n",
451 "options(repr.plot.width=9, repr.plot.height=7)\n",
452 "plotError(list(e_nn, e_pz, e_az, e_nn2), cols=c(1,2,colors()[258], 4))\n",
454 "# Noir: Neighbors, bleu: Neighbors2, vert: moyenne, rouge: persistence\n",
456 "i_np = which.min(e_nn$abs$indices)\n",
457 "i_p = which.max(e_nn$abs$indices)"
462 "execution_count": null,
470 "options(repr.plot.width=9, repr.plot.height=4)\n",
471 "par(mfrow=c(1,2))\n",
473 "plotPredReal(data, p_nn, i_np); title(paste(\"PredReal nn day\",i_np))\n",
474 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn day\",i_p))\n",
476 "plotPredReal(data, p_nn2, i_np); title(paste(\"PredReal nn2 day\",i_np))\n",
477 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn2 day\",i_p))\n",
479 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
480 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
482 "# Bleu: prévue, noir: réalisée"
487 "execution_count": null,
495 "par(mfrow=c(1,2))\n",
496 "f_np = computeFilaments(data, p_nn, i_np, plot=TRUE); title(paste(\"Filaments nn day\",i_np))\n",
497 "f_p = computeFilaments(data, p_nn, i_p, plot=TRUE); title(paste(\"Filaments nn day\",i_p))\n",
499 "f_np2 = computeFilaments(data, p_nn2, i_np, plot=TRUE); title(paste(\"Filaments nn2 day\",i_np))\n",
500 "f_p2 = computeFilaments(data, p_nn2, i_p, plot=TRUE); title(paste(\"Filaments nn2 day\",i_p))"
505 "execution_count": null,
513 "par(mfrow=c(1,2))\n",
514 "plotFilamentsBox(data, f_np); title(paste(\"FilBox nn day\",i_np))\n",
515 "plotFilamentsBox(data, f_p); title(paste(\"FilBox nn day\",i_p))\n",
517 "plotFilamentsBox(data, f_np2); title(paste(\"FilBox nn2 day\",i_np))\n",
518 "plotFilamentsBox(data, f_p2); title(paste(\"FilBox nn2 day\",i_p))"
523 "execution_count": null,
531 "par(mfrow=c(1,2))\n",
532 "plotRelVar(data, f_np); title(paste(\"StdDev nn day\",i_np))\n",
533 "plotRelVar(data, f_p); title(paste(\"StdDev nn day\",i_p))\n",
535 "plotRelVar(data, f_np2); title(paste(\"StdDev nn2 day\",i_np))\n",
536 "plotRelVar(data, f_p2); title(paste(\"StdDev nn2 day\",i_p))\n",
538 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
543 "execution_count": null,
551 "par(mfrow=c(1,2))\n",
552 "plotSimils(p_nn, i_np); title(paste(\"Weights nn day\",i_np))\n",
553 "plotSimils(p_nn, i_p); title(paste(\"Weights nn day\",i_p))\n",
555 "plotSimils(p_nn2, i_np); title(paste(\"Weights nn2 day\",i_np))\n",
556 "plotSimils(p_nn2, i_p); title(paste(\"Weights nn2 day\",i_p))\n",
558 "# - pollué à gauche, + pollué à droite"
563 "execution_count": null,
571 "# Fenêtres sélectionnées dans ]0,7] / nn à gauche, nn2 à droite\n",
572 "p_nn$getParams(i_np)$window\n",
573 "p_nn$getParams(i_p)$window\n",
575 "p_nn2$getParams(i_np)$window\n",
576 "p_nn2$getParams(i_p)$window"
587 "codemirror_mode": "r",
588 "file_extension": ".r",
589 "mimetype": "text/x-r-source",
591 "pygments_lexer": "r",