Spaces:
Sleeping
Sleeping
初步结果
Browse files- app.py +5 -3
- hyper_edges.json +0 -0
- hyper_edges_nips.json +0 -0
- labels_history.json +0 -0
- labels_history_nips.json +0 -0
- my_pages/page1.py +15 -69
- my_pages/page2.py +134 -2
- my_pages/page3.py +90 -2
- utils/streamlit_hypergraph.py +76 -0
app.py
CHANGED
@@ -22,11 +22,13 @@ def main():
|
|
22 |
# https://www.cnblogs.com/wang_yb/p/18502232
|
23 |
|
24 |
page1 = st.Page("my_pages/page1.py", title="无监督聚类动态变化", icon="📊", default=True)
|
25 |
-
page2 = st.Page("my_pages/page2.py", title="
|
26 |
-
page3 = st.Page("my_pages/page3.py", title="
|
27 |
# page3 = st.Page("dev/test.py", title="第三个子应用", icon="📉")
|
28 |
|
29 |
-
pg = st.navigation([page1, page2,
|
|
|
|
|
30 |
pg.run()
|
31 |
# pass
|
32 |
|
|
|
22 |
# https://www.cnblogs.com/wang_yb/p/18502232
|
23 |
|
24 |
page1 = st.Page("my_pages/page1.py", title="无监督聚类动态变化", icon="📊", default=True)
|
25 |
+
page2 = st.Page("my_pages/page2.py", title="超图神经网络训练过程", icon="📈")
|
26 |
+
# page3 = st.Page("my_pages/page3.py", title="超图构建分析-cora", icon="📉")
|
27 |
# page3 = st.Page("dev/test.py", title="第三个子应用", icon="📉")
|
28 |
|
29 |
+
pg = st.navigation([page1, page2,
|
30 |
+
# page3
|
31 |
+
])
|
32 |
pg.run()
|
33 |
# pass
|
34 |
|
hyper_edges.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
hyper_edges_nips.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
labels_history.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
labels_history_nips.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
my_pages/page1.py
CHANGED
@@ -10,10 +10,12 @@ from io import BytesIO
|
|
10 |
import time
|
11 |
from utils.data_processor import load_data, process_data, build_hyperedges
|
12 |
from utils.visualizer import visualize_gmm, visualize_ratings
|
13 |
-
|
|
|
|
|
14 |
|
15 |
def main():
|
16 |
-
st.title("NeurIPS
|
17 |
|
18 |
# 自动播放
|
19 |
slider_max = 10
|
@@ -34,7 +36,6 @@ def main():
|
|
34 |
button_label = "开始拟合"
|
35 |
st.button(button_label, on_click=toggle_play, key="play_button")
|
36 |
# 播放速度
|
37 |
-
speed = st.slider("拟合速度", min_value=0.1, max_value=2.0, value=1.0, step=0.1, key="speed_slider")
|
38 |
# speed = st.slider("播放速度", min_value=0.1, max_value=2.0, value=1.0, step=0.1, key="speed_slider")
|
39 |
# 主页面布局
|
40 |
|
@@ -53,6 +54,7 @@ def main():
|
|
53 |
# 使用 sidebar 控制参数
|
54 |
with st.sidebar:
|
55 |
st.header("控制面板")
|
|
|
56 |
draw_width = st.slider("绘图宽度", min_value=3, max_value=20, value=6, step=1, key="draw_width")
|
57 |
draw_height = st.slider("绘图高度",min_value=3, max_value=20, value=6, step=1, key="draw_height")
|
58 |
|
@@ -74,7 +76,8 @@ def main():
|
|
74 |
# Top K Clusters
|
75 |
if display_option == "Top K Clusters":
|
76 |
max_k = 5
|
77 |
-
top_k = st.slider("选择 K 值", min_value=1, max_value=max_k,
|
|
|
78 |
top_p = None
|
79 |
else:
|
80 |
top_k = None
|
@@ -88,73 +91,16 @@ def main():
|
|
88 |
|
89 |
# print(hyperedges)
|
90 |
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
draw_dual = st.toggle("对偶翻转", value=False, key="draw_dual")
|
95 |
-
euler_first = st.toggle("先看Euler Diagram", value=True, key="euler_first")
|
96 |
|
97 |
-
|
98 |
-
st.
|
99 |
-
|
100 |
-
|
101 |
-
fill_edges = st.toggle("填充超边", value=True, key="fill_edges")
|
102 |
-
with col2:
|
103 |
-
toplexes = st.toggle("只保留未被包含的边(toplexes)", value=False, key="toplexes")
|
104 |
-
with col3:
|
105 |
-
with_edge_labels = st.toggle("不看边名", value=False, key="with_edge_labels")
|
106 |
-
|
107 |
-
|
108 |
-
col1, col2 = st.columns(2)
|
109 |
-
captions = ["论文聚类超图", "论文聚类对偶超图"]
|
110 |
-
|
111 |
-
if 'poses' not in st.session_state:
|
112 |
-
st.session_state.poses = [None, None]
|
113 |
-
if draw_dual:
|
114 |
-
hypergraph = hypergraph.dual()
|
115 |
-
captions = ["论文聚类对偶超图", "论文聚类超图"]
|
116 |
-
# st.session_state.poses = [st.session_state.poses[1], st.session_state.poses[0]]
|
117 |
-
|
118 |
-
with col1:
|
119 |
-
hypergraph_image, st.session_state.poses[0] = draw_hypergraph(hypergraph, draw_dual=False,
|
120 |
-
fill_edges=fill_edges, toplexes=toplexes,
|
121 |
-
with_edge_labels=with_edge_labels
|
122 |
-
# pos=st.session_state.poses[0]
|
123 |
-
,draw_width=draw_width, draw_height=draw_height
|
124 |
-
)
|
125 |
-
st.image(hypergraph_image, caption = captions[0], use_container_width=True)
|
126 |
-
|
127 |
-
with col2:
|
128 |
-
hypergraph_image, st.session_state.poses[1] = draw_hypergraph(hypergraph, draw_dual=True,
|
129 |
-
fill_edges=fill_edges, toplexes=toplexes,
|
130 |
-
with_edge_labels=with_edge_labels
|
131 |
-
# pos=st.session_state.poses[1]
|
132 |
-
,draw_width=draw_width, draw_height=draw_height
|
133 |
-
)
|
134 |
-
st.image(hypergraph_image, caption =captions[1], use_container_width=True)
|
135 |
-
|
136 |
-
def new_visualization(hypergraph):
|
137 |
-
st.subheader("新型可视化")
|
138 |
-
col1, col2 = st.columns(2)
|
139 |
-
with col1:
|
140 |
-
fig, ax = plt.subplots(figsize=(draw_width, draw_height))
|
141 |
-
hnx.draw_bipartite_using_euler(hypergraph)
|
142 |
-
st.image(pyplot_fig_to_buffer(plt.gcf()), caption="双列二分图可视化", use_container_width=True)
|
143 |
-
with col2:
|
144 |
-
fig, ax = plt.subplots(figsize=(draw_width, draw_height))
|
145 |
-
hnx.draw_incidence_upset(hypergraph)
|
146 |
-
st.image(pyplot_fig_to_buffer(plt.gcf()), caption="Incidence/UpSet 可视化", use_container_width=True)
|
147 |
-
|
148 |
-
if euler_first:
|
149 |
-
euler_visualization(hypergraph)
|
150 |
-
new_visualization(hypergraph)
|
151 |
-
else:
|
152 |
-
new_visualization(hypergraph)
|
153 |
-
euler_visualization(hypergraph)
|
154 |
-
|
155 |
-
st.header("高斯混合分布聚类结果")
|
156 |
-
fig_gmm = visualize_gmm(sampled_df, iteration)
|
157 |
-
st.plotly_chart(fig_gmm, use_container_width=True)
|
158 |
|
159 |
# 显示采样论文的详细信息
|
160 |
st.header("采样论文详细信息")
|
|
|
10 |
import time
|
11 |
from utils.data_processor import load_data, process_data, build_hyperedges
|
12 |
from utils.visualizer import visualize_gmm, visualize_ratings
|
13 |
+
|
14 |
+
from utils.streamlit_hypergraph import hypergraph_visualization_component
|
15 |
+
|
16 |
|
17 |
def main():
|
18 |
+
st.title("NeurIPS 2024 Bench Paper 高斯混合聚类分析")
|
19 |
|
20 |
# 自动播放
|
21 |
slider_max = 10
|
|
|
36 |
button_label = "开始拟合"
|
37 |
st.button(button_label, on_click=toggle_play, key="play_button")
|
38 |
# 播放速度
|
|
|
39 |
# speed = st.slider("播放速度", min_value=0.1, max_value=2.0, value=1.0, step=0.1, key="speed_slider")
|
40 |
# 主页面布局
|
41 |
|
|
|
54 |
# 使用 sidebar 控制参数
|
55 |
with st.sidebar:
|
56 |
st.header("控制面板")
|
57 |
+
speed = st.slider("拟合速度", min_value=0.1, max_value=2.0, value=1.0, step=0.1, key="speed_slider")
|
58 |
draw_width = st.slider("绘图宽度", min_value=3, max_value=20, value=6, step=1, key="draw_width")
|
59 |
draw_height = st.slider("绘图高度",min_value=3, max_value=20, value=6, step=1, key="draw_height")
|
60 |
|
|
|
76 |
# Top K Clusters
|
77 |
if display_option == "Top K Clusters":
|
78 |
max_k = 5
|
79 |
+
top_k = st.slider("选择 K 值", min_value=1, max_value=max_k,
|
80 |
+
value=1, step=1)
|
81 |
top_p = None
|
82 |
else:
|
83 |
top_k = None
|
|
|
91 |
|
92 |
# print(hyperedges)
|
93 |
|
94 |
+
show_hypergraph = st.checkbox("显示超图", value=True, key="show_hyperedges")
|
95 |
+
show_gaussian = st.checkbox("显示高斯分布", value=False, key="show_gaussian")
|
96 |
|
97 |
+
if show_hypergraph:
|
98 |
+
hypergraph_visualization_component(hypergraph, draw_width, draw_height)
|
|
|
|
|
99 |
|
100 |
+
if show_gaussian:
|
101 |
+
st.header("高斯混合分布聚类结果")
|
102 |
+
fig_gmm = visualize_gmm(sampled_df, iteration)
|
103 |
+
st.plotly_chart(fig_gmm, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
# 显示采样论文的详细信息
|
106 |
st.header("采样论文详细信息")
|
my_pages/page2.py
CHANGED
@@ -1,7 +1,139 @@
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def main():
|
4 |
-
st.
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
main()
|
|
|
1 |
+
from typing import Dict, List
|
2 |
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
import plotly.express as px
|
6 |
+
import hypernetx as hnx
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
9 |
+
from io import BytesIO
|
10 |
+
import time
|
11 |
+
import json
|
12 |
+
from utils.data_processor import process_data, build_hyperedges
|
13 |
+
from utils.visualizer import visualize_gmm, visualize_ratings
|
14 |
+
from utils.streamlit_hypergraph import hypergraph_visualization_component
|
15 |
+
|
16 |
+
def load_json_data(file_path: str):
|
17 |
+
"""从JSON文件中加载数据"""
|
18 |
+
with open(file_path, 'r') as f:
|
19 |
+
data = json.load(f)
|
20 |
+
return data
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
|
25 |
def main():
|
26 |
+
with st.sidebar:
|
27 |
+
st.header("控制面板")
|
28 |
+
dataset_selection = st.selectbox(
|
29 |
+
"选择可视化的数据集",
|
30 |
+
["NeurIPS 2024 Bench", "Cora Co-Author"]
|
31 |
+
)
|
32 |
+
st.title(f"{dataset_selection} Author-Paper 超图可视化分析")
|
33 |
+
|
34 |
+
# 自动播放状态
|
35 |
+
slider_max = 200
|
36 |
+
if 'play_state' not in st.session_state:
|
37 |
+
st.session_state.play_state = False
|
38 |
+
if 'iteration' not in st.session_state:
|
39 |
+
st.session_state.iteration = 10
|
40 |
+
|
41 |
+
# 定义回调函数来切换播放状态
|
42 |
+
def toggle_play():
|
43 |
+
if not st.session_state.play_state and st.session_state.iteration == slider_max:
|
44 |
+
st.session_state.iteration = 10 # 重置迭代次数
|
45 |
+
st.session_state.play_state = not st.session_state.play_state
|
46 |
+
|
47 |
+
# 创建播放/暂停按钮
|
48 |
+
if st.session_state.play_state:
|
49 |
+
button_label = "暂停"
|
50 |
+
else:
|
51 |
+
button_label = "开始拟合"
|
52 |
+
st.button(button_label, on_click=toggle_play, key="play_button")
|
53 |
+
|
54 |
+
# 显示迭代次数滑条
|
55 |
+
iteration = st.slider("迭代步骤", min_value=10, max_value=slider_max,
|
56 |
+
value=st.session_state.iteration, step=10,
|
57 |
+
key="iteration_slider")
|
58 |
+
|
59 |
+
# 从JSON文件加载数据
|
60 |
+
# 假设JSON文件路径为"authors_papers.json"
|
61 |
+
if "hyper_edges" not in st.session_state or "labels_history" not in st.session_state:
|
62 |
+
if dataset_selection == "NeurIPS 2024 Bench":
|
63 |
+
json_hyper_edges = load_json_data("hyper_edges_nips.json")
|
64 |
+
json_labels_history:list = load_json_data("labels_history_nips.json")
|
65 |
+
elif dataset_selection == "Cora Co-Author":
|
66 |
+
json_hyper_edges = load_json_data("hyper_edges.json")
|
67 |
+
json_labels_history:list = load_json_data("labels_history.json")
|
68 |
+
else:
|
69 |
+
st.error("未知数据集")
|
70 |
+
raise ValueError("Unknown dataset selected")
|
71 |
+
|
72 |
+
st.session_state.hyper_edges = json_hyper_edges
|
73 |
+
|
74 |
+
st.session_state.labels_history = {
|
75 |
+
item['epoch']:item["labels"]
|
76 |
+
for item in json_labels_history
|
77 |
+
}
|
78 |
+
|
79 |
+
|
80 |
+
# 使用 sidebar 控制参数
|
81 |
+
with st.sidebar:
|
82 |
+
speed = st.slider("拟合速度", min_value=0.1, max_value=2.0, value=1.0, step=0.1, key="speed_slider")
|
83 |
+
draw_width = st.slider("绘图宽度", min_value=3, max_value=20, value=6, step=1, key="draw_width")
|
84 |
+
draw_height = st.slider("绘图高度", min_value=3, max_value=20, value=6, step=1, key="draw_height")
|
85 |
+
|
86 |
+
max_samples = len(st.session_state.hyper_edges)
|
87 |
+
num_samples = st.slider("选择采样作者数量", min_value=1,
|
88 |
+
max_value=min(100, max_samples), value=min(10, max_samples), step=1)
|
89 |
+
|
90 |
+
# 采样部分作者
|
91 |
+
sampled_authors = np.random.choice(st.session_state.hyper_edges, size=num_samples, replace=False)
|
92 |
+
|
93 |
+
show_labels = st.checkbox("展示分类结果", value=True, key="show_labels")
|
94 |
+
|
95 |
+
def paper_list_to_types(iteration:int, paper_list:List[int]) -> List[str]:
|
96 |
+
"""将论文列表转换为类型列表"""
|
97 |
+
labels:List[int] = st.session_state.labels_history[str(iteration)]
|
98 |
+
return [labels[paper] for paper in paper_list]
|
99 |
+
|
100 |
+
|
101 |
+
sampled_data = {list(author_dict.keys()
|
102 |
+
)[0]: list(author_dict.values()
|
103 |
+
)[0] if not show_labels else paper_list_to_types(iteration, list(author_dict.values())[0])
|
104 |
+
for author_dict in sampled_authors}
|
105 |
+
|
106 |
+
# 构建超边
|
107 |
+
hyperedges = sampled_data
|
108 |
+
|
109 |
+
|
110 |
+
# 修改 类别信息
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
+
|
115 |
+
hypergraph = hnx.Hypergraph(hyperedges)
|
116 |
+
|
117 |
+
show_hypergraph = st.checkbox("显示超图", value=True, key="show_hyperedges")
|
118 |
+
|
119 |
+
if show_hypergraph:
|
120 |
+
hypergraph_visualization_component(hypergraph, draw_width, draw_height)
|
121 |
+
|
122 |
+
# 显示采样作者的详细信息
|
123 |
+
st.header("采样作者详细信息")
|
124 |
+
authors_df = pd.DataFrame([(author, len(papers)) for author, papers in sampled_data.items()],
|
125 |
+
columns=["作者", "论文数量"])
|
126 |
+
st.dataframe(authors_df)
|
127 |
+
|
128 |
+
# 自动播放功能
|
129 |
+
if st.session_state.play_state:
|
130 |
+
with st.spinner("正在播放..."):
|
131 |
+
if st.session_state.iteration < slider_max:
|
132 |
+
st.session_state.iteration += 10
|
133 |
+
st.write(f"当前迭代次数: {st.session_state.iteration}")
|
134 |
+
time.sleep(1/speed) # 根据速度调整等待时间
|
135 |
+
st.rerun()
|
136 |
+
else:
|
137 |
+
st.session_state.play_state = False
|
138 |
|
139 |
main()
|
my_pages/page3.py
CHANGED
@@ -1,7 +1,95 @@
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def main():
|
4 |
-
st.title("
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
main()
|
|
|
1 |
+
from typing import Dict, List
|
2 |
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
import plotly.express as px
|
6 |
+
import hypernetx as hnx
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
9 |
+
from io import BytesIO
|
10 |
+
import time
|
11 |
+
import json
|
12 |
+
from utils.data_processor import process_data, build_hyperedges
|
13 |
+
from utils.visualizer import visualize_gmm, visualize_ratings
|
14 |
+
from utils.streamlit_hypergraph import hypergraph_visualization_component
|
15 |
+
|
16 |
+
def load_json_data(file_path: str) -> Dict[str, List[int]]:
|
17 |
+
"""从JSON文件中加载数据"""
|
18 |
+
with open(file_path, 'r') as f:
|
19 |
+
data = json.load(f)
|
20 |
+
return data
|
21 |
|
22 |
def main():
|
23 |
+
st.title("CORA Author-Paper 超图可视化分析")
|
24 |
+
|
25 |
+
# 自动播放状态
|
26 |
+
slider_max = 10
|
27 |
+
if 'play_state' not in st.session_state:
|
28 |
+
st.session_state.play_state = False
|
29 |
+
if 'iteration' not in st.session_state:
|
30 |
+
st.session_state.iteration = 0
|
31 |
+
|
32 |
+
# 定义回调函数来切换播放状态
|
33 |
+
def toggle_play():
|
34 |
+
if not st.session_state.play_state and st.session_state.iteration == slider_max:
|
35 |
+
st.session_state.iteration = 0 # 重置迭代次数
|
36 |
+
st.session_state.play_state = not st.session_state.play_state
|
37 |
+
|
38 |
+
# 创建播放/暂停按钮
|
39 |
+
if st.session_state.play_state:
|
40 |
+
button_label = "暂停"
|
41 |
+
else:
|
42 |
+
button_label = "开始拟合"
|
43 |
+
st.button(button_label, on_click=toggle_play, key="play_button")
|
44 |
+
|
45 |
+
# 显示迭代次数滑条
|
46 |
+
iteration = st.slider("迭代步骤", min_value=1, max_value=slider_max,
|
47 |
+
value=st.session_state.iteration, step=1,
|
48 |
+
key="iteration_slider")
|
49 |
+
|
50 |
+
# 从JSON文件加载数据
|
51 |
+
# 假设JSON文件路径为"authors_papers.json"
|
52 |
+
data = load_json_data("hyper_edges.json")
|
53 |
+
|
54 |
+
# 使用 sidebar 控制参数
|
55 |
+
with st.sidebar:
|
56 |
+
st.header("控制面板")
|
57 |
+
speed = st.slider("拟合速度", min_value=0.1, max_value=2.0, value=1.0, step=0.1, key="speed_slider")
|
58 |
+
draw_width = st.slider("绘图宽度", min_value=3, max_value=20, value=6, step=1, key="draw_width")
|
59 |
+
draw_height = st.slider("绘图高度", min_value=3, max_value=20, value=6, step=1, key="draw_height")
|
60 |
+
|
61 |
+
max_samples = len(data)
|
62 |
+
num_samples = st.slider("选择采样作者数量", min_value=1,
|
63 |
+
max_value=min(100, max_samples), value=min(10, max_samples), step=1)
|
64 |
+
|
65 |
+
# 采样部分作者
|
66 |
+
sampled_authors = np.random.choice(data, size=num_samples, replace=False)
|
67 |
+
sampled_data = {list(author_dict.keys())[0]: list(author_dict.values())[0] for author_dict in sampled_authors}
|
68 |
+
|
69 |
+
# 构建超边
|
70 |
+
hyperedges = sampled_data
|
71 |
+
hypergraph = hnx.Hypergraph(hyperedges)
|
72 |
+
|
73 |
+
show_hypergraph = st.checkbox("显示超图", value=True, key="show_hyperedges")
|
74 |
+
|
75 |
+
if show_hypergraph:
|
76 |
+
hypergraph_visualization_component(hypergraph, draw_width, draw_height)
|
77 |
+
|
78 |
+
# 显示采样作者的详细信息
|
79 |
+
st.header("采样作者详细信息")
|
80 |
+
authors_df = pd.DataFrame([(author, len(papers)) for author, papers in sampled_data.items()],
|
81 |
+
columns=["作者", "论文数量"])
|
82 |
+
st.dataframe(authors_df)
|
83 |
+
|
84 |
+
# 自动播放功能
|
85 |
+
if st.session_state.play_state:
|
86 |
+
with st.spinner("正在播放..."):
|
87 |
+
if st.session_state.iteration < slider_max:
|
88 |
+
st.session_state.iteration += 1
|
89 |
+
st.write(f"当前迭代次数: {st.session_state.iteration}")
|
90 |
+
time.sleep(1/speed) # 根据速度调整等待时间
|
91 |
+
st.rerun()
|
92 |
+
else:
|
93 |
+
st.session_state.play_state = False
|
94 |
|
95 |
main()
|
utils/streamlit_hypergraph.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from matplotlib import pyplot as plt
|
2 |
+
import streamlit as st
|
3 |
+
import hypernetx as hnx
|
4 |
+
from utils.hypergraph_drawer import draw_hypergraph, pyplot_fig_to_buffer
|
5 |
+
|
6 |
+
def hypergraph_visualization_component(hypergraph:hnx.Hypergraph,
|
7 |
+
draw_width:int,
|
8 |
+
draw_height:int):
|
9 |
+
"""
|
10 |
+
Visualize a hypergraph using Streamlit.
|
11 |
+
|
12 |
+
Parameters:
|
13 |
+
hypergraph (dict): A dictionary representing the hypergraph, where keys are nodes and values are lists of connected nodes.
|
14 |
+
"""
|
15 |
+
st.header("超图可视化")
|
16 |
+
|
17 |
+
draw_dual = st.toggle("对偶翻转", value=False, key="draw_dual")
|
18 |
+
euler_first = st.toggle("先看Euler Diagram", value=True, key="euler_first")
|
19 |
+
if draw_dual:
|
20 |
+
hypergraph = hypergraph.dual()
|
21 |
+
def euler_visualization(hypergraph):
|
22 |
+
st.subheader("Euler Diagram 可视化")
|
23 |
+
col1, col2, col3, col4 = st.columns(4)
|
24 |
+
with col1:
|
25 |
+
fill_edges = st.toggle("填充超边", value=True, key="fill_edges")
|
26 |
+
with col2:
|
27 |
+
toplexes = st.toggle("只保留未被包含的边(toplexes)", value=False, key="toplexes")
|
28 |
+
with col3:
|
29 |
+
with_edge_labels = st.toggle("不看边名", value=False, key="with_edge_labels")
|
30 |
+
|
31 |
+
|
32 |
+
col1, col2 = st.columns(2)
|
33 |
+
captions = ["超图", "对偶超图"]
|
34 |
+
|
35 |
+
if 'poses' not in st.session_state:
|
36 |
+
st.session_state.poses = [None, None]
|
37 |
+
if draw_dual:
|
38 |
+
captions = ["对偶超图", "超图"]
|
39 |
+
# st.session_state.poses = [st.session_state.poses[1], st.session_state.poses[0]]
|
40 |
+
|
41 |
+
with col1:
|
42 |
+
hypergraph_image, st.session_state.poses[0] = draw_hypergraph(hypergraph, draw_dual=False,
|
43 |
+
fill_edges=fill_edges, toplexes=toplexes,
|
44 |
+
with_edge_labels=with_edge_labels
|
45 |
+
# pos=st.session_state.poses[0]
|
46 |
+
,draw_width=draw_width, draw_height=draw_height
|
47 |
+
)
|
48 |
+
st.image(hypergraph_image, caption = captions[0], use_container_width=True)
|
49 |
+
|
50 |
+
with col2:
|
51 |
+
hypergraph_image, st.session_state.poses[1] = draw_hypergraph(hypergraph, draw_dual=True,
|
52 |
+
fill_edges=fill_edges, toplexes=toplexes,
|
53 |
+
with_edge_labels=with_edge_labels
|
54 |
+
# pos=st.session_state.poses[1]
|
55 |
+
,draw_width=draw_width, draw_height=draw_height
|
56 |
+
)
|
57 |
+
st.image(hypergraph_image, caption =captions[1], use_container_width=True)
|
58 |
+
|
59 |
+
def new_visualization(hypergraph):
|
60 |
+
st.subheader("新型可视化")
|
61 |
+
col1, col2 = st.columns(2)
|
62 |
+
with col1:
|
63 |
+
fig, ax = plt.subplots(figsize=(draw_width, draw_height))
|
64 |
+
hnx.draw_bipartite_using_euler(hypergraph)
|
65 |
+
st.image(pyplot_fig_to_buffer(plt.gcf()), caption="双列二分图可视化", use_container_width=True)
|
66 |
+
with col2:
|
67 |
+
fig, ax = plt.subplots(figsize=(draw_width, draw_height))
|
68 |
+
hnx.draw_incidence_upset(hypergraph)
|
69 |
+
st.image(pyplot_fig_to_buffer(plt.gcf()), caption="Incidence/UpSet 可视化", use_container_width=True)
|
70 |
+
|
71 |
+
if euler_first:
|
72 |
+
euler_visualization(hypergraph)
|
73 |
+
new_visualization(hypergraph)
|
74 |
+
else:
|
75 |
+
new_visualization(hypergraph)
|
76 |
+
euler_visualization(hypergraph)
|