Assignment 2 (CS 4884: Computing the Brain)
Deadline: 11:59pm, March 20, 2019

The goal of this assignment is to write code that can replicate the main plot in the Watts-Strogatz paper. You can use any programming language you want. Feel free to use matrix or graph libraries that already implement helpful classes and functions, unless I instruct you otherwise. Work on this assignment individually.

Watts-Strogatz graphs

  1. Write a function generate_watts_strogatz_graph to generate randomised ring graphs using the Watts-Strogatz model. The function should take three parameters: \(n\), \(k\), and \(p\). Here \(n\) is the number of the nodes in the network, \(k\) is the degree of each node, and \(p\) is a probability between \(0\) and \(1\). The parameters \(n\) and \(k\) are integers and \(k\) can be even. A single call to this function should create an undirected, regular, ring graph with \(n\) nodes and \(nk/2\) edges, and then rewire every edge with probability \(p\), as described in the caption of Figure 1 of Collective dynamics of 'small-world' networks. Recall that in a regular graph, all nodes have the same degree. Therefore, in this graph, each node has degree \(k\). If the graph is disconnected after rewiring, rewire repeatedly until it is connected (i.e., all nodes are in the same connected component). Implement this function yourself. Do not use a ready-made implementation in some other package or library.
  2. You will need two other functions that compute the average shortest path length \(l(n, k, p)\) and the clustering coefficient \(c(n, k, p)\) of an undirected graph with these parameters. You can use existing implementations of these methods from Assignment 1. Be careful about blindly using these methods without considering the running time.
  3. Invoke this function with 20 different values of \(p\) (see the next point for which values to try) and the following values of \(n\) and \(k\):
    1. \(n=100\), \(k=6\).
    2. \(n=100\), \(k=10\).
    3. \(n=1,000\), \(k=10\).
    4. \(n=1,000\), \(k=20\). The last two sets of graphs will require about \(5\times 10^5\) shortest path computations per graph. If you develop some heuristics for estimating the average shortest path length efficiently, provide some evidence convincing me that your estimates are good.
  4. Experiment with two different sets of choices of values of \(p\): (a) \(0.05 \times l\), where \(l\) takes the value of every integer between \(1\) and \(20\) and (b) \(x^l\), where \(x\) is suitably chosen between 0 and 1 and \(l\) has the same range as before. Make a sensible choice of \(x\) and provide a justification in your report. For each value of \((n, p, k)\), try at least 10 runs. Your goal is to regenerate Figure 2 of Collective dynamics of 'small-world' networks for each \((n, k)\) pair, while also plotting the average and standard deviations of \(l(n, k, p)/l(n, k, 0)\) and \(c(n, k, p)/c(n, k, 0)\). The paper did not plot the standard deviations.

Here are some guidelines to keep in mind:

  • There are four pairs of \(n\) and \(k\) and two sets of 20 different values of \(p\). For each \((n, p, k)\) combination, you need to execute your code 10 times, for a total of 1,600 runs.
  • It may be challenging to get results on your laptops, especially for \(n=1,000\). You may use the rlogin cluster in the Department of Computer Science.
  • I want to see eight plots, one for each \((n, k, p)\) pair. Each plot should look like Figure 2 of the paper, except that you will plot both the averages and the standard deviations. Either annotate each plot or write in text the range of probabilities for which you think you observe the small-world property.
  • Plot the averages and standard deviations on the same plot, not on the different plots. If you use the Python matplot library, you can use error bars to indicate the standard deviations.
  • Do not submit tables of values! I need to see plots.
  • Start well in advance of the deadline. Your code will have bugs. It will take a long time to run. There is no correct answer, so you will have to do a lot of trial and error.
  • Make sure each plot in the submitted PDF is easy for me to read: the font should be large, the labels and legends should be clear, the ranges for the axes should be appropriate to showcase the trends you want me to notice (and that you describe in the text of your report), the whitespace around the plot should be minimal, and the plot itself should not be small.

Some additional notes:

  • To log into the rlogin cluster if you are not connected to the campus network, you may have to use the Virginia Tech VPN. Install the Pulse Secure software for that purpose.
  • rlogin does not have networkx or other packages installed. Use pip install --user networkx to install the package in your own directory on rlogin. Obtain your results and then transfer them to some computer where you have more power on installing packages in order to the plot the results.
  • It will help if you have one script/program that creates the graphs, computes the shortest path lengths and clustering coefficients, and prints the results and another script that reads in the results and creates the plots. That way you can work on creating nice plots while the other program is churning through the computations.
  • You should be able to run your code for \(n=10\) on your laptops without any problem. Use the results to fine tune your plots.
  • I think you know that it will make sense for your scripts to take command line parameters for n, k, p. You can create output file names automatically based on the input values.
  • You can use the "time" system command to measure the running time of your scripts. You can use it to estimate how much your script will take for \(n=500\), e.g., by running your script for \(n=50\) and multiplying by 100.

Submission via Canvas

Turn in a typeset (not handwritten) report describing your results and the plots. Mention any difficulties you encountered and how you addressed them. Were there any surprises, i.e., results or trends you did not expect? I am also curious to find out what you learnt from this assignment.