junk5
2/1/2006 2:53:00 PM
Hi Darren
> I'm looking at Ruby for scripting/programming of scientific computing
> for neuroimaging.
I used Matlab for my PhD research (medical image modelling and
analysis), and I think it was excellent for my purposes. Below is a
list of why I liked using it, which I'll compare to my (limited)
experience with Ruby afterwards:
1. Matlab language syntax maps closely to the underlying concepts (i.e.
vector and matrices).
2. Very simple, but powerful, plotting/visualisation abilities.
3. (Generally) efficient implementations for common matrix operations
(multiplication, decompositions etc.). These are very well-tested.
4. A REPL (i.e. you can experiment on a 'command line').
5. Cross-platform (Linux, OS X, Solaris, Windows).
6. No compiling (recent Matlabs do just-in-time compilation
automatically).
7. Excellent support for profiling (easily find and quantify those
computational hot-spots).
8. It's easy to write C (or FORTRAN) extensions when you really need
every last ounce of speed or control over memory.
9. Lots of other people use it, so there's an 'ecosystem' (the users
are also working on your problem or closely-related ones).
Comparing this to Ruby:
1. Ruby is high-level, but it's a general purpose language; it's not
specialised for vectors and matrices. You'd have to get a library or
write this yourself. The Ruby syntax is 'sort-of' similar to the Matlab
syntax, though. Well, it feels Matlab-y to me!
2. You'd need to write or find plotting/visualisation library for Ruby.
I've not looked, but I'd hope this is reasonably trivial.
3. You'd need to find or write a library to let you do efficient matrix
computations. I know there is stuff for Ruby out there, but it won't be
as well-tested as Matlab's and it's not a first class citizen of the
environment. Writing your own is much harder than it seems. You really
need a library that allows you to call LAPACK routines from Ruby.
4. Ruby has the irb REPL. This is fine.
5. Ruby seems to be pretty cross-platform, but you'd need to check the
same is true for the additional libraries you'd need. You might not
care about WIndows, but what about your colleagues? You often need to
share code with them.
6. No compiling, but also no JIT as far as I'm aware. Not too big an
issue if you've got a good matrix library.
7. I've not tried profiling in Ruby, but Matlab's profiler is very
good. If you can't profile your code and you're doing numerics, you're
in trouble.
8. I understand you can write Ruby extensions in C but I've not done
it.
9. The ecosystem for your problem domain is going to be much smaller in
Ruby than in Matlab. Ruby's best ecosystem domain seems to be webapps
(i.e. Rails).
Now, the thing I haven't mentioned is price. Matlab is expensive
(thousands of dollars for all the stuff you need). They do student
discounts, but last time I looked you'd need to pay hundreds of dollars
rather than thousands, so it's not a great discount. (Mathematica's
student terms were much better, last time I looked.)
Ruby is free. In my opinion, if you can afford Matlab (or someone else
is affording it for you), you should have a very good reason before you
ditch Matlab. However, if you can't afford Matlab, or have ideological
reasons why you don't want to use it (it's not open source, for
example), you should probably use and improve Octave, the open source
equivalent to Matlab. However, if you need to roll your own soluation,
I think Ruby would make a very good foundation for putting together
your own environment for numerical computing.
I think the real question is whether you want to do the 'fun' thing and
start (almost) from scratch (i.e. base your environment on Ruby) or
stand on the shoulders of giants (i.e. use Matlab or Octave). If you've
got real problems to solve now, you should probably resist the
temptation to do the fun thing.
Chris