Skip to content

Instantly share code, notes, and snippets.

@MatheusR42
Last active October 31, 2020 20:48
Show Gist options
  • Save MatheusR42/ec9445e00e399a9ebfda3598f4900815 to your computer and use it in GitHub Desktop.
Save MatheusR42/ec9445e00e399a9ebfda3598f4900815 to your computer and use it in GitHub Desktop.
def createTable(variableToChange, graphFunc):
table = []
p = 0.05
n = 300
if variableToChange == "N":
for n in range(100, 1000, 50):
G = erdos_renyi_graph(n, p) if graphFunc == 'erdos_renyi_graph' else watts_strogatz_graph(n, 4, p)
table.append({
"N": n,
"Número de arestas": G.number_of_edges(),
"Grau médio": grau_medio(G),
"Coef. de agrupamento médio": nx.average_clustering(G),
"Distância média": nx.average_shortest_path_length(G) if nx.is_connected(G) else np.nan,
"Componentes conexos": nx.number_connected_components(G),
})
elif variableToChange == "P":
for p in range(5, 101, 5):
p = p / 100
G = erdos_renyi_graph(n, p) if graphFunc == 'erdos_renyi_graph' else watts_strogatz_graph(n, 4, p)
table.append({
"P": p,
"Número de arestas": G.number_of_edges(),
"Grau médio": grau_medio(G),
"Coef. de agrupamento médio": nx.average_clustering(G),
"Distância média": nx.average_shortest_path_length(G) if nx.is_connected(G) else np.nan,
"Componentes conexos": nx.number_connected_components(G),
})
return pd.DataFrame(table)
def plotTable(df, variableToChange):
for col in ["Grau médio","Coef. de agrupamento médio","Distância média","Componentes conexos"]:
dfToPlot = df.dropna(how = 'any') if col == "Distância média" else df
fig = plt.figure()
fig.patch.set_facecolor('w')
plt.plot(dfToPlot[variableToChange], dfToPlot[col])
plt.title(col)
plt.xlabel(variableToChange)
plt.ylabel(col)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment