/dav/random some of my randomness https://davrandom.github.io/ Fri, 06 Feb 2026 10:49:11 +0000 Fri, 06 Feb 2026 10:49:11 +0000 Jekyll v3.10.0 Use tensorflow to calculate symbolic derivatives of a function (minimal example) <p>I was using Theano to calculate the jacobian and hessian of some functions in my Python code, but Theano has been “discontinued”.</p> <p>So how can I replace Theano with some other supported library?</p> <p>Tensorflow is a possible alternative, but the library and its jargoon is mainly oriented to DeepLearning tasks. So, doing something as simple as getting the symbolic derivative of a function gets “linguistically” complicated… but we’ll see that it’s not difficult to achieve in TensorFlow… actually it’s quite the opposite!</p> <p>I want to give you a minimal example, then you can build on it.</p> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">tensorflow</span> <span class="k">as</span> <span class="n">tf</span> <span class="c1"># get a number from terminal </span><span class="k">print</span><span class="p">(</span><span class="s">"type a number and press enter"</span><span class="p">)</span> <span class="n">point</span> <span class="o">=</span> <span class="nb">input</span><span class="p">()</span> <span class="n">point</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">point</span><span class="p">)</span> <span class="n">data</span> <span class="o">=</span> <span class="n">tf</span><span class="p">.</span><span class="n">placeholder</span><span class="p">(</span><span class="n">dtype</span><span class="o">=</span><span class="n">tf</span><span class="p">.</span><span class="n">float32</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">())</span> <span class="c1"># the function you want to calculate the gradient </span><span class="k">def</span> <span class="nf">funct</span><span class="p">(</span><span class="n">indata</span><span class="p">):</span> <span class="n">square</span> <span class="o">=</span> <span class="n">tf</span><span class="p">.</span><span class="nb">pow</span><span class="p">(</span><span class="n">indata</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="k">return</span> <span class="n">square</span> <span class="c1"># start a TensorFlow session (you need it to evaluate numerically the symbolic expressions) </span><span class="n">sess</span> <span class="o">=</span> <span class="n">tf</span><span class="p">.</span><span class="n">Session</span><span class="p">()</span> <span class="n">tf_funct</span> <span class="o">=</span> <span class="n">funct</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="c1"># TF symbolic version of funct </span><span class="n">val_funct</span> <span class="o">=</span> <span class="n">tf_funct</span><span class="p">.</span><span class="nb">eval</span><span class="p">(</span><span class="n">feed_dict</span><span class="o">=</span><span class="p">{</span><span class="n">data</span><span class="p">:</span> <span class="n">point</span><span class="p">},</span> <span class="n">session</span><span class="o">=</span><span class="n">sess</span><span class="p">)</span> <span class="c1"># value of funct in your point </span><span class="k">print</span><span class="p">(</span><span class="s">"The value you entered squared: %.1f"</span> <span class="o">%</span> <span class="n">val_funct</span><span class="p">)</span> <span class="n">grad_funct</span> <span class="o">=</span> <span class="n">tf</span><span class="p">.</span><span class="n">gradients</span><span class="p">(</span><span class="n">tf_funct</span><span class="p">,</span> <span class="p">[</span><span class="n">data</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span> <span class="c1"># calculate the gradient of funct </span><span class="n">val_grad_funct</span> <span class="o">=</span> <span class="n">grad_funct</span><span class="p">.</span><span class="nb">eval</span><span class="p">(</span><span class="n">feed_dict</span><span class="o">=</span><span class="p">{</span><span class="n">data</span><span class="p">:</span> <span class="n">point</span><span class="p">},</span> <span class="n">session</span><span class="o">=</span><span class="n">sess</span><span class="p">)</span> <span class="c1"># evaluate the gradient in your point </span><span class="k">print</span><span class="p">(</span><span class="s">"Twice the value you entered: %.1f"</span> <span class="o">%</span> <span class="n">val_grad_funct</span><span class="p">)</span> </code></pre></div></div> <p>Easy! HTH</p> <p>I was using Theano to calculate the jacobian and hessian of some functions in my Python code, but Theano has been “discontinued”.</p> Wed, 20 Jun 2018 00:00:00 +0000 https://davrandom.github.io/blog/Use-tensorflow-to-calculate-gradients/ https://davrandom.github.io/blog/Use-tensorflow-to-calculate-gradients/ memo programming After updating ruby gems jekyll stops working <p>Today I updated the ruby gems because I installed a new gem and thought that it passed a long time since the last time I updated them…</p> <p>The rule should be ‘if it works, don’t touch it’… but… I did.</p> <p>Searching for a solution, I actually <a href="https://talk.jekyllrb.com/t/updated-gems-now-jekyll-auto-regenerate-is-broken/1574/5">found one</a>!</p> <p>To fight obsolescence I will copy anthonyjsmith solution here:</p> <p><em>As you’re building a GitHub Pages site, I suggest making a file in the same folder as _config.yml called Gemfile with this as the contents:</em></p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>source 'https://rubygems.org' gem 'github-pages' </code></pre></div></div> <p><em>Then run these commands:</em></p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gem install bundler bundle install bundle exec jekyll serve -V </code></pre></div></div> <p><em>The bundle exec in the last command makes sure you run the same version of Jekyll as on GitHub Pages, and the -V gives verbose output, which might give you some clues if things go wrong.</em></p> <p>The End. HTH</p> <p>Today I updated the ruby gems because I installed a new gem and thought that it passed a long time since the last time I updated them…</p> Wed, 03 Aug 2016 00:00:00 +0000 https://davrandom.github.io/blog/Updated-gems-broken-jekyll/ https://davrandom.github.io/blog/Updated-gems-broken-jekyll/ web metapost memo Camminate in Catalunya <p>Come la maggior parte dei post di questo sito è principalmente scritto per ricordare a me delle cose. Ma spero che possa essere in qualche modo utile anche ad altri.</p> <p>Qui raccolgo le camminate –di solito montane– fatte in Catalunya.</p> <h2 id="2014">2014</h2> <p>Ottobre - <a href="http://es.wikiloc.com/wikiloc/view.do?id=14170864">Garrotxa: Volcan Santa María e Fageda</a> // :repeat: 13.7km :arrow_up: 607m</p> <p>Settembre - <a href="http://es.wikiloc.com/wikiloc/view.do?id=14170515">da Greixer a Refugio de Sant Jordi</a> // :repeat: 17.4km :arrow_up: 1485m</p> <h2 id="2015">2015</h2> <p>Maggio - <a href="http://es.wikiloc.com/wikiloc/view.do?id=9830282">Bruguers - Morella - Bruguers</a> // :repeat: 13.2km :arrow_up: 523m</p> <p>Giugno - <a href="http://es.wikiloc.com/wikiloc/view.do?id=14167993">Bastiments</a> // :repeat: 9.0km :arrow_up: 2714m</p> <p>Luglio - <a href="http://es.wikiloc.com/wikiloc/view.do?id=14168178">Nuria - Puigmal - Nuria</a> // :repeat: 9.8km :arrow_up: 2754m</p> <p>Novembre - <a href="http://es.wikiloc.com/wikiloc/view.do?id=14168244">Hospital de Sangre</a> // :repeat: 13.0km :arrow_up: 946m</p> <h2 id="2016">2016</h2> <p>Febbraio - <a href="http://es.wikiloc.com/wikiloc/view.do?id=14168360">da Sant Vicent de Castellet a Sant Jaume de Vallhonesta</a> // :repeat: 11.5km :arrow_up: 354m</p> <p>Maggio - <a href="http://es.wikiloc.com/wikiloc/view.do?id=14168415">da Olesa de Bonesvalls a La Mola del Garraf</a> // :repeat: 10.5km :arrow_up: 445m</p> <p>Luglio - <a href="http://es.wikiloc.com/wikiloc/view.do?id=14168444">da Presa de Cavallers a Refugio Ventosa</a> // :repeat: 14.5km :arrow_up: 2037m</p> <p>Come la maggior parte dei post di questo sito è principalmente scritto per ricordare a me delle cose. Ma spero che possa essere in qualche modo utile anche ad altri.</p> Mon, 01 Aug 2016 00:00:00 +0000 https://davrandom.github.io/blog/camminate_in_catalunya/ https://davrandom.github.io/blog/camminate_in_catalunya/ viaggi memo post from MrHyde app <p>so… I was wandering about the possibility of having a telegram bot that interfaces with Jekyll to publish new posts… these days when I go home I don’t really want to open another PC and start writing posts…</p> <p>apparently there is no such a thing as a telegram Jekyll bot yet, but an Android app should be already there, no? let’s ask Google…</p> <p>and tha-daaa I found <a href="https://play.google.com/store/apps/details?id=org.faudroids.mrhyde">MrHyde</a> by faudroids! and this is my very first test from their Android app</p> <p><img src="/images/mrhyde.png" alt="screenshot" /></p> <p>let’s see what happens</p> <p>update: it would be cool to drag and drop stuff like links and images and get the markdown already in place… dreaming?</p> <p>update 2: I actually opened a bug in faudroid github and they were kind enough to add a markdown cheatshett to their app. Now waiting for this fix to propagate until google Play.</p> <p>update 3: the fix reached Google play! thanks!</p> <p><img src="/images/markdown1.png" alt="insert markdown" /></p> <p><img src="/images/markdown2.png" alt="insert markdown list" /></p> <p>so… I was wandering about the possibility of having a telegram bot that interfaces with Jekyll to publish new posts… these days when I go home I don’t really want to open another PC and start writing posts…</p> Thu, 14 Jul 2016 00:00:00 +0000 https://davrandom.github.io/blog/post-from-mrhyde-app/ https://davrandom.github.io/blog/post-from-mrhyde-app/ android memo metapost Running Portabee GO v1 from MacOs <p>I’m finally entering the world of 3D printing. After having printed a small piece and payed quite some money, I decided to go for neighbouring resources. A colleague of mine has a small Portabee Go v1, so I decided to try it out.</p> <p>Since it resulted quite hacky to get it printing something, I decided to take some notes for future reference.</p> <p>Todo list:</p> <ul> <li>install software as documented by portabee (if you are under MacOs install 2014 version of printrun, the 2015 doesn’t work)</li> <li>open cura</li> <li>open model</li> <li>export gcode</li> <li>from the created gcode remove line: M109 S210.000000</li> <li>remove also the last lines where the carried is moved to home position:</li> <li>open gcode in printurn</li> <li>(in printrun)</li> <li>connect</li> <li>reset TWICE</li> <li>start the fan: M106</li> <li>set temperature</li> <li>print</li> </ul> <p>Changing values of printing velocity in Cura helps a lot with the quality of the print (to be honest, quite low for this model of printer). HTH</p> I'm finally entering the world of 3D printing. After having printed a small piece and payed quite some money, I decided to go for neighbouring resources. A colleague of mine has a small Portabee Go v1, so I decided to try it out. Thu, 25 Feb 2016 00:00:00 +0000 https://davrandom.github.io/blog/portabee_go/ https://davrandom.github.io/blog/portabee_go/ nerdiness memo tips Regulador de parabrisas Touratech, mi experiencia <p>En junio 2015 compré una Yamaha Super Ténéré XT1200Z de segunda mano (2011). Como soy bastante alto, la pantalla normal no me cubre en los trayectos en autopista, mientras que con la pantalla más alta me faltan los clásicos dos dedos para estar bien cubierto. Entonces mirando los acesorios de Touratech encontré un <a href="http://shop.touratech-españa.com/en/carenado-y-parabrisas/2339-regulador-del-parabrisas-con-barra-de-montaje-para-gps-para-yamaha-xt1200z-super-tenere.html#/combinacion-basica">soporte para el parabrisas</a> de la XT1200Z que se puede regular en altura e inclinación. Vale al rededor de los 110€ … no sale barato.</p> <h2 id="descripción-del-producto">Descripción del producto</h2> <p>El regulador está hecho de dos piezas metalicas, una que se atornilla al cuadro donde se atornilla la pantalla normalmente, y una otra pieza a la que hay que atornillar la pantalla. Las dos piezas deslizan una sobre la otra permitiendo regular la altura y la inclinación de la pantalla. Las dos piezas se aseguran entre ellas a través de cuatro tornillos que llevan una tuerca cada uno que se puede abrir y cerrar con los dedos.</p> <p>El producto parece bien pensado y hecho.</p> <h2 id="mi-experiencia-de-uso">Mi experiencia de uso</h2> <p>La instalación es extremadamente fácil: sacar la pantalla, montar el soporte Touratech, montar otra vez la pantalla sobre el nuevo soporte. Diez minutos como mucho.</p> <p>Parece que el producto esté bien pensado pero nunca probado en carretera. Ahora me explico. Este producto tiene esencialmente dos problemas, a mi manera de ver:</p> <ol> <li> <p>Las tuercas que aseguran las dos piezas se destornillan con las vibraciones de la moto</p> </li> <li> <p>Las arandelas y las dos piezas deslizan entre ellas, así que la pantalla vuelve a su inclinación mínima después de pocos kilómetros de autopista</p> </li> </ol> <p>Bueno … sí es que soy un tiquismiquis. Sí y no: si se destornilla una tuerca y te parte un tornillo mientras que estás conduciendo, os aseguro que no es nada divertido. Y es exactamente lo que me pasó a mi. Después del susto, escribí al servicio de postventa de Touratech España para saber como/donde encontrar una tuerca, tornillo y arandelas adecuadas.</p> <h2 id="servicio-postventa-españa">Servicio postventa España</h2> <p>Este es el correo que les envié:</p> <p><em>Buenos días,</em></p> <p><em>hace un par de meses compré un regulador del parabrisas con barra de montaje para GPS para Yamaha XT1200Z Super Tenere. Después de montarlo y utilizarlo de he dado cuenta que los 4 tornillos que permiten regular la altura e inclinación del parabrisas no agarran bien (la pantalla vuelve a la inclinación mínima) y a veces se destornillan. Yo veo dos problemas:</em></p> <ol> <li><em>las arandelas son demasiado lisas y deslizan sobre el metal, así que la pantalla vuelve en posición de mínimo ángulo con el viento</em></li> <li><em>los tornillos se destornillan solos! habría que poner un final de recorrido en la tuerca.</em></li> </ol> <p><em>Mientras que estaba viajando una tuerca y el tornillo se soltaron y se volaron golpeando el deposito y los perdí. Fue un buen susto porqué no entendí enseguida lo que había pasado, pensé de haber perdido una pieza más fundamental. Además había vehículos detrás de mi y por suerte nadie se hizo daño.</em></p> <p><em>Pregunta: ¿donde puedo encontrar un tornillo y tuerca adecuados? (ya que son bastante peculiares)</em></p> <p><em>Muchas gracias y un saludo</em></p> <p>Me contestaron muy rapidamente diciendome que pedian la pieza a la fábrica de Alemania. Después de poco me llegan las piezas a casa, parece todo perfect. Intento atornillar la tuerca al tornillo pero no acaba de atornillarse… uhm… aquí pasa algo raro! La tuerca es de 4mm y el tornillo de 6mm! Escribo un correo al servicio postventa. No me contestan. Vuelvo a escribir un correo al servicio postventa. No me contestan. Escribo un percer correo al servicio postventa. No me contestan.</p> <p>Ok. Ahora estoy cabreado y no hay manera de encontrar una tuerca apta.</p> <p>Para el cabreado escribiré este articulo en 4 idiomas (lo siento si hay errores el Castellano no es mi idioma materno). Para la tuerca emprimiré una con una impresora 3D.</p> <h2 id="emprimir-una-tuerca-en-3d">Emprimir una tuerca en 3D</h2> <p>He hecho un dibujo con OpenScad de la tuerca:</p> <p><a data-flickr-embed="true" href="https://www.flickr.com/photos/davrandom/24447444169/in/dateposted-public/" title="Tuerca in OpenScad"><img src="https://farm2.staticflickr.com/1537/24447444169_f364b3e96e.jpg" width="486" height="442" alt="Tuerca in OpenScad" /></a><script async="" src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"></script></p> <p>La idea es que el plastico sirva como agarre para una tuerca normal y corriente en inox que pondremos dentro de este esqueleto de plastico.</p> <p>Después he ido a un bar de Barcelona donde se pueden emprimir objetos en 3D, y aquí está la pieza:</p> <p><a data-flickr-embed="true" href="https://www.flickr.com/photos/davrandom/24186766294/in/dateposted-public/" title="Tuerca"><img src="https://farm2.staticflickr.com/1568/24186766294_7f3a08ef37_z.jpg" width="536" height="640" alt="Tuerca" /></a><script async="" src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"></script></p> <p>El código fuente para esta pieza está <a href="https://bitbucket.org/davrandom/misc_projects/src/4e7c5a98694037af93aa3a701b41f9e9929f51b1/3D_scad/?at=master">aquí</a>; la pieza se llama touratech_grip y tenéis tanto el scad como el stl.</p> <p>No estoy al 100% satisfecho con este diseño y en los próximos meses lo cambiaré bastante…</p> <h2 id="solucionar-el-deslizamiento-de-la-pantalla">Solucionar el deslizamiento de la pantalla</h2> <p>Una solucíon que no prevee poner arandelas más agresivas es poner una arandela de goma entre la placa del soporte y la arandela metálica que va a contacto con la tuerca.</p> En junio 2015 compré una Yamaha Super Ténéré XT1200Z de segunda mano (2011). Como soy bastante alto, la pantalla normal no me cubre en los trayectos en autopista, mientras que con la pantalla más alta me faltan los clásicos dos dedos para estar bien cubierto. Wed, 03 Feb 2016 00:00:00 +0000 https://davrandom.github.io/blog/touratech_es/ https://davrandom.github.io/blog/touratech_es/ moto diy My Vespa ET4 1996 <p>Dopo essere tornato dall’esperienza di Summer Student al Cern nel 2007, mi erano rimasti un po’ di euro in tasca. Non molti a dire il vero, cinquecento, ma sufficienti per iniziare a sognare un mezzo a due ruote con motore. Un pomeriggio estivo nel dipartimento di Fisica, dopo una partita di scopone, sfoglio il settimanale di annunci della zona, “il Mercatino”. Trovo l’annuncio di una Vespa ET4 del 96 per … esattamente il mio budget! Poi la Vespa…</p> <p>Chiamo i miei “Domani vado a vedere una vespa” loro “non la comprerai mica?” … beh intanto vado a vederla. Il giorno dopo mi trovo con questo signore, appena andato in pensione, molto preciso e gentile. La vespa è perfetta. Come faccio a non comprarla? E infatti la compro.</p> <p>Qui ritratta in mezzo ai campi della furlanìa, nelle vicinanze di Muscletto.</p> <p><img src="/images/vespetta_muscletto_small.jpg" alt="vespetta" /></p> <p>La mia esperienza con questa Vespa è stata super positiva. Affidabile, non velocissima, ho fatto un sacco di chilometri e traslochi… che non saprei quantificare esattamente.</p> Un pomeriggio estivo nel dipartimento di Fisica, dopo una partita di scopone, sfoglio il settimanale di annunci della zona, "il Mercatino". Trovo l'annuncio di una Vespa ET4 del 96 per ... esattamente il mio budget! Poi la Vespa... Sun, 24 Jan 2016 00:00:00 +0000 https://davrandom.github.io/blog/vespettaET4/ https://davrandom.github.io/blog/vespettaET4/ moto La Tenerona (XT750Z) 1989 <p>Dopo essere stato investito da una signora distratta in País Vasco nel viaggio con Andrea, nel mentre in cui la Dory veniva lentamente riparata, ho pensato bene di prendere un’altra moto. La caratteristica principale era che doveva essere economica. A fine 2013 compro un mito: la Super Ténéré XT750Z del 1989 per “soli” 2500 euro, con borse rigide e tutto…</p> <p>Sulla carta fantastica: posso viaggiare, fare un po’ di enduro (i campi! l’infanzia! la natura!)</p> <p>Si rivelerà il peggior acquisto mai fatto finora. La rivenderò a inizio 2015 per 1000 euro e con la voglia di andare in moto quasi estinta.</p> <p><img src="/images/tenerona_a_casa.jpg" alt="tenerona a bcn" /></p> Dopo essere stato investito da una signora distratta in País Vasco nel viaggio con Andrea, nel mentre in cui la Dory veniva lentamente riparata, ho pensato bene di prendere un'altra moto. Fri, 22 Jan 2016 00:00:00 +0000 https://davrandom.github.io/blog/tenerona/ https://davrandom.github.io/blog/tenerona/ moto Trying a table in md <p>This is a typical table written in markdown</p> <table> <thead> <tr> <th>Tables</th> <th style="text-align: center">Are</th> <th style="text-align: right">Cool</th> </tr> </thead> <tbody> <tr> <td>col 1 is</td> <td style="text-align: center">left-aligned</td> <td style="text-align: right">$1600</td> </tr> <tr> <td>col 2 is</td> <td style="text-align: center">centered</td> <td style="text-align: right">$12</td> </tr> <tr> <td>col 3 is</td> <td style="text-align: center">right-aligned</td> <td style="text-align: right">$1</td> </tr> </tbody> </table> <p>Which is cool and fast.</p> <p>But actually I would like to make a table without borders… and for that you need to write the table in html :( A <a href="http://www.tablesgenerator.com/html_tables">nice website</a> can help in this task. Try it out!</p> <p>HTH d</p> A typical table in md Thu, 10 Dec 2015 00:00:00 +0000 https://davrandom.github.io/blog/tabletest/ https://davrandom.github.io/blog/tabletest/ memo tips memo Open a terminal IN Vim <p>I was searching for a way to open a shell in Vim and I got many answers. Essentially all the juice is listed <a href="http://stackoverflow.com/questions/1236563/how-to-run-a-terminal-inside-of-vim">here</a>. First I will list the ones that are possible but that are not <em>my</em> answer:</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>:! somecommand <span class="o">[</span>ENTER] </code></pre></div></div> <p>or</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>:! bash <span class="o">(</span>or your favourite shell<span class="o">)</span> <span class="o">[</span>ENTER] </code></pre></div></div> <p>But no… this is not what I wanted. I wanted a <em>real</em> terminal <strong>inside</strong> (a tab of) <strong>Vim</strong>… so the answer is <a href="https://code.google.com/p/conque/">ConqueTerm</a>. Enjoy!</p> <p>HTH</p> <p>d</p> Sometimes you really want to open a terminal IN Vim. Here is how you do that! Wed, 19 Aug 2015 00:00:00 +0000 https://davrandom.github.io/blog/open_terminal_in_vim/ https://davrandom.github.io/blog/open_terminal_in_vim/ memo tips memo