numeric minimization in Haskell

Does anyone know of any Haskell code for numeric minimization? I was thinking conjugate gradient would be good, but at this point I'd be happy with anything. I've found some code written by Tomasz Cholewo at http://ci.uofl.edu/tom/software/Haskell/ but it requires importing his "Arr.lhs" library, which is not publicly available. The only other thing I've been able to dig up is this www.st.cs.ru.nl/papers/1997/serp97-cgfunctional.ps.gz which suggests Haskell is slow for such problems. I suspect this was an implementation issue, so I don't think their code would be very helpful (though it would be nice to tidy it up and demonstrate the improvement - could it beat the Clean implementation they give?) The other possibility I was considering was using Alberto Ruiz's wrapper for the GSL library http://dis.um.es/~alberto/GSLHaskell/ The only problems with this are (1) requires having GSL available, so it's not as portable, and (2) does everything in terms of lists, which requires a lot of translations to and from lists (I'm using mutable arrays). If there's nothing already written that works together, one of these should give me a start, but I'd like to avoid reinventing the wheel if possible. Thanks! -- Chad Scherrer "Time flies like an arrow; fruit flies like a banana" -- Groucho Marx

On Wed, Feb 28, 2007 at 10:58:30AM -0800, Chad Scherrer wrote:
Does anyone know of any Haskell code for numeric minimization? I was thinking conjugate gradient would be good, but at this point I'd be happy with anything.
Conjugate gradients shouldn't require more than about five lines of code (which I don't have time to write at the moment), apart from array code for the vectors you wish to minimize. I'd recommend considering GHC.PArr, if you don't need more than just minimization. If you include {-# OPTIONS -fparr -fglasgow-exts #-} at the top of your file, you'll also get a fancy array syntax. Manuel is currently working on parallelization of arrays using this API, so this would be a good API to use, moving forward. -- David Roundy Department of Physics Oregon State University

G'day all.
Quoting David Roundy
Conjugate gradients shouldn't require more than about five lines of code (which I don't have time to write at the moment), apart from array code for the vectors you wish to minimize.
I apologise for the quality of the code, but here's an implementation of the Marquardt-Levenberg algorithm (which is actually a smooth interpolation between the conjugate gradient and Newton-Raphson methods), which I had to do a year or so ago: http://andrew.bromage.org/darcs/misc/Marquardt.hs It even includes code to compute standard errors on the parameters. Cheers, Andrew Bromage

