updated with nice outputs for review

main
Luca Lombardo 2 years ago
parent 3236e18d36
commit 1cfa9c6ed0

File diff suppressed because one or more lines are too long

@ -502,8 +502,8 @@ def create_random_graphs(G: nx.Graph, model = None, save = True) -> nx.Graph:
if model == "erdos_renyi": if model == "erdos_renyi":
G_random = nx.erdos_renyi_graph(G.number_of_nodes(), nx.density(G)) G_random = nx.erdos_renyi_graph(G.number_of_nodes(), nx.density(G))
print("Creating a random graph with the Erdos-Renyi model {}" .format(G.name)) print("Creating a random graph with the Erdos-Renyi model {}" .format(G.name))
print("Number of edges in the original graph: {}" .format(G.number_of_edges())) # print("Number of edges in the original graph: {}" .format(G.number_of_edges()))
print("Number of edges in the random graph: {}" .format(G_random.number_of_edges())) # print("Number of edges in the random graph: {}" .format(G_random.number_of_edges()))
G_random.name = G.name + " Erdos-Renyi" G_random.name = G.name + " Erdos-Renyi"
if save: if save:
@ -520,8 +520,8 @@ def create_random_graphs(G: nx.Graph, model = None, save = True) -> nx.Graph:
p = G.number_of_edges() / (G.number_of_nodes()) p = G.number_of_edges() / (G.number_of_nodes())
avg_degree = int(np.mean([d for n, d in G.degree()])) avg_degree = int(np.mean([d for n, d in G.degree()]))
G_random = nx.watts_strogatz_graph(G.number_of_nodes(), avg_degree, p) G_random = nx.watts_strogatz_graph(G.number_of_nodes(), avg_degree, p)
print("Number of edges in the original graph: {}" .format(G.number_of_edges())) # print("Number of edges in the original graph: {}" .format(G.number_of_edges()))
print("Number of edges in the random graph: {}" .format(G_random.number_of_edges())) # print("Number of edges in the random graph: {}" .format(G_random.number_of_edges()))
G_random.name = G.name + " Watts-Strogatz" G_random.name = G.name + " Watts-Strogatz"
if save: if save:
@ -635,7 +635,7 @@ def random_sample(graph: nx.Graph, k: float) -> nx.Graph:
The graph to sample The graph to sample
`k`: float `k`: float
The percentage of nodes to sample from the graph. The percentage of nodes to remove from the graph
Returns Returns
------- -------
@ -644,8 +644,7 @@ def random_sample(graph: nx.Graph, k: float) -> nx.Graph:
""" """
nodes = list(graph.nodes()) nodes = list(graph.nodes())
n = int(k*len(nodes)) nodes_sample = np.random.choice(nodes, size=int((1-k)*len(nodes)), replace=False)
nodes_sample = random.sample(nodes, n)
G = graph.subgraph(nodes_sample) G = graph.subgraph(nodes_sample)
@ -654,8 +653,6 @@ def random_sample(graph: nx.Graph, k: float) -> nx.Graph:
connected = max(nx.connected_components(G), key=len) connected = max(nx.connected_components(G), key=len)
G_connected = graph.subgraph(connected) G_connected = graph.subgraph(connected)
print(nx.is_connected(G_connected))
print("Number of nodes in the sampled graph: ", G.number_of_nodes()) print("Number of nodes in the sampled graph: ", G.number_of_nodes())
print("Number of edges in the sampled graph: ", G.number_of_edges()) print("Number of edges in the sampled graph: ", G.number_of_edges())

Loading…
Cancel
Save