CSS 455 Scientific Programming
Machine Problem #2 MP2
Rats in a Maze[i]
Deadline: for full credit - 11:45 PM, Sunday, February 12.
for 75% credit - up to 24 hrs late
for 50% credit – up to 48 hrs late
Changes made since original posting are in blue.
Specification. The overall problem here is to provide a Matlab program for a psychologist is testing whether or not rats can learn. A psychological experiment which is used to test whether rats can learn consists of (repeatedly) putting a rat in a maze of interconnecting passages. At each intersection the rat chooses a direction and proceeds to the next intersection. Food is placed at one or more of the exits from the maze. If the rat learns, then it should get food more
frequently than would result from random decisions. The computer program provides the random probability from each cell that the rat will find food. The “simple case” for this problem is essentially the one you ran in a HW3 assignment:
Consider a small 4 rows x 5cols
demo problem of the rat maze. The maze is given below with a set of probabilities
of finding food on the perimeter:
XX |
0 |
0 |
0 |
XX |
1 |
P22 |
P23 |
P24 |
0 |
1 |
P32 |
P33 |
P34 |
0 |
XX |
0 |
0 |
0 |
XX |
The corner cells are
inaccessible and irrelevant. The exits with “1” have food in them, and the
ones with “0” do not. The edge cells are all exits from the maze. The
probability of success for any interior cell is given as the average of its
four neighbors:
There is one equation like this for each internal cell (6 equations here). This system of equations for the probabilities for a system of linear equations that can be solved in various ways.
Base Case. Because this is a sparse system and we intend to run large cases, you are to use the Gauss Seidel iterative method. This is covered in ch 7 of Turner and has been the subject of the HW3a problem. The detailed specification of the first-phase of the program is as follows:
Runs to be Reported
Base case.
1. Provide properly labeled output for the case of 8 rows and 7 columns using the pattern of food shown in the diagram above.
Refinements and Extensions. After you have the base case running and tested,
you are to extend it . In each of the following cases, the program should add
these features without subtracting the ones you introduced in the base case.
Each number below is an additional case to be reported:
2.
Run the basic rectangular grid for
a wide range of maze sizes (n x m) to determine experimentally how the
time to convergence and the number of iterations varies with grid dimension. You
should achieve dimensions of at least 130 rows and columns in this
process. This analysis should indicate experimentally how the time of
calculation varies with dimension of the system of equations. #2 does not
involve modifying the eqns of #1.
3.
Add diagonal passages, so that the
rat can go diagonally with the same probability as to the four
directions above. For example , the rat could go from cell (3,3) to cell (2,4)
in addition to the four in the simple problem: (2,3), (4,3), (3,2), and (3,4). This
rat could also go to (2,2), (4,4) and (4,2) . The probability of cell (3,3) is
now the average of the probabilities for 8 neighboring cells. The corner cells
of the maze can now be reached, but they are to be set to “no food.” This involves
modifying the equations..
4. Now working from the simple rectangular grid (no diagonal moves), make a model in which all moves are not equally probable. The probability of a certain move will depend upon the direction of the rat at that time and will be different for the four available directions.
a. For example, if a northbound rat is in cell (2,3), then there are different probabilities that the rat will move forward to cell (1,3), turning to the right to cell (2,4), turning to the left to cell (2,2), or reversing direction to cell (3,3). Instead of each direction being weighted equally (25%) as in the base case, each of the directions has a different weight.
b. The probabilities for neighboring cells would be weighted differently for different orientations of the rat. An eastbound rat in cell (2,3) would have forward probability to cell (2,4), right turn to cell (3,3), left turn to cell (1,3), and reverse to cell (2,2). That means there are four different probabilities for each cell, depending on the orientation with which the rat is dropped into it.
c. The user will provide this model with a set of four probabilities for the rat to: move ahead, turn right, turn left, or turn around in reverse. These can be different, must add up to unity, and can be individually zero. For example, if rats cannot turn around, then the reverse probability becomes zero, and the other three must sum to unity. Note as a test for this model, setting all probabilities equal to 25% should duplicate the base case.
d. Produce a nicely labeled output for the (8 x 7) case with the following probabilities: reverse (0), and all other directions equally probable.
e. Produce a nicely labeled output for the (8 x 7) case with the following probabilities: reverse (0), forward 50%, turn right or left 25%.
5.
Working with the base rectangular
grid, add the possibility of a “trap door” in one cell, in which the rat falls
out of the maze upon entering that cell. The user should be able to select the
cell. Run this for the (8x 7) case and turn in a nicely labeled output.
6.
Finally (do this last!)
parallelize the code and distribute it over Matlab workers in a matlab pool. Unlike
MP1, this is not so easy or efficient here. The Jacobi method described in the
book is closely related to Gauss Seidel, in general slower to converge, but
more readily made parallel. I would base my distributed strategy on the Jacobi
method. The key question is whether the slower Jacobi convergence more than
overwhelms the computational advantage of parallel computing. You will need to
do an analysis as a function of problem size to determine this. This should
be done last – the other steps are of greater importance in the final grade
here. The code may need some redesign at this point.
Programming comments.
Preliminary submission. By 11:59 PM, Friday, February 3, you are to turn in a deliverable to the “MP2PreliminarySubmission” drop box. This file is to report on the design (including modularization), author responsibilities for different components and phases of code development. It should also include rough drafts ( not yet debugged) of any modules that have been started.
Report. Report should include:
[i] Turner, P.R., notes from “Numerical methods – An introduction to Scientific Computing”, Fall 2007, private communication.