# I485: Biologically Inspired Computing

# Lab 0: Python Review

### Topics

- The purpose of this lab is to introduce you to the computing platform we will use throughout the course, which is Python 2.7.
**Installing Python**: We recommend installing the "Enthought Canopy Express" a python distribution, which is freely available. There is also an academic version of Canopy that comes with additional benefits for free (the 64-bit version is recommended). Canopy will automatically install Python 2.7.6;*do not*install Python 3. Downloading and installing Canopy is quite straightforward, but help is available.- Python is a versatile scripting language, and is a popular choice for scientific computing purposes. To add spice to your code, Python also comes with friendly graphics and visualization packages that you will be using a lot for your assignments and projects, often as a necessity. You can peek at a few student lab submissions from previous years. If you don't already know how to program in Python, learning it is relatively easy. Although the objective of this course is not to learn Python, but to use it to explore bio-inspired computing algorithms, in this lab we provide a quick refresher (this is an iPython notebook; you will need Canopy or another iPython package to view it) of the basic commands and data structures that you may require throughout the course. All necessary software for this course is available in the STC Windows computers.

# Training Exercises

**For beginners: Drunken ant.**A flat ant lives on a flat world. It is intoxicated and meanders on its world. Simulate this random walk for a few steps, and calculate its net displacement.*First*, make a few assumptions. Assume that the 2D coordinates of the world are only integers:*(x, y)*where*x*and*y*can be a positive or negative integer. Assume that the flat is of infinite size, that is*x*and*y*can be very large numbers. Assume that the center of the world is at (0, 0), and the ant always starts from there and takes exactly 10 steps from there.*Second*, implement the world coordinates. One way is to use tuples.*Third*, implement the ant's drunken walk. Starting from the center of the world, the ant must take a small step in a random direction. You can use the modules available in the package 'random' for this. Remember to make random additions to both*x*and*y*directions.*Finally*, calculate the net displacement. This is the Euclidean distance between its position of the ant on the 10th step and the center of the world from where the ant first takes off. You may also wish to keep track of the full trail and calculate the total distance walked.

**More Advanced: Graph traversal.**Take a piece of paper, and make up a small graph (or network) with 5 vertices (or nodes) in it. Randomly assign a few links or edges between them. Your graph drawing should look something like this. Label the nodes with numbers or strings.*Your first task*is to represent this graph in Python. You may use any data-structure of your choice: it may be a dictionary with keys standing for node labels and values standing for the neighboring nodes’ labels, or two separate lists, one containing all the “from” nodes, and the other lists of lists containing lists of all the “to” nodes that each “from” node is connected to, or define an adjacency matrix, or you can get creative.*Your second task*is to pick up all possible paths between two chosen nodes where no path visits a node more than once. Note that since there are only 5 nodes, the maximum number of edges in such paths between any two nodes is only 4. You may also wish to play with directed edges where you assign a direction to each edge in your graph, so your program will be constrained to traverse edges only along the directions specified.

# More

*Acknowledgements*

- Lab prepared by Santosh Manicka.

*Links*

I485 Biologically-inspired Computing