def order_parameter (G): if nx.is_connected(G): # Simulate from random initial conditions netevo.rnd_uniform_node_states(G, [(0.0, 6.2)]) netevo.simulate_steps(G, 100, None) # Calculate the order_parameter and return value mu = 0.0 for i in G.nodes(): for j in G.nodes(): if i != j: dist = np.linalg.norm(G.node[i]['state'] - G.node[j]['state']) # Heaviside function (allow for some numerical error:0.01) if dist - 0.001 >= 0.0: mu += 100.0 return mu * (1.0 / (G.number_of_nodes() * (G.number_of_nodes() - 1.0))); # If the network is not connected it is not valid return float('inf')
def order_parameter (G): if nx.is_connected(G): # Simulate from random initial conditions netevo.rnd_uniform_node_states(G, [(0.0, 10.0), (0.0, 10.0), (0.0, 10.0)]) # Simulate the system res, nmap, emap = netevo.simulate_ode_fixed(G, [0.0, 20.0], node_dim=3) # Calculate the order_parameter and return value mu = 0.0 for i in G.nodes(): for j in G.nodes(): if i != j: dist = np.linalg.norm(res[-1][nmap[i]:nmap[i]+2] - res[-1][nmap[j]:nmap[j]+2]) # Heaviside function (allow for some numerical error:0.01) if dist - 0.01 >= 0.0: mu += 100.0 return mu * (1.0 / (G.number_of_nodes() * (G.number_of_nodes() - 1.0))); # If the network is not connected it is not valid return float('inf')
#========================================= # Create a fully connected graph G = nx.complete_graph(12) # Both node and edge dynamics are required G.graph['node_dyn'] = True G.graph['edge_dyn'] = True # All nodes are chaotic Lorenz oscillators netevo.set_all_node_dynamics(G, lorenz_node_dyn) # All edges follow the adaptive rule netevo.set_all_edge_dynamics(G, adaptive_law_edge_dyn) # Randomly assign node states netevo.rnd_uniform_node_states(G, [(0.1, 20.0), (0.1, 20.0), (0.1, 20.0)]) # Edges all start with a very weak strength netevo.rnd_uniform_edge_states(G, [(0.00000001, 0.00000001)]) #========================================= # DEFINE THE VISUAL REPORTER #========================================= # Create the figure to display the visualization fig = plt.figure(figsize=(6.5,6.5)) # Node positions to use for the visualization pos = nx.circular_layout(G) # Function to generate the visualisation of the network def visual_reporter (G, t): plt.clf() n_sizes = []
G.graph['node_dyn'] = True G.graph['edge_dyn'] = False # Graph should have a ring topology n_nodes = 30 G.add_node(0) for i in range(1, n_nodes): G.add_node(i) G.add_edge(i-1, i) G.add_edge(i, 0) # All nodes are Kuramoto oscillators (discrete-time) netevo.set_all_node_dynamics(G, kuramoto_node_dyn) # Set random initial conditions for each node netevo.rnd_uniform_node_states (G, [(0.0, 6.2)]) #========================================= # DEFINE THE VISUAL REPORTER #========================================= # Create the figure to display the visualization fig = plt.figure(figsize=(6,6)) # Node positions to use for the visualization pos=nx.circular_layout(G) # A visual reporter that will display the current state of the network # as it is being simulated #ims = [] plt.show()
for n in range(12): G.node[n]['color'] = 'b' G.node[12]['color'] = 'r' # Both node and edge dynamics are required G.graph['node_dyn'] = True G.graph['edge_dyn'] = True # All nodes are chaotic Lorenz oscillators netevo.set_all_node_dynamics(G, lorenz_node_dyn) # All edges follow the adaptive rule netevo.set_all_edge_dynamics(G, netevo.no_edge_dyn) # Randomly assign node states netevo.rnd_uniform_node_states (G, [(3.0, 10.0), (3.0, 10.0), (3.0, 10.0)]) # Edges all start with a very weak strength netevo.rnd_uniform_edge_states (G, [(0.3, 0.3)]) # Our pinning node has no dynamics just fixed states that change G.node[12]['state'] = [30.0, 30.0, 30.0] G.node[12]['dyn'] = pinner_node_dyn #========================================= # DEFINE THE VISUAL REPORTER #========================================= # Turn on animation in pylab # http://stackoverflow.com/questions/8965055/basic-animation-with-matplotlibs-pyplot pylab.ion() # Create the figure to display the visualization
# Create an empty graph (undirected) G2 = nx.Graph() # We only need node dynamics G2.graph["node_dyn"] = True G2.graph["edge_dyn"] = False # Create the network of n nodes connected in a ring n_nodes = 4 G2.add_node(0) G2.node[0]["dyn"] = kuramoto_node_dyn for i in range(1, n_nodes): # Create the node G2.add_node(i) # Set the dynamics of the new node G2.node[i]["dyn"] = kuramoto_node_dyn # Connect it to the previous node in the ring G2.add_edge(i - 1, i) # Finish the ring G2.add_edge(i, 0) # Set the initial state to a random number in the range (0, 6.0) netevo.rnd_uniform_node_states(G2, [(0.0, 6.0)]) # ========================================= # SIMULATE THE NETWORK DYNAMICS # ========================================= # Simulate the dynamics and print the state to the screen netevo.simulate_steps(G2, 100, netevo.state_reporter)