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.

344 CHAPTER 16. DYNAMICAL NETWORKS I: MODELINGHere is an example <strong>of</strong> <strong>the</strong> revised code, where I also changed <strong>the</strong> color map <strong>to</strong> cm.hsvso that <strong>the</strong> state can be visualized in a more cyclic manner:Code 16.8: net-kuramo<strong>to</strong>.pyimport matplotlibmatplotlib.use(’TkAgg’)from pylab import *import networkx as nxdef initialize():global g, nextgg = nx.karate_club_graph()g.pos = nx.spring_layout(g)for i in g.nodes_iter():g.node[i][’<strong>the</strong>ta’] = 2 * pi * r<strong>and</strong>om()g.node[i][’omega’] = 1. + uniform(-0.05, 0.05)nextg = g.copy()def observe():global g, nextgcla()nx.draw(g, cmap = cm.hsv, vmin = -1, vmax = 1,node_color = [sin(g.node[i][’<strong>the</strong>ta’]) for i in g.nodes_iter()],pos = g.pos)alpha = 1 # coupling strengthDt = 0.01 # Delta tdef update():global g, nextgfor i in g.nodes_iter():<strong>the</strong>ta_i = g.node[i][’<strong>the</strong>ta’]nextg.node[i][’<strong>the</strong>ta’] = <strong>the</strong>ta_i + (g.node[i][’omega’] + alpha * ( \sum(sin(g.node[j][’<strong>the</strong>ta’] - <strong>the</strong>ta_i) for j in g.neighbors(i)) \/ g.degree(i))) * Dtg, nextg = nextg, g

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

Saved successfully!

Ooh no, something went wrong!