after merge
[talweg.git] / pkg / vignettes / talweg.Rmd
CommitLineData
613a986f 1---
8f84543c
BA
2title: "talweg"
3author: "Benjamin Auder"
613a986f
BA
4date: "`r Sys.Date()`"
5output: rmarkdown::html_vignette
6vignette: >
7 %\VignetteIndexEntry{Vignette Title}
8 %\VignetteEngine{knitr::rmarkdown}
9 %\VignetteEncoding{UTF-8}
10---
11
8f84543c
BA
12
13## Introduction
14
15J'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
16
17 * simtype="exo" ou "mix" : similarités exogènes avec/sans endogènes (fenêtre optimisée par VC)
18 * same_season=FALSE : les indices pour la validation croisée ne tiennent pas compte des saisons
19 * mix_strategy="mult" : on multiplie les poids (au lieu d'en éteindre)
20
21J'ai systématiquement comparé à une approche naïve : la moyennes des lendemains des jours "similaires" dans tout le passé ; à chaque fois sans prédiction du saut (sauf pour Neighbors : prédiction basée sur les poids calculés).
22
23Ensuite j'affiche les erreurs, quelques courbes prévues/mesurées, quelques filaments puis les histogrammes de quelques poids. Concernant les graphes de filaments, la moitié gauche du graphe correspond aux jours similaires au jour courant, tandis que la moitié droite affiche les lendemains : ce sont donc les voisinages tels qu'utilisés dans l'algorithme.
24
25<h2 style="color:blue;font-size:2em">Pollution par chauffage</h2>
26
27
28loop: indices_ch, ep, np et titres: Pollution par chauffage, Pollution par épandage, Semaine non polluée
29
30
31
32p_nn_exo = computeForecast(data, indices_ch, "Neighbors", "Neighbors", simtype="exo", horizon=H)
33p_nn_mix = computeForecast(data, indices_ch, "Neighbors", "Neighbors", simtype="mix", horizon=H)
34p_az = computeForecast(data, indices_ch, "Average", "Zero", horizon=H) #, memory=183)
35p_pz = computeForecast(data, indices_ch, "Persistence", "Zero", horizon=H, same_day=TRUE)
36
37e_nn_exo = computeError(data, p_nn_exo)
38e_nn_mix = computeError(data, p_nn_mix)
39e_az = computeError(data, p_az)
40e_pz = computeError(data, p_pz)
41options(repr.plot.width=9, repr.plot.height=7)
42plotError(list(e_nn_mix, e_pz, e_az, e_nn_exo), cols=c(1,2,colors()[258], 4))
43
44#Noir: neighbors_mix, bleu: neighbors_exo, vert: moyenne, rouge: persistence
45
46i_np = which.min(e_nn_exo$abs$indices)
47i_p = which.max(e_nn_exo$abs$indices)
48
49options(repr.plot.width=9, repr.plot.height=4)
50par(mfrow=c(1,2))
51
52plotPredReal(data, p_nn_exo, i_np); title(paste("PredReal nn exo day",i_np))
53plotPredReal(data, p_nn_exo, i_p); title(paste("PredReal nn exo day",i_p))
54
55plotPredReal(data, p_nn_mix, i_np); title(paste("PredReal nn mix day",i_np))
56plotPredReal(data, p_nn_mix, i_p); title(paste("PredReal nn mix day",i_p))
57
58plotPredReal(data, p_az, i_np); title(paste("PredReal az day",i_np))
59plotPredReal(data, p_az, i_p); title(paste("PredReal az day",i_p))
60
61#Bleu: prévue, noir: réalisée
62
63par(mfrow=c(1,2))
64f_np_exo = computeFilaments(data, p_nn_exo, i_np, plot=TRUE); title(paste("Filaments nn exo day",i_np))
65f_p_exo = computeFilaments(data, p_nn_exo, i_p, plot=TRUE); title(paste("Filaments nn exo day",i_p))
66
67f_np_mix = computeFilaments(data, p_nn_mix, i_np, plot=TRUE); title(paste("Filaments nn mix day",i_np))
68f_p_mix = computeFilaments(data, p_nn_mix, i_p, plot=TRUE); title(paste("Filaments nn mix day",i_p))
69
70par(mfrow=c(1,2))
71plotFilamentsBox(data, f_np_exo); title(paste("FilBox nn exo day",i_np))
72plotFilamentsBox(data, f_p_exo); title(paste("FilBox nn exo day",i_p))
73
74plotFilamentsBox(data, f_np_mix); title(paste("FilBox nn mix day",i_np))
75plotFilamentsBox(data, f_p_mix); title(paste("FilBox nn mix day",i_p))
76
77par(mfrow=c(1,2))
78plotRelVar(data, f_np_exo); title(paste("StdDev nn exo day",i_np))
79plotRelVar(data, f_p_exo); title(paste("StdDev nn exo day",i_p))
80
81plotRelVar(data, f_np_mix); title(paste("StdDev nn mix day",i_np))
82plotRelVar(data, f_p_mix); title(paste("StdDev nn mix day",i_p))
83
84#Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir
85
86par(mfrow=c(1,2))
87plotSimils(p_nn_exo, i_np); title(paste("Weights nn exo day",i_np))
88plotSimils(p_nn_exo, i_p); title(paste("Weights nn exo day",i_p))
89
90plotSimils(p_nn_mix, i_np); title(paste("Weights nn mix day",i_np))
91plotSimils(p_nn_mix, i_p); title(paste("Weights nn mix day",i_p)
92
93#- pollué à gauche, + pollué à droite
94
95#Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite
96p_ch_nn_exo$getParams(i_np)$window
97p_ch_nn_exo$getParams(i_p)$window
98
99p_ch_nn_mix$getParams(i_np)$window
100p_ch_nn_mix$getParams(i_p)$window
101
102
103
104
105## Bilan
106
107Problè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 dernière valeur observée (méthode "zéro"). La persistence donne parfois de bons résultats mais est trop instable (sensibilité à l'argument <code>same_day</code>).
108
109Comment améliorer la méthode ?
110
111
112
113
613a986f
BA
114Vignettes are long form documentation commonly included in packages. Because they are part of the distribution of the package, they need to be as compact as possible. The `html_vignette` output type provides a custom style sheet (and tweaks some options) to ensure that the resulting html is as small as possible. The `html_vignette` format:
115
116- Never uses retina figures
117- Has a smaller default figure size
118- Uses a custom CSS stylesheet instead of the default Twitter Bootstrap style
119
120## Vignette Info
121
122Note the various macros within the `vignette` section of the metadata block above. These are required in order to instruct R how to build the vignette. Note that you should change the `title` field and the `\VignetteIndexEntry` to match the title of your vignette.
123
124## Styles
125
126The `html_vignette` template includes a basic CSS theme. To override this theme you can specify your own CSS in the document metadata as follows:
127
128 output:
129 rmarkdown::html_vignette:
130 css: mystyles.css
131
132## Figures
133
134The figure sizes have been customised so that you can easily put two images side-by-side.
135
136```{r, fig.show='hold'}
137plot(1:10)
138plot(10:1)
139```
140
141You can enable figure captions by `fig_caption: yes` in YAML:
142
143 output:
144 rmarkdown::html_vignette:
145 fig_caption: yes
146
147Then you can use the chunk option `fig.cap = "Your figure caption."` in **knitr**.
148
149## More Examples
150
151You can write math expressions, e.g. $Y = X\beta + \epsilon$, footnotes^[A footnote here.], and tables, e.g. using `knitr::kable()`.
152
153```{r, echo=FALSE, results='asis'}
154knitr::kable(head(mtcars, 10))
155```
156
157Also a quote using `>`:
158
159> "He who gives up [code] safety for [code] speed deserves neither."
160([via](https://twitter.com/hadleywickham/status/504368538874703872))