2014/11/23

Reading Notes: For the Bankers, the Neuroscientists, the Physicians, etc.

"It is difficult to get a man to understand something, when his salary depends upon his not understanding it!" ---Upton Sinclair

2014/08/08

Mathematica for the Neuroscientist (0): Introduction

We are facing another turning point in neuroscientific computing, where the ~10 year reign of MatLab is coming to a close. A large number of people with an eye to the future are moving towards Python.
MatLab was, for better or for worse, the first package which made basic data analysis relatively simple for many neuroscientists without a programming background. The loose syntax and ease of doing simple stuff, however, actually makes intermediate and advanced programming extremely difficult.
Here are some reasons for the recent shift away from MatLab:
  • the 1970's ish scripting syntax for MatLab is showing its age more than ever, and there are an increasing number of things that you just can't do effectively. Important paradigms such as parallel computing and pattern matching, and accepted modern programming practices such as unit testing are virtually impossible to do properly, given the loose syntax.  
  • the cost and pricing... nothing can beat free (i.e. Python)
  • There haven't been any fundamental advances in the MatLab package for the last 5 years, despite the price you pay---basically, there have only been bugfixes and incremental tweaks. (Indeed, this post from 5 years ago is still rather valid; MatLab's progress cannot even start to compare with progress in the standard Mathematica package, even with one version change.)



There are more than enough neuroscience Python fanboys on the web. Here, I'd like to provide an alternate counterpoint: Mathematica. I am a Mathematica fan, and have been since I started with it almost 2 decades ago. My opinions are based on a very solid amateur programming background, but they are colored by my decades-long excitment at the elegance of Mathematica. Furthermore, Mathematica has always allowed even relatively casual hobbists to stay at the forefront of modern data concepts (e.g. network analysis) and programming methods (e.g. parallel/distributed computing).

Of the languages I have experience with (LOGO, Pascal, C++, Java, Mathematica, Matlab, Labview, Scala) or have dabbled with (Python, JavaScript, Visual Basic, C, etc.), Mathematica offers a certain sweet spot for scientific computing in general. I predict that this situation will continue for at least another decade.

My overarching goal in this series, therefore, is to present why I as a neuroscientist and scientific programmer, favor Mathematica hands down. I will try to do this through concrete Neuroscience-related examples which show how Mathematica can help you to analyze your data, effectively and simply.



There are quite a few things that are really easy with the standard Mathematica package, and for this introductory post, I'll give you some examples which may or may not be directly relevant to neurophysiology:

Image Analysis

See this standard example on how you can create a function to discriminate handwritten digits, and then apply that image classifier function to new exemplars.
Untitled-1

There are quite a few GPU-accelerated functions for image analysis in the standard package (no add-ons necessary): everything from regular stuff like deconvolution, sharpening, etc, to cool stuff like face detection, and advanced functions like 3D image segmentation.

This is a good illustration of how powerful the standard Mathematica package is. Especially if you are used to the MatLab business model, you will be surpised that everything is available in the standard package! If you are used to the Python environment, you might be surprised that all of this functionality is curated in a coherent form by Wolfram Research, and you don't have to pick through a hodgepodge of different open-source packages of varying quality and different syntax.

You just do the analysis you want.


Network Analysis

Untitled-1
This is a good illustration of the simple/flexible data structures that are possible in Mathematica, and how it has allowed newer analysis methods to be incorporated seamlessly into the main language.


Curated Databases

Mathematica has had some pretty impressive curated databases. For example, chemistry...
Untitled-1
Or geography...
Untitled-1

While these aren't directly relevant for neurophysiology at all, they are occasionally very entertaining to play around with.


Other Examples

For more examples, see the Wolfram demonstrations project.



In the next post, I'll start with basics by discussing the notebook interface.

2011/11/26

Hypotheses are obliged to be interesting

"You'll reply that reality hasn't the least obligation to be interesting. And I'll answer you that reality may avoid that obligation but that hypotheses may not."

---Borges as quoted by Oliver Sacks "Migraine" Ch. 10

2011/11/18

On Enjoying Science

