๐ฆ๊ทธ๋ํ์ ํน์ ํ์ ๊ทธ๋ํ๋ฅผ ์ถ์ถํ๋ ์๊ณ ๋ฆฌ์ฆ, K-Core
Definition
- K-Core ์๊ณ ๋ฆฌ์ฆ์ ๊ทธ๋ํ ์ด๋ก ์์ ์ฌ์ฉ๋๋ ์๊ณ ๋ฆฌ์ฆ์ผ๋ก, ๊ทธ๋ํ์ ํน์ ๋ถ๋ถ์ ์ถ์ถํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
- K-Core๋ ๊ฐ ๋ ธ๋๊ฐ ์ต์ํ K๊ฐ์ ์ด์ ๋ ธ๋๋ฅผ ๊ฐ์ง๋ ์ต๋ ๋ถ๋ถ ๊ทธ๋ํ๋ฅผ ์๋ฏธํฉ๋๋ค.
Motivation
- ์์ ๋คํธ์ํฌ, ์๋ฌผํ์ ๋คํธ์ํฌ, ์ธํฐ๋ท ๊ตฌ์กฐ ๋ฑ ๋ค์ํ ๋ถ์ผ์์ ๋ฐ์ง๋ ํ์ ๊ตฌ์กฐ๋ฅผ ์๋ณํ๊ธฐ ์ํด ๋ฑ์ฅํ์ต๋๋ค. ๊ฐ์ธ์ ์ธ ๊ฒฝํ์์๋ FDS ๊ด๋ จ ์ฌ๊ธฐ๊ฑฐ๋๋ฅผ ์ง๋จ์ผ๋ก ํ๋ ์ ์ฒด๋ฅผ ํ์งํ๊ธฐ ์ํด์ ํ์ฉํ ๋ฐ ์์ต๋๋ค.
- ์ด๋ ๋คํธ์ํฌ์ ์ฃผ์ ๊ตฌ์ฑ ์์๋ฅผ ๋ถ์ํ๊ณ , ์ค์ํ ๋ ธ๋๋ค์ ์๋ณํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
Pros & Cons
Pros
- ๋ฐ์ง๋ ํ์ ๊ตฌ์กฐ ์๋ณ: ๊ทธ๋ํ ๋ด์์ ๋ฐ์ง๋ ํ์ ๊ตฌ์กฐ๋ฅผ ํจ์จ์ ์ผ๋ก ์๋ณํ ์ ์์ต๋๋ค.
- ์ค์ ๋ ธ๋ ์๋ณ: ๋คํธ์ํฌ ๋ด์์ ์ค์ํ ๋ ธ๋๋ฅผ ์๋ณํ๋ ๋ฐ ์ ์ฉํฉ๋๋ค.
- ๋ค์ํ ์์ฉ ๋ถ์ผ: ์์ ๋คํธ์ํฌ, ์๋ฌผํ์ ๋คํธ์ํฌ, ์ธํฐ๋ท ๊ตฌ์กฐ ๋ฑ ๋ค์ํ ๋ถ์ผ์ ์ ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
Cons
- ๋ณต์ก์ฑ: ํฐ ๊ทธ๋ํ์ ๋ํด K-Core๋ฅผ ๊ณ์ฐํ๋ ๊ฒ์ ๋ณต์กํ ์ ์์ต๋๋ค.
- ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ: ํฐ ๊ทธ๋ํ๋ฅผ ์ฒ๋ฆฌํ ๋ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ด ๋ง์ ์ ์์ต๋๋ค.
- ์ ํ๋ ๋ฌธ์ : ๋ฐ์ง๋ ํ์ ๊ตฌ์กฐ๋ฅผ ์๋ณํ๋ ๊ณผ์ ์์ ์ผ๋ถ ์ค์ํ ๋ ธ๋๊ฐ ๋๋ฝ๋ ์ ์์ต๋๋ค.
Alternatiive
- Clique: ๊ทธ๋ํ ๋ด์์ ๋ชจ๋ ๋ ธ๋๊ฐ ์๋ก ์ฐ๊ฒฐ๋ ๋ถ๋ถ ๊ทธ๋ํ๋ฅผ ์ฐพ๋ ์๊ณ ๋ฆฌ์ฆ.
- Community Detection: ๋คํธ์ํฌ ๋ด์์ ์ปค๋ฎค๋ํฐ๋ฅผ ๋ฐ๊ฒฌํ๋ ์๊ณ ๋ฆฌ์ฆ.
- Modularity Optimization: ๋คํธ์ํฌ์ ๋ชจ๋์ฑ์ ์ต์ ํํ์ฌ ์ปค๋ฎค๋ํฐ๋ฅผ ์ฐพ๋ ๋ฐฉ๋ฒ
Sample
import networkx as nx
import matplotlib.pyplot as plt
from networkx.algorithms.clique import find_cliques
from networkx.algorithms.community import greedy_modularity_communities
def compute_and_visualize_k_core(edges, k):
# ๊ทธ๋ํ ์์ฑ
G = nx.Graph()
G.add_edges_from(edges)
# K-Core ๊ณ์ฐ
k_core = nx.k_core(G, k=k)
# ๊ทธ๋ํ ์๊ฐํ
pos = nx.spring_layout(G)
plt.figure(figsize=(8, 6))
nx.draw(G, pos, with_labels=True, node_color='lightblue', edge_color='gray')
nx.draw(k_core, pos, with_labels=True, node_color='red', edge_color='black')
plt.title(f"K-Core (k={k}) of the Graph")
plt.show()
return k_core.nodes(), k_core.edges()
def find_and_visualize_cliques(edges):
# ๊ทธ๋ํ ์์ฑ
G = nx.Graph()
G.add_edges_from(edges)
# Clique ๊ณ์ฐ
cliques = list(find_cliques(G))
# ๊ทธ๋ํ ์๊ฐํ
pos = nx.spring_layout(G)
plt.figure(figsize=(8, 6))
nx.draw(G, pos, with_labels=True, node_color='lightblue', edge_color='gray')
for clique in cliques:
nx.draw_networkx_nodes(G, pos, nodelist=clique, node_color='red')
plt.title("Cliques in the Graph")
plt.show()
return cliques
def detect_and_visualize_communities(edges):
# ๊ทธ๋ํ ์์ฑ
G = nx.Graph()
G.add_edges_from(edges)
# ์ปค๋ฎค๋ํฐ ๊ฐ์ง
communities = list(greedy_modularity_communities(G))
# ๊ทธ๋ํ ์๊ฐํ
pos = nx.spring_layout(G)
plt.figure(figsize=(8, 6))
nx.draw(G, pos, with_labels=True, node_color='lightblue', edge_color='gray')
colors = ['red', 'blue', 'green', 'orange', 'purple']
for i, community in enumerate(communities):
nx.draw_networkx_nodes(G, pos, nodelist=list(community), node_color=colors[i % len(colors)])
plt.title("Communities in the Graph")
plt.show()
return communities
# ์์ ๋ฐ์ดํฐ
edges = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 4)]
# K-Core ๊ฒฐ๊ณผ
k = 2
nodes, edges = compute_and_visualize_k_core(edges, k)
print("Nodes in k-core:", nodes)
print("Edges in k-core:", edges)
# Clique ๊ฒฐ๊ณผ
cliques = find_and_visualize_cliques(edges)
print("Cliques in the graph:", cliques)
# Community Detection ๊ฒฐ๊ณผ
communities = detect_and_visualize_communities(edges)
print("Communities in the graph:", communities)