Sunday, May 25, 2014

Book review: "Clojure for machine learning"

I had the opportunity to give my opinion about a book that I expected to read. After having encountered some issues dealing with Incanter matrices (a ML framework for Clojure programers), I googled my issue and got answers that seem to be part of Clojure for Machine Learning book (Packt Publishing). Of course, the book wasn't entirely available online, so you can imagine how I felt when I got the whole copy three days later for review.

First of all, it was the first time I've read a book from Packt. I have to admit it was even the first time I've heard about Packt. I can't say I was amazed by the layout and print styles, but it's more than acceptable (and totally subjective!).


Machine Learning

Well, it's time to talk about the content. I know it's always hard to provide well balanced explanations of machine learning algorithms: too academic books become so boring for those who already master the concepts and underlying mathematics (and for those who absolutely don't have any maths background). Too pragmatic books, at the contrary, can be interesting and relevant but most of the time it becomes quite hard to apply concepts to other use cases and problems, and it can be frustrating to not know how and why everything is working. The author explains his point of view at the early beginning of the book: it aims to be at the middle of this large scale, wants to cover most relevant problematic in a generic fashion but avoids diving too deep into low-level maths. What a challenge!

Clojure

What about Clojure content? I'm still considering myself as a Clojure beginner since I didn't write any large program nor solved really hard issues. Even if I deeply know and understand all the concepts individually, it remains not-so-easy to gather all of them and think everything in a perfect Clojure's style when I have to solve real life problems. Until now I mostly played with Machine Learning algorithms using GNU Octave or Python. This books looks perfect in this dimension! The author provides clear Clojure code, assuming you already know Clojure fundamentals and giving relevant notes for lines that deserve further explanations.

Clojure for Machine Learning

Mixing these 2 axis together, you get this book. At first sight I was surprised to not see any reference to Incanter project. You just have to wait and keep reading, then this book will transform into a nice Incanter introduction. However, I had the feeling the author didn't want to speak too much about Incanter but he had to anyway (just a personal feeling). I think it would make sense to explicitly introduce this amazing project and would't mean that the book was 100% single-library oriented.

The first part I really liked within the first chapters was the nice introduction to available frameworks to deal with matrices (and not Incanter!). It calls into question how I considered matrices in Clojure so far. I just regret some figures are missing but it highly motivates me to write these benchmarks.

Another point I realized is the strange overall organization of this book. Despite the table of content makes it very clear, I think the author is doing strong shortcuts, bypassing some important concepts; on the other hand he supplies long and deep details about some fundamentals (mostly about ML, not really about Clojure). Make your choice: there is too much theory or not enough theory.

Worth reading?

To be honest, I don't know. I guess it depends who you are, and what you'll expect from this book. The best I can do is give this classical overview as pros/cons list.

Pros:

  • Nice introduction to LOTS OF concepts
  • Pragmatic, real-life oriented
  • Well-balanced required Clojure's skill
  • Fair level of details overall

Cons:

  • Lack of fundamentals / academic stuff
  • Lack of summarized explanations
  • No real Incanter introduction
  • Not enough organized

Thursday, May 1, 2014

Emacs, clojure/cider mode: boring autofocus...

Today, – labor day – I've fine tuned my Emacs setup which hasn't evolved for a while. Digging into emacs24 packages, testing rainbow-delimiters, customizing company-mode, etc. As a Clojure beginner, I'm discovering joy of programming lisp-languages within my favorite $EDITOR as well.

Then I've played with CIDER, a Clojure IDE and REPL for Emacs. As expected you can benefit form REPL model directly, plus many additional features, such as stacktraces analysis. One of my favorite feature is to get shortcut (C-c C-d in my case) to display the documentation of an input function.


The problem was that CIDER always decided to automatically move the focus to the attached buffer. This leads into boring keyboard combinations to switch back to the original buffer, even smart shortcuts such as C-<up> won't satisfy myself. There are configuration options to annihilate this behavior when throwing an error or the REPL prompts, but I didn't find anything when accessing the documentation.

And here comes the patch! If you're annoyed by this behavior, feel free to patch your setup:

diff --git a/emacs/emacs.d/elpa/cider-0.5.0/cider-interaction.el b/emacs/emacs.d/elpa/cider-0.5.0/cider-interaction.el
index 8f4b8cb..8bcccbf 100644
--- a/emacs/emacs.d/elpa/cider-0.5.0/cider-interaction.el
+++ b/emacs/emacs.d/elpa/cider-0.5.0/cider-interaction.el
@@ -1153,7 +1153,7 @@ if there is no symbol at point, or if QUERY is non-nil."
 (defun cider-doc-handler (symbol)
   "Create a handler to lookup documentation for SYMBOL."
   (let ((form (format "(clojure.repl/doc %s)" symbol))
-        (doc-buffer (cider-popup-buffer cider-doc-buffer t)))
+        (doc-buffer (cider-popup-buffer cider-doc-buffer nil)))
     (cider-tooling-eval form
                         (cider-popup-eval-out-handler doc-buffer)
                         nrepl-buffer-ns)))

Of course, you may create your own variable to customize focus strategy, but I've never seen a very long documentation which could justify moving focus to another buffer.