Saturday, June 2, 2012

Pull back on the reins

I use Matlab for my research and teaching at Waterloo.  However, AIMS encourages the use of open-source software, and that's not Matlab.

The students have been learning SciPy, a python-based scientific programming language. I decided I would use that for my computational neuroscience course. I've been wanting to learn Python for a while, anyway.

Over the past few months, I've been working on converting my basic neuroscience code from Matlab to SciPy. It's not easy. The hardest part is that in Matlab the basic data type is the matrix. But in SciPy there are different, but similar, data types. For example, if I create an array with 2 rows and 3 columns, I can store it as an "ndarray", or a "matrix". The problem is that how you can use the data depends on which type it's stored as. In particular, a plot can look totally different, even though the underlying data is the same... the data type can drastically alter how the data is interpreted. I find that annoying.

On the first day of lectures here, the instructor of the other course, Raouf Ghomrasni, said he is going to use Scilab. He said it's a free Matlab work-alike... I immediately started salivating.

Later that day, I downloaded Scilab, and found it to be excellent. In in that few hours of exposure, I decided to abandon all my SciPy preparation, and instead teach the course using Scilab.

I must admit, I feel a bit bad for the students. They know SciPy, and yet we're thrusting ANOTHER language on them. But I can make myself feel better when I consider that:
  1. Matlab is one of the most common scientific programming languages, so learning it would be an asset to these budding scientists.
  2. The students would likely stumble over the same SciPy ndarray/matrix issues I was having.
  3. Using Scilab will save me a lot of time in the long run. I'll be teaching a course on computational neuroscience at Waterloo in the fall, and I'll use Matlab for that. Investing in a Matlab-like language now will transfer more easily to that course.
So there.


  1. This comment has been removed by the author.

  2. (posted on behalf of Jan Groenewald)

    You have raised one of my favourite topics ;) I'm not sure what the title of the post implies though?

    Disclaimer: I'm the guy pushing the Free/Libre software for Science at AIMS.

    This article in Nature agrees with the general principle.

    Here is some background on Free Software for Science, and it's use at AIMS.

    Note Scilab had some restrictions, on redistributing modified copies (which is why we historically preferred Octave, another Matlab compatible package. By the time Scilab's license improved, we had already moved to SciPy (and now Sage). Matlab, Octave, and Scilab historically have different strengths in their respective "toolboxes" or "plugins". However, at a masters level you often cannot tell the difference, as advanced features are not used.

    Octave has a full GPL license and a special compatibility modes for Matlab too Often porting code Matlab to Octave requires only changing end to endif and endwhile. Sometimes it was not possible or easy to port ODE related code, as the functions were called differently. I haven't ported code for years, because we simply rewrite in SciPy or Sage now.

    A useful for the newly converted, or users of both syntaxes, is the SciPy Cookbook
    Matplotlib Gallery.

    Addressing your original points:

    1. Google trends comparing Matlab and Python. OK, that's not SciPy, and Python is a general purpose programming languages. But that is one of its strengths. SciPy skills are also an asset, and some would argue a bigger asset due to it's license and growing community. I don't refute Matlab's value for going into traditional academic departments or engineering jobs. But none of us are using punch cards anymore, and it was probably a valuable skill for some mathematicians at some point.

    2. Maybe this explanation on differences between arrays and matrices from the SciPy FAQ will help. I find it useful being able to do both element-wise and matrix operations.

    3. I respectfully disagree. Using Scilab will save you a lot of time on the *short* run. Using SciPy will be a good investment in the long run, but it will take more time to convert existing code and exercises at the moment. Migrating to SciPy during a 3-week-long course is hard, but on the long run being able to publish and scrutinize all code, saving money, and being able to redistribute and contribute back is priceless.

    More about Sage:

    Sage or Sagemath is a python-based front-end to many Free/Libre packages for numerical and symbolic computations, aiming to create a viable free open source alternative to Magma, Maple, Mathematica and Matlab.

    Also, you can still run legacy Matlab code behind the Sage interface:
    (and Mathematica, Maple, and Magma)

    Have a look at this positive experience migrating from Matlab to Sage.

    More Sage success stories.

    So there?

    Jan Groenewald
    (AIMS IT Manager)