Programming for Cognitive Science

Fall 2012

General information

Lab: Tuesday and Thursday 2:30pm - 3:45pm Lindley Hall LH 030.
Course website:

Instructor: Eduardo Izquierdo.
Office: Eigenmann Hall EG841.
Email: (be sure to include "Q530" in the subject line).
Office hours: Thursday 3:45pm - 4.45pm (immediately after class). Or by appointment.

Course description

This course is designed to refine your computer programming skills and acquaint you with applications of programming in cognitive science. Fundamentals of computer programming are introduced. Topics include: programming languages, variables, functions, and control structures; writing algorithms, understanding orders of complexity, testing and debugging programs; good programming style, and basic software design. The examples and exercises focus on cognitive science applications such as models of simple agent behavior, multi-agent games, self-organizing systems, and neural networks. Ultimately, the goal of the course is to increase your skills and confidence in problem solving using programming.


Think Python: How to Think Like a Computer Scientist (TP)

Python Programming (PP)

The Python Tutorial (PT).


Date Topic Assignment and readings
Unit 1: Programming basics
Week 1
Tue 21 Aug

Goals of the course; Administrative details; Thinking like a computer scientist; Programming languages; Python; IDLE; Values; Data types: Numbers and Strings; Operators; Errors; Debugging.

Assignment 1.

TP: Ch. 1, Ch. 2, and Ch. 5 (through section 5.7), Ch. 7.
PP: Variables and strings, Strings, Input/output, Conditional statements, and Loops.
PT: Tuples and sequences.
Other languages have "variables."

Advanced practice exercises.

Thu 23 Aug

Variables; Functions; Control flow tools: Conditionals and iteration; Flow charts; Programming style. (Code used in class).
Week 2
Tue 28 Aug Functions; Importing libraries; Exhaustive enumeration algorithms; For loops; Data structures. (Code used in class).

Assignment 2.

A selection of 10 different solutions to problem 3 in Assignment 1 from your classmates.

A few basic extra exercises to review what we have learned during the first two weeks.

TP: Ch.3, rest of Ch. 5, and Ch.6.
Floating point arithmetic: issues and limitations.
Successive approximation: Wikipedia article on Newton's method.

Thu 30 Aug Recursion.
Week 3
Tue 4 Sep Algorithmic complexity and efficiency. Bisection method.

Assignment 3.

TP: Appendix B.

Wikipedia: Binary search (focus on the recursive implementation in Section 4).
Wikipedia: Selection sort.
Wikipedia: Insertion sort.
Wikipedia: Merge sort.

Thu 6 Sep Analyzing efficiency (sort and search).
Week 4
Tue 11 Sep Object-oriented programming (part 1).

Assignment 4. Note: The only rule for this assignment is that you cannot access the attributes of a class outside of itself - only its methods.

TP: Chapters 15, 16, 17, and 18.

Thu 13 Sep Object-oriented programming (part 2).
Week 5
Tue 18 Sep Simple plotting using matplotlib and iPython.

Assignment 5.

Matplotlib tutorials: here and here. Gallery. Scipy and numpy documentation.

Script to install Python science packages for OS X.

Running iPython notebook from my computer.

Thu 20 Sep Practice plotting in Python or Matlab.
Unit 2: Programming in Cognitive Science
Week 6
Tue 25 Sep Saving data from simulations and analyzing data stored in files.

Assignment 6.

And remember to make your code readable.

Download words.txt, obama2012.txt, romney2012.txt, obama2008.txt.

Writing/reading files: TP: Chapters 9, 14, Input output, reading and writing files in Python.

Dictionaries. TP: Chapter 11.

Thu 27 Sep Working with text. Data type: dictionaries.
Week 7
Tue 2 Oct

Spatial orientation in simple agents. Building a sensori-motor agent in an environment.

Assignment 7.

A few recommended readings about agent-based modeling: from Think Complexity, Scholarpedia, Boids (flocks, herds, and schools), Agent-based modeling: a revolution, Agent-based modeling: methods and techniques for simulating human systems, Simulation models as opaque thought experiments, The view from elsewhere: perspectives on Alife modeling.

List of applications of individual-based models, arranged by general topic area.

Thu 4 Oct
Week 8
Tue 9 Oct Self-organization in multi-agent systems.

Assignment 8.

Schelling's dynamic model of segregation.

Steven Strogatz: How things in nature tend to sync up.

Thu 11 Oct
Week 9
Tue 16 Oct

Self-organization in multi-agent systems (Continued).

Basic GUI (graphical user interface) in Python using Tkinter.

In-class assignment.

Tkinter basic examples: 1, 2. Example figures: a, b.

Thu 18 Oct
Week 10
Tue 23 Oct

Building simple visual and auditory stimuli experiments in PsychoPy.

Assignment 9.

PsychoPy for Python. (articles about PsychoPy: 1, 2). Download.

Psychtoolbox for Matlab.

Sofwate for visual psychophysics.

A primer of visual stimulus presentation software.

Thu 25 Oct
Week 11
Tue 30 Oct

Building simple visual and auditory stimuli experiments in PsychoPy (continued).

Neural networks (Complex networks of nonlinear heterogenous dynamic elements).

Assignment 10.

Beer (1995). On the dynamics of small continuous-time recurrent neural network.

Example code.

