remove logging
[talweg.git] / reports / report.ipynb
CommitLineData
ff5df8e3
BA
1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "\n",
8 "\n",
9 "<h2>Introduction</h2>\n",
10 "\n",
11 "J'ai fait quelques essais dans différentes configurations pour la méthode \"Neighbors\"\n",
12 "(la seule dont on a parlé).<br>Il semble que le mieux soit\n",
13 "\n",
14 " * simtype=\"exo\" ou \"mix\" : similarités exogènes avec/sans endogènes (fenêtre optimisée par VC)\n",
15 " * same_season=FALSE : les indices pour la validation croisée ne tiennent pas compte des saisons\n",
16 " * mix_strategy=\"mult\" : on multiplie les poids (au lieu d'en éteindre)\n",
17 "\n",
18 "J'ai systématiquement comparé à une approche naïve : la moyennes des lendemains des jours\n",
19 "\"similaires\" dans tout le passé ; à chaque fois sans prédiction du saut (sauf pour Neighbors :\n",
20 "prédiction basée sur les poids calculés).\n",
21 "\n",
22 "Ensuite j'affiche les erreurs, quelques courbes prévues/mesurées, quelques filaments puis les\n",
23 "histogrammes de quelques poids. Concernant les graphes de filaments, la moitié gauche du graphe\n",
24 "correspond aux jours similaires au jour courant, tandis que la moitié droite affiche les\n",
25 "lendemains : ce sont donc les voisinages tels qu'utilisés dans l'algorithme.\n",
26 "\n"
27 ]
28 },
29 {
30 "cell_type": "code",
31 "execution_count": null,
32 "metadata": {
33 "collapsed": false
34 },
35 "outputs": [],
36 "source": [
37 "library(talweg)\n",
38 "\n",
39 "ts_data = read.csv(system.file(\"extdata\",\"pm10_mesures_H_loc_report.csv\",package=\"talweg\"))\n",
40 "exo_data = read.csv(system.file(\"extdata\",\"meteo_extra_noNAs.csv\",package=\"talweg\"))\n",
41 "data = getData(ts_data, exo_data, input_tz = \"Europe/Paris\", working_tz=\"Europe/Paris\", predict_at=13)\n",
42 "\n",
43 "indices_ch = seq(as.Date(\"2015-01-18\"),as.Date(\"2015-01-24\"),\"days\")\n",
44 "indices_ep = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n",
45 "indices_np = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")"
46 ]
47 },
48 {
49 "cell_type": "markdown",
50 "metadata": {},
51 "source": [
52 "\n",
53 "\n",
54 "<h2 style=\"color:blue;font-size:2em\">Pollution par chauffage</h2>"
55 ]
56 },
57 {
58 "cell_type": "code",
59 "execution_count": null,
60 "metadata": {
61 "collapsed": false
62 },
63 "outputs": [],
64 "source": [
65 "p_nn_exo = computeForecast(data, indices_ch, \"Neighbors\", \"Neighbors\", simtype=\"exo\", horizon=H)\n",
66 "p_nn_mix = computeForecast(data, indices_ch, \"Neighbors\", \"Neighbors\", simtype=\"mix\", horizon=H)\n",
67 "p_az = computeForecast(data, indices_ch, \"Average\", \"Zero\", horizon=H) #, memory=183)\n",
68 "p_pz = computeForecast(data, indices_ch, \"Persistence\", \"Zero\", horizon=H, same_day=TRUE)"
69 ]
70 },
71 {
72 "cell_type": "code",
73 "execution_count": null,
74 "metadata": {
75 "collapsed": false
76 },
77 "outputs": [],
78 "source": [
79 "e_nn_exo = computeError(data, p_nn_exo)\n",
80 "e_nn_mix = computeError(data, p_nn_mix)\n",
81 "e_az = computeError(data, p_az)\n",
82 "e_pz = computeError(data, p_pz)\n",
83 "options(repr.plot.width=9, repr.plot.height=7)\n",
84 "plotError(list(e_nn_mix, e_pz, e_az, e_nn_exo), cols=c(1,2,colors()[258], 4))\n",
85 "\n",
86 "# Noir: neighbors_mix, bleu: neighbors_exo, vert: moyenne, rouge: persistence\n",
87 "\n",
88 "i_np = which.min(e_nn_exo$abs$indices)\n",
89 "i_p = which.max(e_nn_exo$abs$indices)"
90 ]
91 },
92 {
93 "cell_type": "code",
94 "execution_count": null,
95 "metadata": {
96 "collapsed": false
97 },
98 "outputs": [],
99 "source": [
100 "options(repr.plot.width=9, repr.plot.height=4)\n",
101 "par(mfrow=c(1,2))\n",
102 "\n",
103 "plotPredReal(data, p_nn_exo, i_np); title(paste(\"PredReal nn exo day\",i_np))\n",
104 "plotPredReal(data, p_nn_exo, i_p); title(paste(\"PredReal nn exo day\",i_p))\n",
105 "\n",
106 "plotPredReal(data, p_nn_mix, i_np); title(paste(\"PredReal nn mix day\",i_np))\n",
107 "plotPredReal(data, p_nn_mix, i_p); title(paste(\"PredReal nn mix day\",i_p))\n",
108 "\n",
109 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
110 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
111 "\n",
112 "# Bleu: prévue, noir: réalisée"
113 ]
114 },
115 {
116 "cell_type": "code",
117 "execution_count": null,
118 "metadata": {
119 "collapsed": false
120 },
121 "outputs": [],
122 "source": [
123 "par(mfrow=c(1,2))\n",
124 "f_np_exo = computeFilaments(data, p_nn_exo, i_np, plot=TRUE); title(paste(\"Filaments nn exo day\",i_np))\n",
125 "f_p_exo = computeFilaments(data, p_nn_exo, i_p, plot=TRUE); title(paste(\"Filaments nn exo day\",i_p))\n",
126 "\n",
127 "f_np_mix = computeFilaments(data, p_nn_mix, i_np, plot=TRUE); title(paste(\"Filaments nn mix day\",i_np))\n",
128 "f_p_mix = computeFilaments(data, p_nn_mix, i_p, plot=TRUE); title(paste(\"Filaments nn mix day\",i_p))"
129 ]
130 },
131 {
132 "cell_type": "code",
133 "execution_count": null,
134 "metadata": {
135 "collapsed": false
136 },
137 "outputs": [],
138 "source": [
139 "par(mfrow=c(1,2))\n",
140 "plotFilamentsBox(data, f_np_exo); title(paste(\"FilBox nn exo day\",i_np))\n",
141 "plotFilamentsBox(data, f_p_exo); title(paste(\"FilBox nn exo day\",i_p))\n",
142 "\n",
143 "plotFilamentsBox(data, f_np_mix); title(paste(\"FilBox nn mix day\",i_np))\n",
144 "plotFilamentsBox(data, f_p_mix); title(paste(\"FilBox nn mix day\",i_p))"
145 ]
146 },
147 {
148 "cell_type": "code",
149 "execution_count": null,
150 "metadata": {
151 "collapsed": false
152 },
153 "outputs": [],
154 "source": [
155 "par(mfrow=c(1,2))\n",
156 "plotRelVar(data, f_np_exo); title(paste(\"StdDev nn exo day\",i_np))\n",
157 "plotRelVar(data, f_p_exo); title(paste(\"StdDev nn exo day\",i_p))\n",
158 "\n",
159 "plotRelVar(data, f_np_mix); title(paste(\"StdDev nn mix day\",i_np))\n",
160 "plotRelVar(data, f_p_mix); title(paste(\"StdDev nn mix day\",i_p))\n",
161 "\n",
162 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
163 ]
164 },
165 {
166 "cell_type": "code",
167 "execution_count": null,
168 "metadata": {
169 "collapsed": false
170 },
171 "outputs": [],
172 "source": [
173 "par(mfrow=c(1,2))\n",
174 "plotSimils(p_nn_exo, i_np); title(paste(\"Weights nn exo day\",i_np))\n",
175 "plotSimils(p_nn_exo, i_p); title(paste(\"Weights nn exo day\",i_p))\n",
176 "\n",
177 "plotSimils(p_nn_mix, i_np); title(paste(\"Weights nn mix day\",i_np))\n",
178 "plotSimils(p_nn_mix, i_p); title(paste(\"Weights nn mix day\",i_p)\n",
179 "\n",
180 "# - pollué à gauche, + pollué à droite"
181 ]
182 },
183 {
184 "cell_type": "code",
185 "execution_count": null,
186 "metadata": {
187 "collapsed": false
188 },
189 "outputs": [],
190 "source": [
191 "# Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n",
192 "p_nn_exo$getParams(i_np)$window\n",
193 "p_nn_exo$getParams(i_p)$window\n",
194 "\n",
195 "p_nn_mix$getParams(i_np)$window\n",
196 "p_nn_mix$getParams(i_p)$window"
197 ]
198 },
199 {
200 "cell_type": "markdown",
201 "metadata": {},
202 "source": [
203 "\n",
204 "\n",
205 "<h2 style=\"color:blue;font-size:2em\">Pollution par épandage</h2>"
206 ]
207 },
208 {
209 "cell_type": "code",
210 "execution_count": null,
211 "metadata": {
212 "collapsed": false
213 },
214 "outputs": [],
215 "source": [
216 "p_nn_exo = computeForecast(data, indices_ep, \"Neighbors\", \"Neighbors\", simtype=\"exo\", horizon=H)\n",
217 "p_nn_mix = computeForecast(data, indices_ep, \"Neighbors\", \"Neighbors\", simtype=\"mix\", horizon=H)\n",
218 "p_az = computeForecast(data, indices_ep, \"Average\", \"Zero\", horizon=H) #, memory=183)\n",
219 "p_pz = computeForecast(data, indices_ep, \"Persistence\", \"Zero\", horizon=H, same_day=TRUE)"
220 ]
221 },
222 {
223 "cell_type": "code",
224 "execution_count": null,
225 "metadata": {
226 "collapsed": false
227 },
228 "outputs": [],
229 "source": [
230 "e_nn_exo = computeError(data, p_nn_exo)\n",
231 "e_nn_mix = computeError(data, p_nn_mix)\n",
232 "e_az = computeError(data, p_az)\n",
233 "e_pz = computeError(data, p_pz)\n",
234 "options(repr.plot.width=9, repr.plot.height=7)\n",
235 "plotError(list(e_nn_mix, e_pz, e_az, e_nn_exo), cols=c(1,2,colors()[258], 4))\n",
236 "\n",
237 "# Noir: neighbors_mix, bleu: neighbors_exo, vert: moyenne, rouge: persistence\n",
238 "\n",
239 "i_np = which.min(e_nn_exo$abs$indices)\n",
240 "i_p = which.max(e_nn_exo$abs$indices)"
241 ]
242 },
243 {
244 "cell_type": "code",
245 "execution_count": null,
246 "metadata": {
247 "collapsed": false
248 },
249 "outputs": [],
250 "source": [
251 "options(repr.plot.width=9, repr.plot.height=4)\n",
252 "par(mfrow=c(1,2))\n",
253 "\n",
254 "plotPredReal(data, p_nn_exo, i_np); title(paste(\"PredReal nn exo day\",i_np))\n",
255 "plotPredReal(data, p_nn_exo, i_p); title(paste(\"PredReal nn exo day\",i_p))\n",
256 "\n",
257 "plotPredReal(data, p_nn_mix, i_np); title(paste(\"PredReal nn mix day\",i_np))\n",
258 "plotPredReal(data, p_nn_mix, i_p); title(paste(\"PredReal nn mix day\",i_p))\n",
259 "\n",
260 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
261 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
262 "\n",
263 "# Bleu: prévue, noir: réalisée"
264 ]
265 },
266 {
267 "cell_type": "code",
268 "execution_count": null,
269 "metadata": {
270 "collapsed": false
271 },
272 "outputs": [],
273 "source": [
274 "par(mfrow=c(1,2))\n",
275 "f_np_exo = computeFilaments(data, p_nn_exo, i_np, plot=TRUE); title(paste(\"Filaments nn exo day\",i_np))\n",
276 "f_p_exo = computeFilaments(data, p_nn_exo, i_p, plot=TRUE); title(paste(\"Filaments nn exo day\",i_p))\n",
277 "\n",
278 "f_np_mix = computeFilaments(data, p_nn_mix, i_np, plot=TRUE); title(paste(\"Filaments nn mix day\",i_np))\n",
279 "f_p_mix = computeFilaments(data, p_nn_mix, i_p, plot=TRUE); title(paste(\"Filaments nn mix day\",i_p))"
280 ]
281 },
282 {
283 "cell_type": "code",
284 "execution_count": null,
285 "metadata": {
286 "collapsed": false
287 },
288 "outputs": [],
289 "source": [
290 "par(mfrow=c(1,2))\n",
291 "plotFilamentsBox(data, f_np_exo); title(paste(\"FilBox nn exo day\",i_np))\n",
292 "plotFilamentsBox(data, f_p_exo); title(paste(\"FilBox nn exo day\",i_p))\n",
293 "\n",
294 "plotFilamentsBox(data, f_np_mix); title(paste(\"FilBox nn mix day\",i_np))\n",
295 "plotFilamentsBox(data, f_p_mix); title(paste(\"FilBox nn mix day\",i_p))"
296 ]
297 },
298 {
299 "cell_type": "code",
300 "execution_count": null,
301 "metadata": {
302 "collapsed": false
303 },
304 "outputs": [],
305 "source": [
306 "par(mfrow=c(1,2))\n",
307 "plotRelVar(data, f_np_exo); title(paste(\"StdDev nn exo day\",i_np))\n",
308 "plotRelVar(data, f_p_exo); title(paste(\"StdDev nn exo day\",i_p))\n",
309 "\n",
310 "plotRelVar(data, f_np_mix); title(paste(\"StdDev nn mix day\",i_np))\n",
311 "plotRelVar(data, f_p_mix); title(paste(\"StdDev nn mix day\",i_p))\n",
312 "\n",
313 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
314 ]
315 },
316 {
317 "cell_type": "code",
318 "execution_count": null,
319 "metadata": {
320 "collapsed": false
321 },
322 "outputs": [],
323 "source": [
324 "par(mfrow=c(1,2))\n",
325 "plotSimils(p_nn_exo, i_np); title(paste(\"Weights nn exo day\",i_np))\n",
326 "plotSimils(p_nn_exo, i_p); title(paste(\"Weights nn exo day\",i_p))\n",
327 "\n",
328 "plotSimils(p_nn_mix, i_np); title(paste(\"Weights nn mix day\",i_np))\n",
329 "plotSimils(p_nn_mix, i_p); title(paste(\"Weights nn mix day\",i_p)\n",
330 "\n",
331 "# - pollué à gauche, + pollué à droite"
332 ]
333 },
334 {
335 "cell_type": "code",
336 "execution_count": null,
337 "metadata": {
338 "collapsed": false
339 },
340 "outputs": [],
341 "source": [
342 "# Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n",
343 "p_nn_exo$getParams(i_np)$window\n",
344 "p_nn_exo$getParams(i_p)$window\n",
345 "\n",
346 "p_nn_mix$getParams(i_np)$window\n",
347 "p_nn_mix$getParams(i_p)$window"
348 ]
349 },
350 {
351 "cell_type": "markdown",
352 "metadata": {},
353 "source": [
354 "\n",
355 "\n",
356 "<h2 style=\"color:blue;font-size:2em\">Semaine non polluée</h2>"
357 ]
358 },
359 {
360 "cell_type": "code",
361 "execution_count": null,
362 "metadata": {
363 "collapsed": false
364 },
365 "outputs": [],
366 "source": [
367 "p_nn_exo = computeForecast(data, indices_np, \"Neighbors\", \"Neighbors\", simtype=\"exo\", horizon=H)\n",
368 "p_nn_mix = computeForecast(data, indices_np, \"Neighbors\", \"Neighbors\", simtype=\"mix\", horizon=H)\n",
369 "p_az = computeForecast(data, indices_np, \"Average\", \"Zero\", horizon=H) #, memory=183)\n",
370 "p_pz = computeForecast(data, indices_np, \"Persistence\", \"Zero\", horizon=H, same_day=TRUE)"
371 ]
372 },
373 {
374 "cell_type": "code",
375 "execution_count": null,
376 "metadata": {
377 "collapsed": false
378 },
379 "outputs": [],
380 "source": [
381 "e_nn_exo = computeError(data, p_nn_exo)\n",
382 "e_nn_mix = computeError(data, p_nn_mix)\n",
383 "e_az = computeError(data, p_az)\n",
384 "e_pz = computeError(data, p_pz)\n",
385 "options(repr.plot.width=9, repr.plot.height=7)\n",
386 "plotError(list(e_nn_mix, e_pz, e_az, e_nn_exo), cols=c(1,2,colors()[258], 4))\n",
387 "\n",
388 "# Noir: neighbors_mix, bleu: neighbors_exo, vert: moyenne, rouge: persistence\n",
389 "\n",
390 "i_np = which.min(e_nn_exo$abs$indices)\n",
391 "i_p = which.max(e_nn_exo$abs$indices)"
392 ]
393 },
394 {
395 "cell_type": "code",
396 "execution_count": null,
397 "metadata": {
398 "collapsed": false
399 },
400 "outputs": [],
401 "source": [
402 "options(repr.plot.width=9, repr.plot.height=4)\n",
403 "par(mfrow=c(1,2))\n",
404 "\n",
405 "plotPredReal(data, p_nn_exo, i_np); title(paste(\"PredReal nn exo day\",i_np))\n",
406 "plotPredReal(data, p_nn_exo, i_p); title(paste(\"PredReal nn exo day\",i_p))\n",
407 "\n",
408 "plotPredReal(data, p_nn_mix, i_np); title(paste(\"PredReal nn mix day\",i_np))\n",
409 "plotPredReal(data, p_nn_mix, i_p); title(paste(\"PredReal nn mix day\",i_p))\n",
410 "\n",
411 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
412 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
413 "\n",
414 "# Bleu: prévue, noir: réalisée"
415 ]
416 },
417 {
418 "cell_type": "code",
419 "execution_count": null,
420 "metadata": {
421 "collapsed": false
422 },
423 "outputs": [],
424 "source": [
425 "par(mfrow=c(1,2))\n",
426 "f_np_exo = computeFilaments(data, p_nn_exo, i_np, plot=TRUE); title(paste(\"Filaments nn exo day\",i_np))\n",
427 "f_p_exo = computeFilaments(data, p_nn_exo, i_p, plot=TRUE); title(paste(\"Filaments nn exo day\",i_p))\n",
428 "\n",
429 "f_np_mix = computeFilaments(data, p_nn_mix, i_np, plot=TRUE); title(paste(\"Filaments nn mix day\",i_np))\n",
430 "f_p_mix = computeFilaments(data, p_nn_mix, i_p, plot=TRUE); title(paste(\"Filaments nn mix day\",i_p))"
431 ]
432 },
433 {
434 "cell_type": "code",
435 "execution_count": null,
436 "metadata": {
437 "collapsed": false
438 },
439 "outputs": [],
440 "source": [
441 "par(mfrow=c(1,2))\n",
442 "plotFilamentsBox(data, f_np_exo); title(paste(\"FilBox nn exo day\",i_np))\n",
443 "plotFilamentsBox(data, f_p_exo); title(paste(\"FilBox nn exo day\",i_p))\n",
444 "\n",
445 "plotFilamentsBox(data, f_np_mix); title(paste(\"FilBox nn mix day\",i_np))\n",
446 "plotFilamentsBox(data, f_p_mix); title(paste(\"FilBox nn mix day\",i_p))"
447 ]
448 },
449 {
450 "cell_type": "code",
451 "execution_count": null,
452 "metadata": {
453 "collapsed": false
454 },
455 "outputs": [],
456 "source": [
457 "par(mfrow=c(1,2))\n",
458 "plotRelVar(data, f_np_exo); title(paste(\"StdDev nn exo day\",i_np))\n",
459 "plotRelVar(data, f_p_exo); title(paste(\"StdDev nn exo day\",i_p))\n",
460 "\n",
461 "plotRelVar(data, f_np_mix); title(paste(\"StdDev nn mix day\",i_np))\n",
462 "plotRelVar(data, f_p_mix); title(paste(\"StdDev nn mix day\",i_p))\n",
463 "\n",
464 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
465 ]
466 },
467 {
468 "cell_type": "code",
469 "execution_count": null,
470 "metadata": {
471 "collapsed": false
472 },
473 "outputs": [],
474 "source": [
475 "par(mfrow=c(1,2))\n",
476 "plotSimils(p_nn_exo, i_np); title(paste(\"Weights nn exo day\",i_np))\n",
477 "plotSimils(p_nn_exo, i_p); title(paste(\"Weights nn exo day\",i_p))\n",
478 "\n",
479 "plotSimils(p_nn_mix, i_np); title(paste(\"Weights nn mix day\",i_np))\n",
480 "plotSimils(p_nn_mix, i_p); title(paste(\"Weights nn mix day\",i_p)\n",
481 "\n",
482 "# - pollué à gauche, + pollué à droite"
483 ]
484 },
485 {
486 "cell_type": "code",
487 "execution_count": null,
488 "metadata": {
489 "collapsed": false
490 },
491 "outputs": [],
492 "source": [
493 "# Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n",
494 "p_nn_exo$getParams(i_np)$window\n",
495 "p_nn_exo$getParams(i_p)$window\n",
496 "\n",
497 "p_nn_mix$getParams(i_np)$window\n",
498 "p_nn_mix$getParams(i_p)$window"
499 ]
500 },
501 {
502 "cell_type": "markdown",
503 "metadata": {},
504 "source": [
505 "\n",
506 "\n",
507 "<h2>Bilan</h2>\n",
508 "\n",
509 "Problème difficile : on ne fait guère mieux qu'une naïve moyenne des lendemains des jours\n",
510 "similaires dans le passé, ce qui n'est pas loin de prédire une série constante égale à la\n",
511 "dernière valeur observée (méthode \"zéro\"). La persistence donne parfois de bons résultats\n",
512 "mais est trop instable (sensibilité à l'argument <code>same_day</code>).\n",
513 "\n",
514 "Comment améliorer la méthode ?"
515 ]
516 }
517 ],
518 "metadata": {
519 "kernelspec": {
520 "display_name": "R",
521 "language": "R",
522 "name": "ir"
523 },
524 "language_info": {
525 "codemirror_mode": "r",
526 "file_extension": ".r",
527 "mimetype": "text/x-r-source",
528 "name": "R",
529 "pygments_lexer": "r",
530 "version": "3.3.3"
531 }
532 },
533 "nbformat": 4,
534 "nbformat_minor": 2
535}