Thursday, June 26, 2008

changes in cl-cairo2

Johann Korndoerfer kindly submitted a patch that adds patterns to cl-cairo2, and also includes some code cleanup. Here is the example Johann contributed to the tutorial, a rainbow created with patterns: Thanks for the nice work, Johann! I am happy that others also find cl-cairo2 useful. cl-cairo2 still suffers from the elusive floating point bug (possibly in libcairo), I am still working on that. In the meantime, you can work around that by not generating PS files directly, but converting them from PDF or SVG files. Since common-lisp.net appears to be down, I took the opportunity to migrate the repository to git, which I am now hosting on my webpage. I find git to be much more convenient than SVN, especially when it comes to ease of distribution. As before, the package remains ASDF-installable. Update: the GIT repository is here, but can also be found from the cliki page for cl-cairo2.

announcement: minpack package

I have been using a simple solver (based on Broyden's method) to finds roots of systems of nonlinear equation, but I encountered an ill-behaving class of problems that required heavier artillery. Numerical methods have made a lot of progress in the last 50 years. Methods presented in introductory textbooks are quite straightforward and very simple to code, but do not cut the mustard when it comes to more difficult situations (eg when you don't have a good initial guess, your function looks like the fjords of Norway, etc). State of the art methods are powerful, but they are tricky to program: the main idea is easy to grasp, but one has to cover a lot of special cases (eg line-search, niceties of trust-region methods) so implementing them from scratch takes a lot of time (and debugging). This is why most researchers rely on Fortran (or most recently, C) packages of these methods. Common Lisp users generally have two alternatives if they don't want to implement these methods from scratch. They can use the foreign code directly via the FFI, or translate the code using f2cl, which is available as part of CLOCC. I found the second option more appealing, for the following reasons:
  • fewer dependencies (no need to install/compile foreign libraries)
  • no need to have callbacks (which are a pain in the neck)
  • better integration into Lisp (eg you can use the condition system)
This is the first time I used f2cl, but it was quite easy to do, especially as CLOCC already has things set up for MINPACK. I think that translating from Fortran is the way to go for some libraries, even though I recognize that for libraries like LAPACK where pure performance matters, FFI is the better option, especially as the functions there have simpler interfaces and don't need callbacks and complex condition handling. MINPACK has already been available as part of CLOCC, but I had a hard time getting the whole thing work in SBCL, and it doesn't use ASDF, so I decided to package it to make it self-contained and ASDF-installable. The extended version of the project I am working on will probably need homotopy methods, and I am looking forward to packaging that too.

Saturday, January 12, 2008

announcement: cl-sparsematrix

Lately I have been working on algorithms that solve Hamilton-Bellman-Jacobi equations (that describe optimal control problems in continuous time) using the methods of Kushner and Dupuis, which involve sparse stochastic matrices. The sparse matrix code has stabilized to the point that I cleaned it up today and decided to make it available as a library, in ASDF-installable form. The package is called cl-sparsematrix, and has the following features:
  • generalized sparse matrices: elements don't have to be numbers, but can be any object (eg functions for parametrized sparse matrices), of course you have to define what you mean by zero in this case
  • utility functions for creating, mapping, traversing or copying sparse matrices
  • numerical operations that make sense for numerical sparse matrices (elementwise addition, subtraction and multiplication, row and column sums, multiplication of rows by corresponding elements in a vector, vector-matrix and matrix-vector products)
  • a simple interface for UMFpack for solving sparse systems (uses cffi and ffa)
You will find an introduction to the main concepts in the code as a PDF file in the documentation/ directory. As usual, comments and suggestions are appreciated.