rm CondaPkg environment

This commit is contained in:
ton
2023-04-06 13:53:47 +07:00
parent 0a57ed7884
commit c43d949309
3329 changed files with 5725 additions and 447022 deletions

View File

@@ -1,7 +1,7 @@
"""
=====================
======================
Betweenness Centrality
=====================
======================
Betweenness centrality measures of positive gene functional associations
using WormNet v.3-GS.

View File

@@ -14,7 +14,7 @@ The graph is bipartite (clubs, women).
"""
import matplotlib.pyplot as plt
import networkx as nx
import networkx.algorithms.bipartite as bipartite
from networkx.algorithms import bipartite
G = nx.davis_southern_women_graph()
women = G.graph["top"]
@@ -30,7 +30,7 @@ print("#Friends, Member")
for w in women:
print(f"{W.degree(w)} {w}")
# project bipartite graph onto women nodes keeping number of co-occurence
# project bipartite graph onto women nodes keeping number of co-occurrence
# the degree computed is weighted and counts the total number of shared contacts
W = bipartite.weighted_projected_graph(G, women)
print()

View File

@@ -38,7 +38,7 @@ original_graph.add_edges_from(
("A", "6"),
]
)
base_options = dict(with_labels=True, edgecolors="black")
base_options = {"with_labels": True, "edgecolors": "black"}
pos = {
"3": (0, 1),
"2": (0, 2),
@@ -85,7 +85,7 @@ nx.draw_networkx(
pos=nonexp_pos,
node_color=nonexp_node_colors,
node_size=nonexp_node_sizes,
**base_options
**base_options,
)
plt.tight_layout()

View File

@@ -0,0 +1,79 @@
"""
=======================================
Community Detection using Girvan-Newman
=======================================
This example shows the detection of communities in the Zachary Karate
Club dataset using the Girvan-Newman method.
We plot the change in modularity as important edges are removed.
Graph is coloured and plotted based on community detection when number
of iterations are 1 and 4 respectively.
"""
import networkx as nx
import pandas as pd
import matplotlib.pyplot as plt
# Load karate graph and find communities using Girvan-Newman
G = nx.karate_club_graph()
communities = list(nx.community.girvan_newman(G))
# Modularity -> measures the strength of division of a network into modules
modularity_df = pd.DataFrame(
[
[k + 1, nx.community.modularity(G, communities[k])]
for k in range(len(communities))
],
columns=["k", "modularity"],
)
# function to create node colour list
def create_community_node_colors(graph, communities):
number_of_colors = len(communities[0])
colors = ["#D4FCB1", "#CDC5FC", "#FFC2C4", "#F2D140", "#BCC6C8"][:number_of_colors]
node_colors = []
for node in graph:
current_community_index = 0
for community in communities:
if node in community:
node_colors.append(colors[current_community_index])
break
current_community_index += 1
return node_colors
# function to plot graph with node colouring based on communities
def visualize_communities(graph, communities, i):
node_colors = create_community_node_colors(graph, communities)
modularity = round(nx.community.modularity(graph, communities), 6)
title = f"Community Visualization of {len(communities)} communities with modularity of {modularity}"
pos = nx.spring_layout(graph, k=0.3, iterations=50, seed=2)
plt.subplot(3, 1, i)
plt.title(title)
nx.draw(
graph,
pos=pos,
node_size=1000,
node_color=node_colors,
with_labels=True,
font_size=20,
font_color="black",
)
fig, ax = plt.subplots(3, figsize=(15, 20))
# Plot graph with colouring based on communities
visualize_communities(G, communities[0], 1)
visualize_communities(G, communities[3], 2)
# Plot change in modularity as the important edges are removed
modularity_df.plot.bar(
x="k",
ax=ax[2],
color="#F2D140",
title="Modularity Trend for Girvan-Newman Community Detection",
)
plt.show()

View File

@@ -0,0 +1,44 @@
"""
=======================
Maximum Independent Set
=======================
An independent set is a set of vertices in a graph where no two vertices in the
set are adjacent. The maximum independent set is the independent set of largest
possible size for a given graph.
"""
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
from networkx.algorithms import approximation as approx
G = nx.Graph(
[
(1, 2),
(7, 2),
(3, 9),
(3, 2),
(7, 6),
(5, 2),
(1, 5),
(2, 8),
(10, 2),
(1, 7),
(6, 1),
(6, 9),
(8, 4),
(9, 4),
]
)
I = approx.maximum_independent_set(G)
print(f"Maximum independent set of G: {I}")
pos = nx.spring_layout(G, seed=39299899)
nx.draw(
G,
pos=pos,
with_labels=True,
node_color=["tab:red" if n in I else "tab:blue" for n in G],
)

View File

@@ -16,18 +16,18 @@ import matplotlib.pyplot as plt
nodes = {
"A": dict(color="Red"),
"B": dict(color="Red"),
"C": dict(color="Red"),
"D": dict(color="Red"),
"E": dict(color="Blue"),
"F": dict(color="Blue"),
"G": dict(color="Blue"),
"H": dict(color="Blue"),
"I": dict(color="Yellow"),
"J": dict(color="Yellow"),
"K": dict(color="Yellow"),
"L": dict(color="Yellow"),
"A": {"color": "Red"},
"B": {"color": "Red"},
"C": {"color": "Red"},
"D": {"color": "Red"},
"E": {"color": "Blue"},
"F": {"color": "Blue"},
"G": {"color": "Blue"},
"H": {"color": "Blue"},
"I": {"color": "Yellow"},
"J": {"color": "Yellow"},
"K": {"color": "Yellow"},
"L": {"color": "Yellow"},
}
edges = [
("A", "B", "Strong"),
@@ -50,7 +50,7 @@ original_graph.add_edges_from((u, v, {"type": label}) for u, v, label in edges)
plt.suptitle("SNAP Summarization")
base_options = dict(with_labels=True, edgecolors="black", node_size=500)
base_options = {"with_labels": True, "edgecolors": "black", "node_size": 500}
ax1 = plt.subplot(1, 2, 1)
plt.title(
@@ -101,7 +101,7 @@ nx.draw_networkx(
pos=summary_pos,
node_color=node_colors,
width=edge_weights,
**base_options
**base_options,
)
plt.tight_layout()

View File

@@ -81,7 +81,7 @@ print(f"\nFrom a total of {len(openings)} different openings,")
print("the following games used the Sicilian opening")
print('with the Najdorff 7...Qb6 "Poisoned Pawn" variation.\n')
for (white, black, game_info) in G.edges(data=True):
for white, black, game_info in G.edges(data=True):
if game_info["ECO"] == "B97":
summary = f"{white} vs {black}\n"
for k, v in game_info.items():
@@ -97,7 +97,7 @@ edgewidth = [len(G.get_edge_data(u, v)) for u, v in H.edges()]
# node size is proportional to number of games won
wins = dict.fromkeys(G.nodes(), 0.0)
for (u, v, d) in G.edges(data=True):
for u, v, d in G.edges(data=True):
r = d["Result"].split("-")
if r[0] == "1":
wins[u] += 1.0

View File

@@ -79,7 +79,7 @@ print(G)
H = nx.Graph()
for v in G:
H.add_node(v)
for (u, v, d) in G.edges(data=True):
for u, v, d in G.edges(data=True):
if d["weight"] < 300:
H.add_edge(u, v)
@@ -110,11 +110,11 @@ try:
# NOTE: When using cartopy, use matplotlib directly rather than nx.draw
# to take advantage of the cartopy transforms
ax.scatter(
*np.array([v for v in G.position.values()]).T,
*np.array(list(G.position.values())).T,
s=[G.population[v] for v in H],
c=node_color,
transform=ccrs.PlateCarree(),
zorder=100 # Ensure nodes lie on top of edges/state lines
zorder=100, # Ensure nodes lie on top of edges/state lines
)
# Plot edges between the cities
for edge in H.edges():

View File

@@ -25,7 +25,7 @@ def multilayered_graph(*subset_sizes):
extents = nx.utils.pairwise(itertools.accumulate((0,) + subset_sizes))
layers = [range(start, end) for start, end in extents]
G = nx.Graph()
for (i, layer) in enumerate(layers):
for i, layer in enumerate(layers):
G.add_nodes_from(layer, layer=i)
for layer1, layer2 in nx.utils.pairwise(layers):
G.add_edges_from(itertools.product(layer1, layer2))

View File

@@ -43,7 +43,7 @@ def mbox_graph():
resent_ccs = msg.get_all("resent-cc", [])
all_recipients = getaddresses(tos + ccs + resent_tos + resent_ccs)
# now add the edges for this mail message
for (target_name, target_addr) in all_recipients:
for target_name, target_addr in all_recipients:
G.add_edge(source_addr, target_addr, message=msg)
return G
@@ -52,7 +52,7 @@ def mbox_graph():
G = mbox_graph()
# print edges with message subject
for (u, v, d) in G.edges(data=True):
for u, v, d in G.edges(data=True):
print(f"From: {u} To: {v} Subject: {d['message']['Subject']}")
pos = nx.spring_layout(G, iterations=10, seed=227)

Some files were not shown because too many files have changed in this diff Show More