Thursday, December 3, 2009

Common Lisp v. Python

So, I've recently implemented a neural network in both Python and Common Lisp. On a network with 2 input nodes, 10 hidden nodes (in one layer) and 1 output node, my python implementation was capable of running approximately 10 training epochs in one second (on 500 training data points).

This was not nearly fast enough. This was being done for an assignment, and we were told to implement multiple weight learning algorithms, each one was to be run for 2 million epochs!

I reimplemented the network in common lisp, and initially got approximately the same performance (20 epochs/sec), but by adding type information and declaring (optimize (speed 3)) in a few key functions and inlining a few others, I magically got 10 times the performance. Finding which functions were "key" was an absolute snap using SBCL. In the past, I have found it painful to profile code in other languages (including Python).

Common Lisp is amazing. In the past I was a massive fanboy of the language, but its dearth of libraries has caused me to slide back towards Python. This recent experience has recharged my love for lisp.

Hi!

It's been too long since I've posted anything here.