Scientific Programming

Instructors: 

Michele Furlan

Amount of frontal teaching: 

45 hours

Aims
The size of datasets regularly collected by and available to neuroscientists is steadily increasing over time. As a result, programming is becoming an essential skill in order to acquire, clean, transform and extract meaningful insights from the data. This course is intended to provide students with a framework to understand programming, as well as with a set of concrete skills in the field of data science.

During the course we will focus on both basics and advanced topics, such as:
    • What are vectors, matrices, and arrays, and how can we access the data contained in them?
    • How can we efficiently import and export data?
    • How can we visualize data?
    • How can we write our own libraries?
    • How can we optimize the execution of our code?

At the end of this course, and with a certain amount of hard work, you will hopefully be able to:
    • Break down complex problems in smaller discrete components, and then solve the big problem by systematically solving the smaller components;
    • Write clear functions as well as clear libraries;
    • Debug your own code as well as other codes;
    • Combine data acquisition with data analysis potentially in the same set of functions;
    • Be able to consistently clean your code in order to share it with other researchers

Structure
The course will last for three weeks, for a total of 45 hours (15 hours per week). Three days a week will be spent exploring the theoretical aspects of programming, while the remaining two days will be spent exploring the practical aspects.

This course will require the students to complete two exams. The evaluation exam will be taken at the start of the course and will be intended to gauge student’s knowledge of programming. The final exam will be taken at the end of the course and will assess what students learnt from the course. The course will be mandatory for all the students who do not pass the evaluation exam, while it will be optional for students who do pass this exam. The primary programming language used during the course will be MATLAB. Students will be asked to use their own laptop, on which MATLAB will be installed.

Dates
Thursday 11/1: Evaluation exam.
Monday 15/1 to Friday 19/1: 14:00 – 17:00
Monday 22/1 to Friday 26/1: 09:00 – 12:00
Monday 29/1 to Friday 2/2: 09:00 – 12:00
Friday 9/2: Deadline for the Final Exam.

Exams
The evaluation exam will cover theoretical aspects (e.g., what is a function, what is a loop) as well as exercises in MATLAB (e.g., matrix multiplication, indexing, control flow). In the final exam students will be asked to write a simple script to run an experiment and collect behavioral data. Students will have the last week of the course to complete the final exam independently, and will be asked to submit it by the final day of the course. The goal of the final exam is to help students see what they have learnt in the course, and which areas they may still want to improve.

 

Lesson Plan

Lesson 1: Programming basics
Here we will focus on what we mean by programming, and why programming is becoming increasingly important for scientific research. We will learn what MATLAB is, how to use it (e.g., using the command window, Workspace, and command history), and where to find help, including the online resources available (e.g., “Loren on the art of MATLAB”) and documentation from Mathworks (manuals).

Lesson 2: Data fundamentals 1

Here we will focus on numerical data (e.g., int, double) and how to combine them in vectors, matrices, and arrays. At the same time, we will explore how to access the data using indexing, matrix manipulation, matrix combination, subsetting, variables, assignments, incrementing and decrementing.

Lesson 3: Exercises on programming basics

Lesson 4: Data fundamentals 2
Here we will focus on other data types, such as characters and strings, and how to manipulate these data types. We will explore concepts including string manipulation, arrays, structures, cells, and dynamic access. We will also learn how to import several types of data and how to tidily store them.

Lesson 5: Exercises on data fundamentals

Lesson 6: Loops
Here we will focus on loops, such as for, if, while, switch, break, return, nested loops, conditional statements (and, or), flow controls. We will also explore how to reduce the number of loops by vectorizing our code.

Lesson 7: Functions
Here we will learn how to write functions. We will learn about nested functions, function handles, the difference between scripts and functions, debugging, error handling (try-catch-end), input, output, and libraries.

Lesson 8: Exercises on loops and functions

Lesson 9: Data visualization
Here we will learn how to visualize our data as a function of our purpose (e.g., fo publications, or a sanity check). We will first focus on simple plots, such as line and scatter plots, and then move on to more complex topics, such as 3D plots, line properties, subplots, figure handles, displaying images, printing plots, and meshes. We will also learn how to import images (e.g, *.bmp) and how to save your images.

Lesson 10: Exercises on data visualization

Lesson 11: Data I/O
Here we will focus on data importing and exporting. This will include how to import and export data with different file formats (e.g., *.txt, *.xls, *.bmp.

Lesson 12: Advanced topics
Here we will understand how to effectively clean your code (although this concept will be emphasised during the whole course). We will focus on topics such as vectorization, timing optimization, memory handling, preallocation and initialization, producing a log, naming, speeding up your code by writing in C++ (creating mex files), and writing your own libraries.

Lesson 13: Exercises on data I/O and advanced topics

Lesson 14: Psychtoolbox
The final part of our course will be spent learning how to create stimuli, visualize stimuli, wait for responses, collect response time and accuracy data, and build an experiment.  

Lesson 15: Exercises on Psychtoolbox