"I am stupid enough to always think that the idea I have at the moment is going to work out, and this is really lucky..." "It saves me a lot of anguish, but more important, by the time I realize that it does not work, it has led to another idea which of course is going to work. At the end of this recursive process there is indeed something which works, which generally has nothing to do with the original idea, but who cares? So I am always trying to explain to students that they should generate enough enthusiasm to persuade themselves that it will work and it will indeed, at some point."

--- Stéphane Mallat, as quoted in "The World According to Wavelets: The Story of a Mathematical Technique in the Making " (Chapter 3, p. 39)

2011/10/12

Information and Knowledge

"Medicine has entered an era when the acuity of illness and the limited time available to evaluate a patient have diminished the ability of physicians to satisfy their intellectual curiosity. As a result, the acquisition of information, quite easily achieved in this era, is often confused with knowledge."

 ---Preface, Cecil Medicine 24e

2010/10/13

A bunch of candy-ass PhDs, who know more and more about less and less

The old hunters cum wardens cum camp managers, in turn, seem to loathe the zoologists, as a general rule. I suspect we represent a final affront, the domestication of their Africa. The are old tough Brits who were there at the beginning, didn't have much schooling, and learned about the bush from the bush, understanding the big picture. We, in turn, are generally young Americans, already a strike against us, from impossible places like Ann Arbor or Queens. We come out there and try to turn their bush into equations about vegetation, or talk about ecosystems and niches, for god's sake. We spend only short periods there (i.e., less than the hunter's lifetime) and study tiny slivers---how one species of plant pollinates, how some disease moves through ungulates, how many acres of land is needed for a whatever to survive. We're a bunch of candy-ass PhDs who know more and more about less and less and barely know how to wipe our noses when it comes to the bush. All probably true.

= Robert Sapolsky, A Primate's Memoir
(on zoologists doing fieldwork in Africa, even more applicable to the dominant reductionistic trend in Neuroscience perhaps)

2009/06/29

There will be no heroes

It’s fair to say that there will be no heroes... Heroism requires understanding the person in the absolute best light. I’m not sure this is good. What was Barack Obama like in elementary school? ‘Oh, yeah, here’s a picture of him picking his nose. God, he’s no longer a hero.’

--Google CEO Eric Schmidt on the influence of pervasive information (NY Times)

2009/06/21

Forgetting and Nonsequiturs--Not Memory and Ration

... We do something like [computers] with our brains, but we do it differently; we get things wrong. We use information not so much for its own sake as for leading to thoughts that really are unrelated, unconnected, patternless, and sometimes therefore quite new. If the human brain had not posessed this special gift, we would still be sharpening bones, muttering to ourselves, unable to make a poem or even whistle.

These two gifts, the ability to lose information unpredictably and to get relationships wrong, distinguish our brains from any computer I can imagine ever being manufactured. Artificial Intelligence is one thing, and I never spend a day without admiring it, but human intelligence is something else again.

--Lewis Thomas, "The Youngest Science," Chapter 8

2009/02/11

Trasparently Accesing Georgetown eJournals from Home

The following instructions tell you how to access ejournals transparently from home, with your Georgetown University Library account. (e.g. when you access "www.nature.com", you will automatically be redirected to "0-www.nature.com.library.lausys.georgetown.edu" which will serve you the page thru the Georgetown library proxy. You will be asked for your library account and password.)

Of course, you can always go to eJournals from home by accessing http://0-www11.tdnet.com.library.lausys.georgetown.edu/frames.asp, but this can be a hassle.

The redirection method is especially convenient for me, because I read my journal subscriptions through Google Reader. Using this method, I can just click on a feed article from home, and automatically get access to the full text through the library.



1. Install the Firefox addon Redirector (http://addons.mozilla.org/en-US/firefox/addon/5064)

2. Restart Firefox.

3. Go to the Firefox property sheet by typing "about:config" in the address bar.

4. Find the preference key "extensions.redirector.redirects" (you can type "redirector" in the search box).


5. Double click on the key name "extensions.redirector.redirects", and copy the following text into the dialog box. (Instead of copying the key, you can also manually enter all of the redirection values by hand. See instructions at the bottom of the page.)
!!! Updated for Redirector 2.0 on Firefox 3.5 !!!

For older versions


6. Click OK to exit the dialog box. You will now be automatically redirected for most biomedical journals, including www.pubmed.com, common aggregation sites (ScienceDirect, MDConsult, Ebsco, Ovid, Ingenta, Factiva), common society journals (AMA, AAP, PNAS, ), common publishing houses (Nature Prss, OUP, Cambridge, Springer, Wiley, Karger, Thieme), and selected independent biomedical journals.



If you have eJournals which are served by the Georgetown Library proxy but aren't included in the above preprogram, you can go to Tools-Redirector, and manually enter the journal. (With redirector wildcards, the settings "http://*.nejm.org/*" "http://$1.nejm.org.extra.stuff.here/$2" will redirect "http://content.nejm.org/whateverPage" to "http://content.nejm.org.extra.stuff.here/whateverPage"

Another tip when searching from a non-academic IP address for journal articles... The "Link Out" feature can sometimes get you to an article even when the main pdf link says that you have no subscription. Sometimes, an academic institution (i.e. Georgetown, will be subscribing not to the Journal directly but through an aggregator like ScienceDirect or Ebsco, and "Link Out" can get you to the aggregator links.



If this tip is helpful, you can send me a fraction of a cent by surfing some of the page abvertisements!

2008/11/06

An Empty, Vague Notioin of Self-Esteem

For a generation that has no boundaries, no rules, no structure in their life, the military actually has a lot to offer. The military may be the only place in American Society today where they'll... understand what it's like to have self confidence and self control rather than this empty, vague notion of self-esteem. And then they start to become productive."

---Maj. Art Finch, staff psychologist for the 75th Ranger Regiment (The Mercury, Oct. 2008)

He actually has a good point, which is a sad reflection of the state of American Society.

2008/11/02

History repeats... ? A poem by Kurt Tucholsky

Sorry, this was apparently a hoax
A little poem from pre-WWII that predics the present situation... hopefully we don't get to the final stanza this time around...



















Wenn die Börsenkurse fallen,
regt sich Kummer fast bei allen,
aber manche blühen auf:
Ihr Rezept heißt Leerverkauf.
When stock markets fall,
All are moved to grief,
For some the hope remains, however--
Short selling: their relief
Keck verhökern diese Knaben
Dinge, die sie gar nicht haben,
treten selbst den Absturz los,
den sie brauchen - echt famos!
What they do not own,
These bold knaves take and sell,
To start the crash that they require,
Isn't this so swell!
Leichter noch bei solchen Taten
tun sie sich mit Derivaten:
Wenn Papier den Wert frisiert,
wird die Wirkung potenziert.
Easier still than that--
Derivatives, they juggle round,
For when the paper boosts its value,
Benefits compound.
Wenn in Folge Banken krachen,
haben Sparer nichts zu lachen,
und die Hypothek aufs Haus
heißt, Bewohner müssen raus.
If this leads to banks collapsing,
For savers it's no laughing matter.
For the mortage on their houses,
Residents must scatter.
Trifft's hingegen große Banken,
kommt die ganze Welt ins Wanken -
auch die Spekulantenbrut
zittert jetzt um Hab und Gut!
But if this hits the larger banks,
The whole world starts to quake-
In fear for their possessions,
The spawn of gamblers start to shake.
Soll man das System gefährden?
Da muß eingeschritten werden:
Der Gewinn, der bleibt privat,
die Verluste kauft der Staat.
Action must be taken,
We must protect the system's fate--
The profits will be kept in private,
The debts paid by the state.
Dazu braucht der Staat Kredite,
und das bringt erneut Profite,
hat man doch in jenem Land
die Regierung in der Hand.
For this we must have public bonds,
The profits will be so much!
For knaves in every land do have,
The governments in their own clutch.
Für die Zechen dieser Frechen
hat der Kleine Mann zu blechen
und - das ist das Feine ja -
nicht nur in Amerika!
For these rascals' debts,
The little guy must pay,
And -it gets better yet-
Not just in USA!
Und wenn Kurse wieder steigen,
fängt von vorne an der Reigen -
ist halt Umverteilung pur,
stets in eine Richtung nur.
And should the market rise again,
The dance begins anew.
This is simply redistribution,
The direction is just askew.
Aber sollten sich die Massen
das mal nimmer bieten lassen,
ist der Ausweg längst bedacht:
Dann wird bisschen Krieg gemacht.
But if the masses rise,
And will not take it any more,
The solution is quite simple:
We start a little war!


from "Die Weltbühne"(1930) Kurt Tucholsky
(translated by M. Lippert / K. Takagaki)

2008/07/29

Linearity in complex systems

... It turns out that the overwhelming importance of a trigonometric analysis in the treatment of linear phenomena does not persist when we come to consider non-linear phenomena...
N. Wiener, Cybernetics


Neuroscience is faced with the problem of going beyond the first-pass view of the brain, that which emphasizes the selective firing of single units and the spatial alignment of these units within the cortex. Imposing this view on the cortex can often become quite tortuous once one exits the realm of (lower) sensory areas.

Somehow, we must address both the unity of experience, and the fact that neural events are not necessarily repeatable-- in our brains, the same visual scene is never quite the same, it is always colored by ill-defined variables such as our mood, and our previous exposures. There is no a priori reason to assume that an "average" experience exists, but this is the simplifying assumption underlying cortical neurophysiology. On a mechanistic level, neural processes on the mesoscopic scale, which could underlie the unity of experience, are profoundly emergent, nonlinear, and ill-behaved.

But in trying to face these problems, we are limited to using methods developed for linear, time-invariant systems. All the common constructs of neurophysiology--sinusoidal oscillation, superlinear/sublinear summation, statistically significant deviations--these concepts are so ingrained in our mind, that I think it is important to clearly state their limitations. Namely, these concepts are not necessarily meaningful if the measures in question are not well behaved, LTI, repeatable, stochastically distributed around a "true" value, etc.

2008/05/10

Dreams from My Father

Barack Obama on returning to his ancestral homeland in Kenya...
For the first time in my life, I felt the comfort, the firmness of identity that a name might provide, how it culd carry an entire history in other people's memories, so that they might nod and say knowingly, "Oh, you are so and so's son."
     ---Dreams from my father: a story of race and inheritance (Ch. 15)

Having moved constantly while growing up, I sympathize with this profoundly.



Words of a British physician, raised in colonial Kenya, who felt compelled to return to the continent
Once you've lived here for a time, the life in England seems terribly cramped. The British have so much more, but seem to enjoy things less. I felt a foreigner there.
     ---ibid Ch. 16

Somehow, I seem to feel the same way a little, living in Germany and comparing it to the US. Not that Germans are materially poor, but...

2008/04/23

Why I use Mathematica and not Matlab

I have to admit that I am somewhat of a Mathematica partisan.

My first serious use of the computer was Mathematica (except for a very heated PC-Tetris phase--that was pretty serious). My father got me an introductory student license of v2.4 and the Gray/Glynn book, and all through high school, I enjoyed physics by making (what I thought were) cool simulations of whatever motion equations and statistical physics that we learned.

In college, I was a biochemist, without programming. In medical school, I switched to neurophysiology, and picked up Matlab in the process. But whenever I could, I used Mathematica. For my use, Mathematica v5 was just as fast as Matlab, and the graphing capabilities were somewhat superior. At that time, Matlab and Mathematica were mostly equal in functionality, but I preferred Mathematica.




That was then. Now that Mathematica is up to v6, I see no compelling reasons to use Matlab instead of Mathematica, at least in Neurophysiology (except maybe that you and your institution cannot afford a license). Right now, the Mathematica graphics capabilities far surpass anything that Matlab can dream of, and the data crunching is lightning fast (I admit that v2.4 was pretty sluggish sometimes--for me, this hasn't been a problem since v4).

Even if you are working with a large legacy Matlab library, you can phase out by gradually translating parts to Java code (which can be called easily from both Mathematica and Matlab). The improvement in code readability, debugging, productivity and maintenance should pay off in a relatively short time, even for a large switch.

It is true that some Matlab toolbox functions, such as DAQ functionality, are not available in Mathematica--but these toolboxes often have superior counterparts outside of Matlab anyway. (For example with DAQ, LabView is much easier. It just takes some extra glucose upstairs and a few weekends to figure out--but it is well worth the effort in saved time.) Most mathematics/engineering functions are also readily available as open source Java libraries.




Here are my top reasons why I use Mathematica and not Matlab:-

  1. Easy output of high quality graphics... This is definitely my biggest reason to choose Mathematica over Matlab. Mathematica graphics are all vector-based, and even on screen, the smooth rendering is not out of place on a sleek modern operating system. Matlab reeks of Win 3.1.


    What's more, Mathematica graphics are all well-defined vector objects, and therefore Mathematica graphics can be directly output at publication quality to .pdf or .ps, without any hassle. Last time I checked, Matlab graphics output was still struggling with pixels and dpi. This could be a very compelling reason for most physiologists to switch to Mathematica.

    Since Mathematica graphics are well-defined vector objects, it is trivial to combine two plots to come up with a third. All plots can, of course, be serialized by using Save["filename", plot], so that you can reload the same plots later and instantly make new combinations, at full resolution. This may seem trivial, but it's a real time-saver when you're playing around with various plots and trying to figure out how to present your data most effectively.


    There are also some extra benefits to Mathematica graphics. For instance, 3D plots in Mathematica can now be rotated interactively, in situ, by click-dragging. Movies can be exported to Flash movies, which can be easily pasted into powerpoint or a webpage. V6 now also supports alpha blends (Matlab can also do transparency in 3D graphics, but last time I checked, not in regular graphics). The following simple graph, for instance, should be a huge hassle (if not impossible) to make with Matlab.


  2. Mathematica syntax makes sense... Matlab syntax is notoriously incoherent, which is unsurprising given its origin as a DOS hack. Similar functions often take positional arguments in different order. Some functions take arguments as strings, whereas similar functions take the arguments as symbol names, without the ' '. There is even that arcane signature where you put an option name, as a string, and in the next argument, the option value. Naming is also incoherent--for example, to plot a matrix, you use plot(), a verb-name, but to play the data as a sound, you use sound(), a noun-name. I'm probably not the only one who spends way too much time in the Matlab help window, looking up how to call functions and the name of functions, compared to actual work in the main Matlab window... And, bad language design also leads to buggier code.

    In contrast, Mathematica functions which do similar things always take the same arguments, in the same order. Naming is logical, and coherent. So for instance, if you know how to use Plot[] to plot a sin wave, you also know how to use Play[] to hear it. And Mathematica function names are not abbreviated (except for a handful like Sin, Cos, Exp, Log), but spelled out fully. So to get a Chi-square distribution, you type ChiSquareDistribution[] instead of chi2distrib or XsqDistrib or chi2d or whatever. At first, this may seem like a pain because of the extra typing, but the longer function names are usually the less common ones, and this full-name convention actually saves a lot of time, because you need to use the help screen less--even in the more common functions, you don't have to worry at all whether the function you want is num2str or num2string or numtostring, you just type ToString[].

    I read recently that this linguistic coherence is because the creator of Mathematica, Stephen Wolfram, still reviews all new Mathematica syntax for each edition... maybe a guy as smart as this should be doing other things with his time, but if he is willing to put in the effort, I will definitely, gratefully, reap the benefits.

  3. Cross-platform compatibility, version-to-version compatibility... I didn't realize just how bad Matlab was for compatibility, until I had to run a pretty spiffy Matlab GUI (that I'd written on Win) on a Mac. Now that Matlab has a Java core, you would think that cross-platform compatibility would come for free...

    Also, everybody knows of Matlab toolboxes and data analysis packages that don't quite run correctly unless it's on version 7.0.2 (or whatever). One look at some of the internal Matlab functions which are implemented as .m files, and it will be immediately obvious why they have compatibility bugs--the Matlab syntax is definitely NOT designed for readability. What's even scarier is, how many other bugs (or pseudo-bugs) are there that you don't notice, that are screwing your results? And if they themselves can only write such unreadable code, how do they expect end users to use Matlab well?

  4. Cool new features... Check the Wolfram Demonstration site for many examples of how people have used the cool new features of Mathematica. Many of the new features are pretty useless for my day job (biomedical research), but hey, you never know.

    I've been using Mathematica for over a decade now, and the basic structure of the language is as solid as ever. That structural soundness probably allows cool new features to be incorporated without creating balls of spaghetti. I wouldn't be surprised at all if I'm still using essentially the same language for technical computing, another 10 years from now.

  5. Symbolic capacities... This one is not so important for physiologists, but it comes in handy occasionally, and it is the original strength of Mathematica. For a physiologist, it is nice that you can play around with formulae, simplify and symbolically solve differential equations, etc., without digging out your math books and reliving the trauma of high school.

2008/01/31

Eugenics and neurophysiology

...The early literature of eugenics is filled with speculations, and pedigrees laboriously compiled and fudged, about the gene for Wanderlust traced trhough the family lines of naval captains, or the gene for temperament that makes some of us placid and others domineering. We must not be misled by how silly such ideas seem today; they represented orthodox genetics for a brief time, and had a major social impact in America.
---The Mismeasure of Man, Stephen J. Gould (Ch. 5)


The oscillation correlating to consciousness, or to wakefulness, or whatever... far worse yet, the gene for consciousness, etc.

2008/01/26

Attitudes in Computer Use

Just as Google has caused people to have a persistent feeling that pretty much anything can be looked up in a few seconds, habitual Mathematica use causes people to have a persistent feeling that just about anything can be computed, probably before breakfast.

Both are of course only partly true, but what matters is the change in attitude: If you assume you'll be able to find any fact you might need, you soon start reflexively googling things, perhaps even before clearly understanding the question you're trying to answer. And if you assume you'll be able to quickly do any math you need done, you start relying on math more and perhaps doing computations that, upon further reflection, didn't really need to be done.

--Theodore Gray, Co-founder, Wolfram Research


I should step back and figure out why I'm spending so much time at the computer

2007/12/06

Biology... tricks and accidents

I approached Feynman after one of his Cornell lectures in 1964 for advice about how best to move into mathematical biophysics from engineering physics as I had planned when choosing Cornell. He cautioned against any such move, on grounds that biology is too much a matter of tricks and accidents of evolution, and too complex for useful mathematical representations. I believe that that is correct, on average, but the rich diversity of living nature provides many niches for peculiar questions and aptitudes.

---A. T. Winfree (2001) The Geometry of Biological Time


This can probably be said about "useful neurophysiological representations" as well. Most modern neurophysiologists blindly assume that their practice, foundationally based on isolated invertebrate preparations, is universally applicable to the complex neocortical network, during the complex function of cognition. However, this assumption is actually a hypothesis, and one which is not necessarily trivial.

2007/08/18

Strong Inference

To paraphrase an old saying, Beware of the man of one method or one instrument, either experimental or theoretical. He tends to become method-oriented rather than problem-oriented. The method-oriented man is shackled; the problem-oriented man is at least reaching freely toward what is most important. Strong inference redirects a man to problem-orientation, but it requires him to be willing repeatedly to put aside his last methods and teach himself new ones.
--JR Platt (1964) "Strong Inference" Science 146:347-


I do not necessarily agree with the "strong inference" argument, especially at the forefronts of modern biology, where the assumptions going into experimental design (including assumptions related to experimental methods) are so complicated, that conclusive disproval of any "hypothesis" with sufficient aesthetic appeal is usually hard to come by.

This is especially true if you are dealing with higher brain functions, since the phenomena are complex (e.g. every time a human sees a flower, this experience is unique, and depends upon mood, hormonal state, directly preceeding sensory experiences, past associations, etc.), as are the emergent neural activity patterns which one would like to link the phenomena to.

However, I do agree in terms of the limitations of "method-oriented science." I think at the forefronts of modern biology, the only way to overcome the limitations of this "method-oriented" nature is to become "methods-oriented," i.e. oriented toward several strategically chosen methods.

2007/07/24

Finding your own voice

[Robin Williams on how he realized he had something unique to offer]

I was trying to find a unique voice versus a combination of other things. There was a big benefit show one night in San Francisco, and I really started to have a good time. I thought, "Hey, this is me! This isn't like Jonathan Winters or something." (Winters is one of Williams' biggest influences.) Everyone starts off kind of being someone else.

--US Airways inflight magazine

2007/01/10

Attribution of thoughts

Much of what I have to say has been stimulated by sources other than those I can cite or recall. A student's question, a colleague's comment, a paragraph or phrase read in a context now forgotten, a deep insight expressed by a scholar far more capable than I--all have stimulated my thinking in ways that I can no longer trace. Similarly, an absurdity in another writer's presentation or even a poorly designed and interpreted experiment may have strongly influenced my point of view. To all these now invisible sources, I am grateful.

-- W. R. Uttal, The New Phrenology, Acknowledgements