15.08.2015 Views

Introduction to the Modeling and Analysis of Complex Systems

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

16.4. SIMULATING ADAPTIVE NETWORKS 367you are interested in more details <strong>of</strong> this, you should read Zachary’s original paper [59],which contains some more interesting s<strong>to</strong>ries.This data looks perfect for our modeling purpose. We can set up <strong>the</strong> initialize functionusing this ’club’ property <strong>to</strong> assign binary states <strong>to</strong> <strong>the</strong> nodes. The implementation<strong>of</strong> dynamical equations are straightforward; we just need <strong>to</strong> discretize time <strong>and</strong> simulate<strong>the</strong>m just as a discrete-time model, as we did before. Here is a completed code:Code 16.17: net-diffusion-adaptive.pyimport matplotlibmatplotlib.use(’TkAgg’)from pylab import *import networkx as nxdef initialize():global g, nextgg = nx.karate_club_graph()for i, j in g.edges_iter():g.edge[i][j][’weight’] = 0.5g.pos = nx.spring_layout(g)for i in g.nodes_iter():g.node[i][’state’] = 1 if g.node[i][’club’] == ’Mr. Hi’ else 0nextg = g.copy()def observe():global g, nextgcla()nx.draw(g, cmap = cm.binary, vmin = 0, vmax = 1,node_color = [g.node[i][’state’] for i in g.nodes_iter()],edge_cmap = cm.binary, edge_vmin = 0, edge_vmax = 1,edge_color = [g.edge[i][j][’weight’] for i, j in g.edges_iter()],pos = g.pos)alpha = 1 # diffusion constantbeta = 3 # rate <strong>of</strong> adaptive edge weight changegamma = 3 # pickiness <strong>of</strong> nodesDt = 0.01 # Delta t

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!