<jupyter_start><jupyter_text>First create a Watts-Strogatz network with 100 nodes.<jupyter_code>N = 100
av_degree = 6
m = int(av_degree/2)

GWS = nx.watts_strogatz_graph(N, m,0.5)

# plot the network
pos = nx.fruchterman_reingold_layout(GWS);
plt.figure(figsize=(8,8));
plt.axis("off");
nx.draw_networkx_nodes(GWS, pos, node_size=100, node_color="black");
nx.draw_networkx_edges(GWS, pos, alpha=0.500);
plt.show();<jupyter_output><empty_output><jupyter_text>ConsensusA *Consensus_Simulation* object may be constructed with fixed graph topology inherent to it's dynamics function.<jupyter_code>CS = consensus.ConsensusSimulation(GWS,
                          consensus.distributed,    
                          [nx.laplacian_matrix(GWS).todense()])<jupyter_output><empty_output><jupyter_text>The disagreement and agreement are calculated by by<jupyter_code>print("Disagreement: ", CS.disagreement())
print("Agreement: ", CS.agreement())<jupyter_output>Disagreement:  37682.5
Agreement:  False<jupyter_text>The simulation is run and results plotted as follows<jupyter_code>CS.run_sim()
CS.plot()<jupyter_output><empty_output><jupyter_text>Let's also add some delay to the influence<jupyter_code>CS = consensus.ConsensusSimulation(GWS,
                          consensus.distributed,    
                          [nx.laplacian_matrix(GWS).todense()])
CS.run_sim_delay(delay=1)
CS.plot()<jupyter_output><empty_output><jupyter_text>Flocking<jupyter_code># could also leave Q and P for a default random initialisation
N=10
Q = np.sqrt(2500)*np.random.randn(N,2)
P = (5)*np.random.rand(N,2)-1

FS = consensus.Flock(number_of_agents=N,
           initial_position=Q,
           initial_velocity=P,
           inter_agent_distance=7,
           gamma_agent=True)

p = FS.plot(arrow_width=0.25)
plt.title("Initial state for flock following F2", fontsize=25)
# run the sim for 10 seconds and save all the data
FS.run_sim(T=100, save_data=True)
# plot the final state
q=FS.plot(arrow_width=0.1);
plt.title("A late state for a flock following F3", fontsize=25)
FS.velocity_angle_agreement(FS.P)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11773049645390071, 'fraction_numerical': 0.025059101654846337, 'mean_word_length': 4.8292011019283745, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '346916', 'license': 'MIT', 'n_tokens_mistral': 799, 'n_tokens_neox': 741, 'n_words': 141, 'path': 'Examples/.ipynb_checkpoints/Example-checkpoint.ipynb', 'repo_name': 'harveydevereux/Consensus', 'size': '2115'}