<jupyter_start><jupyter_text>Week 3 exercises Part 1  Questions 1* What's the problem with random networks as a model for real-world networks according to the argument in section 3.5 (near the end)?* List the four regimes that characterize random networks as a function of ⟨k⟩.* According to the book, why is it a problem for random networks (in terms of being a model for real-world networks) that the degree-dependent clustering C(k) decreases as a function of k in real-world networks?  Answers 1* Random networks are much les clustered than real-life networks. The arqument is made that there al large number of nodes with high degree (people with lots of "friends", well connected nodes). More than random networks asume. * let ⟨k⟩ be the avarage degree of nodes. The four regimes are:    * distribution of degrees of nodes (binomial or poisson)    * clustering     * mean    * variance * The same answer as the answer for question 1?<jupyter_code>import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
import random
%matplotlib inline<jupyter_output><empty_output><jupyter_text>1. First, let's use networkx to play around with WS graphs. Use nx.watts_strogatz_graph to generate 3 graphs with 500 nodes each, average degree = 4, and rewiring probablity p=0,0.1,and1. Calculate the average shortest path length ⟨d⟩ for each one. Describe what happens to the network when p=1.<jupyter_code># help(nx.watts_strogatz_graph)
avrg_short_path = []

for i in range(3):
    smlaworld_graph_1 = nx.watts_strogatz_graph(n=500,k=4,p=0.01)
    avrg_short_path.append(nx.average_shortest_path_length(smlaworld_graph_1))
    
print(avrg_short_path)

smlaworld_graph_1 = nx.watts_strogatz_graph(n=500,k=4,p=1)
print(nx.average_shortest_path_length(smlaworld_graph_1))


# G = nx.complete_graph(5)
# nx.draw(G, with_labels=True, font_weight='bold')
# nx.average_shortest_path_length(G)<jupyter_output>[21.787094188376752, 21.097739478957916, 25.277002004008015]
4.786244488977956<jupyter_text>When we increese the number probabbility of crossing to 1 (so it always happens), The avarage length of shorthest path is decreased significantly. (In our case from length of arround 22 nodes between any 2 nodes, to arround 5 nodes)<jupyter_code>P = [0,0.01,0.03,0.05,0.1,0.2]
res = []

for p in P:
    trres = []
    for _ in range(50):
        trres.append(nx.average_shortest_path_length(nx.watts_strogatz_graph(n=500,k=4,p=p)))
    trres = np.array(trres)
    
    res.append((np.average(trres),np.std(trres)))
    
print(res)

plt.errorbar(P,[i[0] for i in res],yerr=[i[1] for i in res],color="b",ecolor="r")
plt.show()<jupyter_output><empty_output><jupyter_text>Part 2 * What are the three slope dependent regimes of complex networks with power-law degree distributions? Briefly describe each one. (You will have to skim chp 5.7 to answer this one).* What are the three regimes we find in non-linear preferential attachement? (chapter 5) Briefly describe each one.<jupyter_code>def create_Barabas_Albert_graph(n):
    G = nx.Graph()
    G.add_node(0)
    
    nx.draw(G)
#create_Barabas_Albert_graph(1)

help(random.choice)

a = {0:0,100:0}
for i in range(1000):
    k = random.choice([0,100])
    a[k] += 1
    
print(a)<jupyter_output>Help on method choice in module random:

choice(seq) method of random.Random instance
    Choose a random element from a non-empty sequence.

{0: 487, 100: 513}
{'fraction_non_alphanumeric': 0.09288653733098177, 'fraction_numerical': 0.047325102880658436, 'mean_word_length': 4.907986111111111, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '319477', 'license': 'MIT', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1155, 'n_words': 381, 'path': 'class_work/week_03/Untitled.ipynb', 'repo_name': 'LukaAvbreht/socialgraphs2019', 'size': '3402'}