Programming Project #1
Population Dynamics

Code due Friday of 6th Week
Paper due Tuesday of 7th Week

 


Introduction

The purpose of this project is to practice creating and analyzing computational models in Python. You may work on this project individually or in group of two. The specific sysem we will be examining is a discrete time, discrete space, model of predator-prey population dynamics. Our model will make the following simplifying assumptions:

There are two deadlines for this project. For the first deadline you will need to get a basic version of the project working and submit your code. For the second deadline you will need to run experiments using your code and submit a report describing the results. Depending on the experiments you choose to perform, you may or may not need to make changes to your original code. The code and the paper will be weighted equally in final grade for this project.


Part 1: Writing the Code

Much of the code for this project is already written. You may get a copy by downloading the file Population.py. The (incomplete) main function for the program is the predator_prey function. Your goal will be to fill in the missing pieces of this function and several other functions.

The rules that will govern our simulation are taken from [1]. The evolution of the system is governed by the following three interactions1:

V + O -->r   2V    (Reproduction)
V + P -->p   2P    (Predation)
P + O -->d   2O    (Starvation)

In these interactions, V represents a cell occupied by prey, P represents a cell occupied by a predator, and O represents an empty cell. The variables r, p, and d represent the probabilities that the indicated interactions will occur. As an example of how these rules will be implemented in the code, let's consider reproduction:

Select a random cell from the environment.
    If the cell contains prey (V), then
        select one of the four neighbors of the cell at random.
        If the neighbor is empty (O), then
            It is filled with prey with probability r.
        Otherwise 
            Nothing happens.
    If the originally selected cell does not contain prey, then
        nothing happens.

A partially completed function, reproduction, to implement this logic is provided in the Population.py file. It will be your responsibility to create similar functions to handle the rules for predation and starvation2. The simulation progresses by repeatedly applying these three rules.

In order to analyze the results of the simulation, it will be necessary to track the population sizes of the different species over time. You will need to write a Python function that is able to count the number of cells that have a particular value. You should not have three separate functions: count_prey, count_predator and count_space. Instead, you should create a single function, count_species, that uses a parameter to determine what species it should be counting. Your function should work equally well for a simulation that includes 50 species as it does for a simulation that only include three. Throughout the code that is provided, prey are represented by cells containing 1's, predators are represented by cells containing 2's, and empty space is represented by cells containing 0's.

Before you dive in and start programming, you should carefully read this entire document to make sure you understand what is expected. You should also take a careful look at the code that is provided, read the comments, and make sure you understand the changes that need to be made. You should test each function as you code it rather than trying to write all of the code at once.

The functions that will be included in your completed program fall into the following three categories:

  1. Functions that are provided and do not need modification:

  2. Functions that are provided but need to be completed:

  3. Functions that you need to create from scratch:

1These dynamics are not terribly realistic. For example, why doesn't a predator have a chance of starving when it interacts with another predator? However, they do result in interesting cyclical dynamics.
2Optionally, you could write a single parametrized function that is able to handle any interaction of the kind described here.

Submitting Your Code

When you are satisfied your code is working properly, submit your Population.py file via Kit. Your Python code will be graded on the basis of style as well as correctness. Your code should include appropriate comments. (Comments before functions, inside of functions, program description, etc.) Variable names should be descriptive.

The following scale will be used to grade the program:
Grading Criteria Points
Functionality 30
Style/Organization 10
Appropriate Comments 10
TOTAL 50


Part 2: Experimentation and Report

Once you have your code working properly, you'll need to choose a question that you would like to address with your model, and run appropriate experiments to answer it. Be creative. There are many possibilities. Here are a few ideas that you could pursue. Most of these are a bit broad; you will probably need to narrow them down to come up with a manageable project. Don't be too ambitious. You are more likely to do a good job if you pick a topic that is simple and focused.

Keep in mind that some of these questions can be answered without making changes to the code, while others cannot.

The Report

The final report should be a 3-5 page paper detailing your experiment(s) and results. It should include appropriate figures to illustrate your results. Grammar and spelling will count, as will the overall structure and flow of the paper. Your paper can be prepared using any word processing program and then converted to PDF. Minimally, it should include:

In writing your paper, you can consider the rest of the class to be the target audience. This means that you do not need an extensive explanation of the basic premise of the paper, but you do need to clearly describe the specific question that you are addressing. Reports will be graded according to the following rubric:
Grading Criteria Points
Content
Do you have a clearly articulated experimental question?
Does your paper effectively address that question?
10
Spelling, grammar, sentence structure 5
Word selection and tone
Your paper should use precise and unambiguous language. It should not have an informal tone.
5
Organization
Appropriately organized sections. Well structured paragraphs.
5
Figures
Figures should support the conclusions of your paper. They should include captions and axis labels.
3
BiblographyAny outside information should be cited. 2
TOTAL: 30


Submitting Your Report

Your completed report should be submitted on Kit.


References

[1] A. Provata, G. Nicolis, and F. Baras. Oscillatory dynamics in low-dimensional supports: A lattice Lotka-Volterra model. Journal of Chemical Physics, 110(17), 1999.