Wikipedia: Recurrent Neural Networks.

Thu 1 Nov
Week 12
Tue 6 Nov

Neural networks (Complex networks of nonlinear heterogenous dynamic elements).

Thu 8 Nov
Unit 3: Final projects
Week 13
Tue 13 Nov

Assignment 10 due.

Proposal hand-in and presentations.

Thu 15 Nov
Thanksgiving Week
Tue 20 Nov No class.  
Thu 22 Nov
Week 14
Tue 27 Nov Progress update on final projects.  
Thu 29 Nov
Week 15
Tue 4 Dec Results presentations.  
Thu 6 Dec
Week 16

Tue 11 Dec

Thu 6 Dec

Final project due.

Rest of results presentations.

Class policies

You are expected to attend and participate.

Sessions will begin with a presentation of the topic. You are expected to have done the readings for that week and participate in a discussion of the topic. The lecture and discussion will include computer demonstrations. The rest of the time will be used to work together through additional problems on the topic.

If you are working on your own machine, you may need to install Python (Python comes pre-installed on Mac OS X). We will be using the standard Python software, available here. You should download and install version 2.7.3.

Weekly assignments
There will be assignments given weekly for (roughly) the first 12 weeks. The assignments will be further developments of the topics covered that week in the class. Assignments shall be handed via Email (see details on the assignments). Assignments will not be accepted late for any reason. Instead, the lowest homework grade will be dropped, so it would be wise to plan on using this drop in the case of illness, emergencies, etc. You are welcome to collaborate on assignments with your peers. Each student must turn in their own assignment. You should state in your report who you collaborated with and what each of your contributions were. If you have problems with the homework, seek help.

Final project
The final weeks of the semester will be dedicated to working on your final project on a topic of interest and relevance to your graduate research. Proposal: 500 word abstract proposing how you will use programming to study an aspect of cognition. Written report: You will be asked to write a short paper (over 1000 words, four or more pages in length, 1.5 spaced, 12 point font) reporting on the motivation for your project, the methods, a justification of the model and the programming, the results, and a discussion. The report should include figures and references. You will also be asked to turn in the programming code, well commented. Oral presentation: 15 minute presentation to share your final project and to get feedback from your peers.

10% Participation
55% Assignments (5% each, ×11, lowest dropped)
35% Final project (5% for written proposal; 15% for results presentation; and 15% written final report)

Late work
Assignments and projects will not be accepted late for any reason.

Supplementary material

Although not officially assigned for the course, the following books and research articles address many of the topics that we will discuss in further depth.

Classical computer science textbooks:

Cormen, et al., (2009). Introduction to Algorithms.  

Aho et al., (1983). Data Structures and Algorithms.

Mehlhorn and Sanders (2008). Data Structures and Algorithms. 

Press, et al., (2007) Numerical Recipes: The Art of Scientific Computing.

Knuth (1997). The Art of Computer Programming. (And why he calls it an art).

Books on computational modeling in biology and cognitive science:

Kauffman (1993). Origins of Order: Self-organization and Selection in Evolution.

Ashby (1952). Design for a Brain: The Origin of Adaptive Behavior.

Alon (2007). An Introduction to Systems Biology: Design Principles of Biological Circuits.

Ellner and Guckenheimer (2006). Dynamic Models in Biology.

Wagner (2005). Robustness and Evolvability in Living Systems.

Walleczek (2000). Self-Organized Biological Dynamics and Nonlinear Control.

Camazine, et al., (2001). Self-Organization in Biological Systems.

Dayan and Abbott (2005). Theoretical Neuroscience: Computational and Mathematical Modeling of Neural Systems.

Flake (1998). The Computational Beauty of Nature: Computer Explorations of Fractals, Chaos, Complex Systems, and Adaptation.

Noe, van Hooff, and Hammerstein (2001). Economics in Nature: Social Dilemmas, Mate Choice, and Biological Markets.

Downey (2012). Think Complexity.

Articles on the role of computational modeling in biology and cognitive science:

Abbott (2008). Theoretical neuroscience rising.

Bedau (). Can unrealistic computer models illuminate theoretical biology?

Beer (1995). A dynamical systems perspective on agent-environment interaction

Bray (2001). Reasoning for results.

Brenner (1999). Theoretical biology in the third millennium.

Boden and Mellor (1984). What is computational psychology?

Chiel and Beer (1997). The brain has a body.

Cliff (1990). Computational Neuroethology: A Provisional Manifesto.

Di Paolo et al., (2000). Simulation models as opaque thought experiments

Harvey et al., (2005).  Evolutionary robotics: A new scientific tool for studying cognition

Harvey, I. (2009) Tool-makers versus tool-users: Division of Labour.

Kitano (2002). Systems biology: A brief overview.

Lazebnik (2002). Can a biologist fix a radio? - or, What I learned while Studying Apoptosis.

Marr (1977). Artificial Intelligence - A personal view.

Miller (1995). Artificial life as theoretical biology: How to do real science with computer simulation

Noble et al., (2000). Artificial life: Discipline or method? 

O'Reilly (2012). Biologically based computational models of high-level cognition.

Stanford Encyclopedia of Philosophy. Models in Science.

Wheeler et al., (2002). The view from elsewhere: Perspectives on ALife modelling

Victor (2011). Up and down the ladder of abstraction.