Thursday 23 October 2014

Wednesday 15 October 2014

Programming for Scientists

I'm assuming that everyone has come to the conclusion now that programming is a necessary part of any scientific pursuit. Computers are an integral part of how we all gather, analyse and present our data. There are also techniques of code abstraction, version control and code testing that facilitate writing error free code that is easy to maintain and over time becomes a resource. These techniques are slowly making their way from the computer science field to the behavioral sciences. Unfortunately it has taken some high profile retractions of journal articles to push this issue forward.

As those I have been studying with have entered their PhD phase, there is a growing realisation that learning to program is essential. Along with that realisation I am also hearing a common statement. Most people assume that somewhere along the line, they would be sat down and shown how to program, that there would be some course to teach them what they need to know about programming. At least enough to analyse fMRI, MEG or EEG data. Most are shocked when they are handed a data set and told to 'now go analyse it'.

I went looking for teaching materials to meet this need and help my friends out. We talked a lot about what was necessary and arrived at a few realisations.

1. You learn best when the problem you are trying to solve is your own.
2. Everyone is too busy to learn programming right now but they will be busier any time in the future.
3. The easiest way to get someone into programming is to teach them something that will benefit them right now.
4. Teaching what you have learned to someone is of huge benefit and therefore absolute beginners who can be taught by those who are a little more advanced are a valuable resource for any learning group.
5. There needs to be a certain level of uncertainty, it greatly improves the internalisation of the material once the uncertainty is removed through experimentation. We are mostly scientists and the process of hypothesizing and testing is a skill we can use here too.  

The Facebook page gets a lot of views and a good amount of 'likes'. There are three or four people who turn up on a regular basis and are making great progress. The big struggle now is to get more people to actually turn up and do some coding.

The weekly sessions have taken on a definite style and are challenging but really enjoyable. The general format is to propose a common task and work slowly through the steps needed to solve this problem. The main feature is to pause at the start of each step and have everyone talk about their expectations. Having people talk about possible strategies and how they might use ideas from other solutions helps understand where everyone is in their thinking. It usually clears up misconceptions before they become too confusing.

Learning these techniques is very similar to learning a musical instrument. You can study the subject as much as you like but  you won't really improve until you practice. Trying things out and making mistakes is much more valuable that having the final answer presented to you with all the anguish removed.

Serious writers write, inspired or not

I have many reasons for writing this blog. One of them is to practice writing.

As a scientist, I think my main task is to communicate. Usually as written reports but also at conferences and in classrooms. Although gathering and analysing data is a crucial part of scientific inquiry, it is a little bit pointless if I can't transmit what I learn to others. In an effort to be better at that, I take pointers from two sources.

The chain

 

This post about the Jerry Seinfeld's "Don't break the chain" method is why I put my writing online.
The main message is that if you want to be a great comic, you need great jokes. To have great jokes you need to write lots of jokes to get better at it and to be able to pick the better jokes from the ok jokes. To write lots of jokes, you need to write often - this is where the chain comes in. If you have a wall calendar and make a big cross on every day you write, the crosses form a pattern. After you write on a few consecutive days, you want to keep writing so you 'Don't break the chain'. It's a way to consciously create a habit.

This blog is a public place where it is obvious if I'm regularly putting up content, it's obvious how productive I'm being. I have to write complete post, not just 'to do' lists. I have to write for someone else, not just notes for myself. This means I need to express ideas clearly and fully.

In the same vein, the  NeuralCode  meetings mean I must research and prepare material on scientific computing every week. I also post related articles to the feed as a way to engage the members of the group and send support material to the email list. It's a way of getting to where I want to be.

I hope to be someone who gives lectures and tutorials on scientific computing. I am really passionate about modernising research and the practice of reproducible research. To one day be that person I need to have a body of work that shows I know what I'm talking about and can express that well. I also need to practice expressing those ideas. Because just like writing a joke, even if the original idea is great, if it practiced and honed it can be taken to a whole new level of great.

Scientific writing

A main theme is to simplify your expression and to follow the simple rules of good writing. The purpose of scientific writing is to communicate clearly. Einstein is reported to have said that if your science is any good, you should be able to explain it to a child. Part of this is using the clearest expression that conveys precisely what you mean. Using a complex and obscure word where a simple and common word would have the same meaning is something that creeps into our writing. It sounds more scientific. We read it in the papers of senior researchers. Knowing what big words mean gives us a sense of actually knowing something in a field where we are usually in a state of having no idea what's going on. So we hide behind the big words and cling to them like mantras so we don't feel like such fakes.

fa5.jpg

Unfortunately this makes understanding some literature harder than it needs to be. Obviously there is a need for very specific terminology at times, terms that may be very specialised and require the reader to search out the meaning if they haven't come across them before. There is a balance that needs to be found.

A great bit from the scientific writing course:

- from William Zinsser's book On Writing Well, which is a great book to pick up to read for this course if you have time.
He says,
"The secret of good writing is to strip every sentence to it's cleanest components.
Every word that serves no function, every long word that could be a short word,
every adverb that carries the same meaning that's already in the verb, every passive
construction that leaves the reader unsure of who is doing what.
These are the thousand and one adulterants that weaken the strength of a sentence.
And they usually occur in proportion to the education and rank (of the writer)."




Wednesday 1 October 2014

Psychopy in the IPython shell

Since finding Psychopy I've wanted the convenience of the IPython shell when writing scripts. The editor in Psychopy is OK but doesn't have all the nice features of IPython.

I had hoped that there might be a package in the conda environment but no such luck. The solution turned out to be Binstar.
I had been curious about Binstar since it started popping up as a suggestion whenever I tried to install something with conda and the package couldn't be found. It is basically user created packages and there was a package for Psychopy from Eric Kastman. I created a new conda environment with the command -
>> conda create -n psyk anaconda

I then activated this environment and installed Psychopy with Eric's package.

>> conda install -c https://conda.binstar.org/erik psychopy


I copied some tutorial code from  Psych711 created by Prof. Gary Lupya and ran it. 

There is a problem when I try to stop the Psychopy window but other than that 
it runs great!