Random Graphs in NetworkX: My Spatial-Temporal Preferred Attachment Diversion

To take my mind off my meetings, I spent a little time modifying the Spatial Preferred Attachment model from Aiello, Bonato, Cooper, Janssen, and Prałat’s paper A Spatial Web Graph Model with Local Influence Regions so that it changes over time.

NetworkX makes this kind of messing around pretty easy, and I find the random functions in PyMC are handy, too. Here’s what it takes to generate one of their graphs:

def make_graph(n, d, p, A1, A2, A3):
    position = runiform(0, 1, size=(n, d))
    affinity = runiform(0, 1, size=(n,n))

    G = DiGraph()
    G.add_nodes_from(range(n))

    for t in range(1, n):
        for s in range(t):
            if distance(position[s], position[t]) \
                    <= (A1 * G.in_degree(s) + A2) / (t + A3):
                if affinity[t, s] <= p:
                    G.add_edge(t, s)

    return G

Here is how I animated it.

3 Comments

Filed under combinatorics, probability

3 responses to “Random Graphs in NetworkX: My Spatial-Temporal Preferred Attachment Diversion

  1. Does anyone know how to make this into a youtube movie?

  2. I figured out how: mencoder mf://*.png -mf w=800:h=600 -ovc x264 -of avi

  3. Finally, I have removed the 100 meg gif animation. Final puzzle piece: [vimeo 17389019] to embed the flash video in wordpress. They should document that!