The MATLAB handcuff

The first computer language I learned was BASIC back in the stone age, which led directly to Fortran. These are procedural languages that allow the infamous GOTO statement, now shunned by the computer literati. Programming with the GOTO gives you an appreciation for why the Halting problem is undecidable.  Much of what I did in those days was to track down infinite loops. I was introduced to structured programming in university, where I learned Pascal. I didn’t really know what structured programming meant except that I no longer could use GOTO and there were data structures like records. I was forced to use APL at a summer job. I have little recollection of the language except that it was extremely terse and symbolic. It was fun to try to construct the shortest program possible to do the task. The ultimate program was the so-called “APL one liner”. APL gave me first hand experience of the noncomputability of Kolmogorov complexity. In graduate school I went back to Fortran, which was the default language to do scientific computing at that time. I also used the computer algebra system called Macsyma, which was much better than Mathematica. I used it to do Taylor expansions and perturbation theory. I was introduced to C and C++ in my first postdoc. That was an eye-opening experience as I never really understood how a computer worked until I programmed in C. Pointer arithmetic was a revelation. I now had such control and power. C++ was the opposite of C for me. Object oriented programming takes you very far away from the workings of a computer. I basically programmed exclusively in C for a decade – just C and XPP, which was a real game changer. I had no need for anything else until I got to NIH. It was only then that I finally sat down and programmed in MATLAB. I had resisted up to that point and still feel like it is cheating but I now almost do all of my programming in MATLAB, with a smattering of R and XPP of course. I’m also biased against MATLAB because it gave a wrong answer in a previous version. At first, I programmed in MATLAB as I would in C or Fortran but when it came down to writing the codes to estimate heritability directly from GWAS (see here), the matrix manipulating capabilities of MATLAB really became useful. I also learned that statistics is basically applied linear algebra. Now, when I code I think instinctively in matrix terms and it is very hard for me to go back to programming in C. (Although I did learn Objective C recently to write an iPhone App to predict body weight. But that was mostly point-and-click and programming by trial and error. The App does work though (download it here). I did that because I wanted to get a sense of what real programmers actually do.) My goal is to switch from MATLAB to Python and not rely on proprietary software. I encourage my fellows to use Python instead of MATLAB because it will be a cinch to learn MATLAB later if they already know Python. The really big barrier for me for all languages is to learn the ancillary stuff like what do you actually type to run programs, how does Python know where programs are, how do you read in data, how do you plot graphs, etc? In MATLAB, I just click on an icon and everything is there. I keep saying that I will uncuff myself from MATLAB one day and maybe this is the year that I actually do.

Advertisements

11 thoughts on “The MATLAB handcuff

  1. Hi Carson,

    In the spirit of your post being autobiographical, a light-hearted Psych 101 analysis and pep talk seems in order. Briefly: you should just do it already (and write about your experience)!

    In your post, it’s interesting that you don’t sound like you’ve really committed to your goal of transitioning although you advocate others to start with Python. It sounds like maybe you’re setting up some cognitive dissonance through a medium of “public accountability” to help motivate you. I’m sure there’s some proper psych term for this but I can’t think of it….

    The scientific python community has worked very hard in the past 10 years to improve the coherence of the scientific toolset. Admittedly, as a collection of first and third party components, it’s probably never going to be as unified as MATLAB can be. But the ancillary stuff you mention is a short-term problem to overcome, and for someone with your computing experience it will not be a challenge. I think we all tend to exaggerate how hard a major transition will be, and I think your barriers are much more cognitive than technical. For instance:

    There are many tutorials and resources now to help transition former MATLAB users. For instance, the Matplotlib library was specifically designed to mimic MATLAB’s graphing interface, so basic plotting syntax is almost trivial to learn. The popular “numpy for matlab users” guide is a comprehensive quick reference for re-adjusting your mindset to the different syntax, 0 vs 1 first array index rule, etc. The cookbook recipes and stackoverflow pages are rife with off-the-shelf examples for all the basics, like data I/O. It has never been so easy to teach yourself! Data visualziation and stats-oriented packages like Pandas have revolutionized simple access to python-based tools that previously only existed in R or commercial GUI environments. There are great parallel processing tools available, although nothing quite like Simulink yet. If you insist, you can still run XPP using a python interface that my old Matlab-XPP interface apparently inspired. But really, of course, you should use my PyDSTool for anything seriously involving dynamical systems :)

    *If* you install things from scratch then there are a couple of fussy PATH settings, etc., to fix, but that’s no different from everyday UNIX usage. The installer bundles like Enthought Edition and Python(x,y) take care of all of that until you need to tweak some internal settings one day with a new library you want to add.

    The only annoying issue, in my opinion, is choosing an IDE setup that suits you. I admit there are (too) many to choose from, but several are very good and so it’s not that big a deal.

    Running programs couldn’t be easier. In the IPython shell: “run myprog.py” or “python myprog.py” from your OS shell. In most IDEs you can run the programs exactly like you would in MATLAB, from a drop-down menu or keyboard shortcut.

    What’s more exciting — and maybe more daunting — are the endless opportunities to improve and expand your scientific workflow beyond what is possible (or at least native) in MATLAB. The python world is so much more integrated with other computing capabilities. For instance: 1) the variety of “literate programming” tools and environments for python-based simulation and modeling. E.g., Sumatra, pypet, dexy, lancet, IPython notebook, Pweave, PyLit; 2) the easy access to data and doc standards like json, XML, tools like github, and browser-based environments like Django for interfacing with DBs and apps online.

    Now _those_ might be a reason to pause and wonder what Pandora’s box you’ll be opening! But it would provide ample blog material, and you should write about your experience here and provide feedback on the existing educational materials. I know they can be stand to be improved. I’m expecting to start a blog this year on learning and using those tools I just mentioned.

    Cheers,
    Rob

    Like

  2. Mark and I took 6.00x through edX.org, which uses Python. The professor gave a series of lectures on plotting w/ Matplotlib in the middle of the course. For some of the homework sets, the TAs gave out test suites we could run locally before uploading our programs for grading. Those test code scripts taught me a great deal about Python workflow.

    The class just started up again and I highly recommend it.

    Like

  3. To be clear, you view the MATLAB handcuffs as the application’s “matrix manipulating capabilities” and ease of use?

    Like

  4. @Jeremy That and the fact that I can also easily load data files, make plots, do statistical analysis, and so forth without thinking. Mathworks has done a good job making Matlab a complete environment so you never really need to use anything else.

    Like

  5. So, why choose to re-invent the wheel? Matlab is practically open-source now with the $50 Home/Student edition. Is your goal primarily to satisfy an academic itch? Rather than focusing on how computer languages work, wouldn’t it be more rewarding to solve tough math problems easier with a higher-level programming language?

    Just my 2-cents :)

    Like

  6. @Jeremy It is still not open source and quite costly for my lab. The lack of open source has been an issue when we have tried to distribute our codes used in research projects. Also, while Matlab is fast for matrix manipulations, it is still too slow for loops to do fast simulations of large dynamical systems.

    Like

  7. Correct, Matlab with loops can be slow for simulations. Have you looked into using Simulink for modeling your dynamical systems? Of course, I understand this would not be open source either if that is a major concern for your lab.

    Like

  8. IDL is slow to loop, too.
    However, you can easily rewrite it as vectorized IDL to eliminate loops. Does Matlab also do the same?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s