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')
Esempio n. 2
0
#ims = []
plt.show()
def visual_reporter (G, t):
    # Clear the figure
    plt.clf()
    n_sizes = []
    # Calculate the sizes of the nodes (their state)
    for i in G.nodes():
        new_size = 100.0 * G.node[i]['state']
        if new_size < 1.0: new_size = 1
        n_sizes.append(new_size)
    # Draw the network and update the canvas
    nx.draw(G, pos, node_size=n_sizes, node_color='#A0CBE2', width=4, 
            with_labels=False)
    im = fig.canvas.draw()
    #im = plt.imshow()
    #im = plt.draw()
    #ims.append([im])


#=========================================
# SIMULATE THE DYNAMICS
#=========================================
    
# Simulate the dynamics (discrete-time) using the visual reporter
netevo.simulate_steps(G, 200, visual_reporter)
#ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True, repeat_delay=2000)

# Close the visualization
plt.close()
Esempio n. 3
0
# 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)