GSL is written in C, and I don't know any language more portable than that! gsl_vector and gsl_matrix use a continuous block of doubles, so you can use the FFI to marshall this however you want for efficiency. I'd stick with GSLHaskell until you're ready to optimize the data marshalling though. I like spending my time on interesting things, not reinventing pre-debugged and efficient libraries. I use GSLHaskell in my work and have never had a problem. Dan Chad Scherrer wrote:
Does anyone know of any Haskell code for numeric minimization? I was thinking conjugate gradient would be good, but at this point I'd be happy with anything.
I've found some code written by Tomasz Cholewo at http://ci.uofl.edu/tom/software/Haskell/ but it requires importing his "Arr.lhs" library, which is not publicly available.
The only other thing I've been able to dig up is this www.st.cs.ru.nl/papers/1997/serp97-cgfunctional.ps.gz which suggests Haskell is slow for such problems. I suspect this was an implementation issue, so I don't think their code would be very helpful (though it would be nice to tidy it up and demonstrate the improvement - could it beat the Clean implementation they give?)
The other possibility I was considering was using Alberto Ruiz's wrapper for the GSL library http://dis.um.es/~alberto/GSLHaskell/ The only problems with this are (1) requires having GSL available, so it's not as portable, and (2) does everything in terms of lists, which requires a lot of translations to and from lists (I'm using mutable arrays).
If there's nothing already written that works together, one of these should give me a start, but I'd like to avoid reinventing the wheel if possible.
Thanks!

On 2/28/07, Dan Weston
I like spending my time on interesting things, not reinventing pre-debugged and efficient libraries. I use GSLHaskell in my work and have never had a problem.
Did I just read an admission that Sony Imageworks use Haskell for movie post-production? -- Dan

Did I just read an admission that Sony Imageworks use Haskell for movie post-production?
Nice try, but I do not speak for Sony Pictures Imageworks. Whatever things they do or do not do in post-production would no doubt fall under some kind of trade secret thing and I would not mention them here. Kudos to you for knowing that Imageworks is a part of Sony. You must be an industrial spy! Even so, you are inferring more than I implied. By "in my work", I mean specifically that I use Haskell (and GSLHaskell) to develop algorithms, prototype them, then validate the results of production code written in C++ (and GSL). As such, I couldn't care less about efficiency in Haskell. I realize that this way of doing things may be considered "impure" to hardcore Haskellers. My full comment was actually:
GSL is written in C, and I don't know any language more portable than that! gsl_vector and gsl_matrix use a continuous block of doubles, so you can use the FFI to marshall this however you want for efficiency.
I know it's heresy on this list to treat Haskell like a wrapper over C/C++, but my experience shows that it has a lot of advantages, even if the final product is code in another language! This is the only argument for using Haskell "in the real world" that I have found has any traction with management, so I hope people don't disdain it while waiting for the day when the benefits of Haskell will be apparent to all. Dan Dan Piponi wrote:
On 2/28/07, Dan Weston
wrote: I like spending my time on interesting things, not reinventing pre-debugged and efficient libraries. I use GSLHaskell in my work and have never had a problem.
Did I just read an admission that Sony Imageworks use Haskell for movie post-production? -- Dan _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 2/28/07, Dan Weston
GSL is written in C, and I don't know any language more portable than that! gsl_vector and gsl_matrix use a continuous block of doubles, so you can use the FFI to marshall this however you want for efficiency.
I'd stick with GSLHaskell until you're ready to optimize the data marshalling though.
I like spending my time on interesting things, not reinventing pre-debugged and efficient libraries. I use GSLHaskell in my work and have never had a problem.
Dan
That's my preference, too. Have you ever tried GSLHaskell on MS Windows? I do most of my work on Linux, but a guy I'm working with uses MS, and I've heard cygwin can be a huge pain. I have a big space leak right now I thought might be because of list laziness in the interface, but that should be squashable with a little work, and is not as big a deal as having lots of dependencies when passing code around. I only really need one function from GSL, and the odds of someone having written a work-alike in Haskell seemed pretty good. Of course, in cases where GSL is already installed, or where more of its functionality is needed, GSLHaskell is the obvious choice. Chad

On Wed, Feb 28, 2007 at 02:54:06PM -0800, Dan Weston wrote:
GSL is written in C, and I don't know any language more portable than that! gsl_vector and gsl_matrix use a continuous block of doubles, so you can use the FFI to marshall this however you want for efficiency.
I'd stick with GSLHaskell until you're ready to optimize the data marshalling though.
I like spending my time on interesting things, not reinventing pre-debugged and efficient libraries. I use GSLHaskell in my work and have never had a problem.
It seems like GSLHaskell is an awfully big stick, when all you need are scalar multiply and vector addition. Of course, we don't know what functions he wants to minimize, but in the absence of any need for GSL functions, I don't see a good reason for it. I see that GSLHaskell has a binding to a conjugate gradients minimizer, but it's not useful for any hard problems (it stores the trajectory, which defeats the purpose of using conjugate gradients), and can only be very, very slow.
From the API alone it cannot be efficient. Code that is written by people who obviously either don't know or don't care about efficiency is just not in general a good idea. I don't know what you use GSLHaskell for in your work, but I hope you don't use it for conjugate gradients, or only use it on easy problems. -- David Roundy Department of Physics Oregon State University
participants (5)
-
ajb@spamcop.net
-
Chad Scherrer
-
Dan Piponi
-
Dan Weston
-
David Roundy