Here's a task that doesn't seem to be terribly well documented in one place. What happens if you want to spin up some long-running background shell process in clojure? For example, suppose you're trying to communicate with a python script (example of how to do that), and you'd like to spin both the rabbitmq server and the continuously-running python script up from your main clj application? You can't just use clojure.java.shell, because that will hang the application until the other process returns (i.e., it's blocking).
The easiest method to do this that I can discern is to just wrap it in a future. For example:Continue reading →
(With help from Carlos De La Guardia, who was like "dude, vectorize this stuff" after seeing the incredibly slow implementation the first time, and then was kind enough to talk through the problem and the notebook on which this post is based. All infelicities are mine (and I didn't even implement his wise suggestions for cleaning up the notebook).)
Naive Bayes is the simplest possible machine learning algorithm. In its Bernoulli form, calculation is just a matter of applying probability 101 techniques to calculate the (estimated) conditional probabilities of your predictors given the labels and estimated probability of the labels, then applying Bayes Rule directly to generate a posterior on a label given the data. Trivial.Continue reading →
Mathjax and markdown tend to fight with one another a bit. When I started blogging math notes on here, the combination of Mathjax and Cryogen's markdown parser and Highlight.js fought with one another a lot. So here's a quick tutorial on fixing it.
The assumption here is that you want to write in normal markdown, i.e., the kind of thing that you could convert to a PDF with pandoc. And you want to write latex math. But you observe that doing so blows up when you convert to html and use mathjax.
So, confession: my brain works in a functional way, and really doesn't work in an object-oriented way. This can be a bit of an issue when you're using an object-oriented language and trying to avoid excessive code duplication.
So here's some really unnatural stuff I just did. The problem: I'm writing a Python library to wrap a bunch of legal and political APIs with a simpler interface. (Extreme work in progress.) I had a bunch of code that looked very similar. For example, this was what two of my session objects (interfaces to different APIs) looked like, in relevant part:Continue reading →