Metropolis-Hastings en Scala

Tengo la sensación de que un lenguaje funcional (como Scala) está particularmente bien adaptado al tipo de operaciones que exige MCMC.

Juzguen Vds.

Primero, genero datos en R:

datos <- rnorm(500, 0.7, 1)
writeLines(as.character(datos), "/tmp/datos.txt")
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-R" data-lang="R"><span style="display:flex;"><span>Son de una normal con media <span style="color:#ae81ff">0.7</span>. En el modelo que vamos a crear, suponemos <span style="color:#a6e22e">conocida </span>(e igual a <span style="color:#ae81ff">1</span>) la varianza de la normal y trataremos de estimar la media suponiéndole una distribución a priori normal estándar. Y con Scala, así<span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;</span>div class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;highlight&#34;</span><span style="color:#f92672">&gt;&lt;</span>pre tabindex<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;0&#34;</span> style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;</span><span style="color:#f92672">&gt;&lt;</span>code class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;language-Scala&#34;</span> data<span style="color:#f92672">-</span>lang<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Scala&#34;</span><span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>import<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> scala.io.Source
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>import<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> java.io.PrintWriter
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#75715e&#34;</span><span style="color:#f92672">&gt;/*</span> read data <span style="color:#f92672">*/&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>val<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> source <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#a6e22e&#34;</span><span style="color:#f92672">&gt;</span>Source<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>fromFile<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#e6db74&#34;</span><span style="color:#f92672">&gt;&amp;</span><span style="color:#75715e">#34;/tmp/datos.txt&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;UTF-8&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>val<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> data <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> source<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>mkString<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>split<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#e6db74&#34;</span><span style="color:#f92672">&gt;&amp;</span><span style="color:#75715e">#34;\\s+&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;).&lt;/span&gt;map&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;_&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;toDouble&lt;span style=&#34;color:#f92672&#34;&gt;).&lt;/span&gt;toList</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#75715e&#34;</span><span style="color:#f92672">&gt;/*</span> we need random numbers <span style="color:#f92672">*/&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>var<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> r <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> scala<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>util<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#a6e22e&#34;</span><span style="color:#f92672">&gt;</span>Random<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#75715e&#34;</span><span style="color:#f92672">&gt;/*</span> <span style="color:#a6e22e">almost </span>(standard) dnorm <span style="color:#f92672">*/&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>def<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> dnorm<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>x<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> math<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>exp<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">-&lt;/</span>span<span style="color:#f92672">&gt;</span>x<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;*&lt;/</span>span<span style="color:#f92672">&gt;</span>x<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;/&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#ae81ff&#34;</span><span style="color:#f92672">&gt;</span><span style="color:#ae81ff">2</span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#75715e&#34;</span><span style="color:#f92672">&gt;/*</span> chain transitions <span style="color:#f92672">*/&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>def<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> rg<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>y<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> y <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;+&lt;/</span>span<span style="color:#f92672">&gt;</span> r<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>nextGaussian
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#75715e&#34;</span><span style="color:#f92672">&gt;/*</span> <span style="color:#a6e22e">prior </span>(standard normal) times likelihood <span style="color:#f92672">*/&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>def<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> dpost<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>x<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> dnorm<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>x<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;*&lt;/</span>span<span style="color:#f92672">&gt;</span> data<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>map<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>y <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;=&amp;</span>gt;<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> dnorm<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>x <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;-&lt;/</span>span<span style="color:#f92672">&gt;</span> y<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)).&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>reduce<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>_<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;*&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>_<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#75715e&#34;</span><span style="color:#f92672">&gt;/*</span> metropolis<span style="color:#f92672">-</span>hastings acceptance ratio <span style="color:#f92672">*/&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>def<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> acceptanceRatio<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>from<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>,<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> to<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> dpost<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>to<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;/&lt;/</span>span<span style="color:#f92672">&gt;</span> dpost<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>from<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>def<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> posterior<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>a<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;:&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Stream<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>[<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>Double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>]<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>{<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>    <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>lazy<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>val<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> elegidos <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#a6e22e&#34;</span><span style="color:#f92672">&gt;</span>Stream<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>continually<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>a<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> map rg filter <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>x <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;=&amp;</span>gt;<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> r<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>nextDouble <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;&amp;</span>lt;<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> acceptanceRatio<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>a<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>,<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> x<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>))<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>    a <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span><span style="color:#75715e">#&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;posterior&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;elegidos.head&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>}<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#75715e&#34;</span><span style="color:#f92672">&gt;/*</span> Get values and drop burning obs <span style="color:#f92672">*/&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>val<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> res <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> posterior<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#ae81ff&#34;</span><span style="color:#f92672">&gt;</span><span style="color:#ae81ff">0.4</span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>).&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>take<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#ae81ff&#34;</span><span style="color:#f92672">&gt;</span><span style="color:#ae81ff">10000</span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>).&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>toList<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>drop<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#ae81ff&#34;</span><span style="color:#f92672">&gt;</span><span style="color:#ae81ff">2000</span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#75715e&#34;</span><span style="color:#f92672">&gt;/*</span> Thin <span style="color:#f92672">*/&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>val<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> res_thin <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> res zip <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#a6e22e&#34;</span><span style="color:#f92672">&gt;</span>Stream<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> from <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#ae81ff&#34;</span><span style="color:#f92672">&gt;</span><span style="color:#ae81ff">1</span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> filter <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>_<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>_2 <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>%<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#ae81ff&#34;</span><span style="color:#f92672">&gt;</span><span style="color:#ae81ff">5</span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;==&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#ae81ff&#34;</span><span style="color:#f92672">&gt;</span><span style="color:#ae81ff">0</span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> map <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>_<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>_1<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#75715e&#34;</span><span style="color:#f92672">&gt;/*</span> Export <span style="color:#f92672">*/&lt;/</span>span<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>val<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> out <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#66d9ef&#34;</span><span style="color:#f92672">&gt;</span>new<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#a6e22e&#34;</span><span style="color:#f92672">&gt;</span>PrintWriter<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#e6db74&#34;</span><span style="color:#f92672">&gt;&amp;</span><span style="color:#75715e">#34;/tmp/posterior.txt&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>res map out<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>println
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>out<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>.&lt;<span style="color:#f92672">/</span>span<span style="color:#f92672">&gt;</span>close<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;</span>()<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>code<span style="color:#f92672">&gt;&lt;/</span>pre<span style="color:#f92672">&gt;&lt;/</span>div<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Leo los datos de la posteriori en R y los represento así<span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;</span>div class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;highlight&#34;</span><span style="color:#f92672">&gt;&lt;</span>pre tabindex<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;0&#34;</span> style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;</span><span style="color:#f92672">&gt;&lt;</span>code class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;language-R&#34;</span> data<span style="color:#f92672">-</span>lang<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;R&#34;</span><span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;</span>posterior <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;&amp;</span>lt;<span style="color:#f92672">-&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#a6e22e&#34;</span><span style="color:#f92672">&gt;</span>as.double<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#a6e22e&#34;</span><span style="color:#f92672">&gt;</span>readLines<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>(<span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#e6db74&#34;</span><span style="color:#f92672">&gt;&amp;</span><span style="color:#75715e">#34;/tmp/posterior.txt&amp;#34;&lt;/span&gt;))</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;display:flex;&#34;</span><span style="color:#f92672">&gt;&lt;</span>span<span style="color:#f92672">&gt;&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#a6e22e&#34;</span><span style="color:#f92672">&gt;</span>hist<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>(posterior, breaks <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#f92672&#34;</span><span style="color:#f92672">&gt;=&lt;/</span>span<span style="color:#f92672">&gt;</span> <span style="color:#f92672">&lt;</span>span style<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;color:#ae81ff&#34;</span><span style="color:#f92672">&gt;</span><span style="color:#ae81ff">50</span><span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;</span>)<span style="color:#f92672">&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>span<span style="color:#f92672">&gt;&lt;/</span>code<span style="color:#f92672">&gt;&lt;/</span>pre<span style="color:#f92672">&gt;&lt;/</span>div<span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">!</span>[posteriori_scala<span style="color:#a6e22e">]</span>(<span style="color:#f92672">/</span>wp<span style="color:#f92672">-</span>uploads<span style="color:#f92672">/</span><span style="color:#ae81ff">2016</span><span style="color:#f92672">/</span><span style="color:#ae81ff">06</span><span style="color:#f92672">/</span>posteriori_scala.png<span style="color:#75715e">#center)</span></span></span></code></pre></div>