2catycm commited on
Commit
81f3976
·
1 Parent(s): d83eb30

fix: different state

Browse files
Files changed (4) hide show
  1. app.py +3 -2
  2. my_pages/page2.py +11 -10
  3. my_pages/page3.py +9 -90
  4. presentation.html +296 -0
app.py CHANGED
@@ -4,6 +4,7 @@ import streamlit as st
4
  # 设置页面配置
5
  st.set_page_config(layout="wide")
6
 
 
7
  # 主应用
8
  def main():
9
  # st.sidebar.title("导航")
@@ -23,11 +24,11 @@ def main():
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
 
4
  # 设置页面配置
5
  st.set_page_config(layout="wide")
6
 
7
+
8
  # 主应用
9
  def main():
10
  # st.sidebar.title("导航")
 
24
 
25
  page1 = st.Page("my_pages/page1.py", title="无监督聚类动态变化", icon="📊", default=True)
26
  page2 = st.Page("my_pages/page2.py", title="超图神经网络训练过程", icon="📈")
27
+ page3 = st.Page("my_pages/page3.py", title="Presentation 演示", icon="📉")
28
  # page3 = st.Page("dev/test.py", title="第三个子应用", icon="📉")
29
 
30
  pg = st.navigation([page1, page2,
31
+ page3
32
  ])
33
  pg.run()
34
  # pass
my_pages/page2.py CHANGED
@@ -35,13 +35,13 @@ def main():
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
  # 创建播放/暂停按钮
@@ -53,8 +53,8 @@ def main():
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"
@@ -85,7 +85,8 @@ def main():
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)
@@ -128,9 +129,9 @@ def main():
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:
 
35
  slider_max = 200
36
  if 'play_state' not in st.session_state:
37
  st.session_state.play_state = False
38
+ if 'iteration_app2' not in st.session_state:
39
+ st.session_state.iteration_app2 = 10
40
 
41
  # 定义回调函数来切换播放状态
42
  def toggle_play():
43
+ if not st.session_state.play_state and st.session_state.iteration_app2 == slider_max:
44
+ st.session_state.iteration_app2 = 10 # 重置迭代次数
45
  st.session_state.play_state = not st.session_state.play_state
46
 
47
  # 创建播放/暂停按钮
 
53
 
54
  # 显示迭代次数滑条
55
  iteration = st.slider("迭代步骤", min_value=10, max_value=slider_max,
56
+ value=st.session_state.iteration_app2, step=10,
57
+ key="iteration_app2_slider")
58
 
59
  # 从JSON文件加载数据
60
  # 假设JSON文件路径为"authors_papers.json"
 
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),
89
+ value=min(10, max_samples), step=1)
90
 
91
  # 采样部分作者
92
  sampled_authors = np.random.choice(st.session_state.hyper_edges, size=num_samples, replace=False)
 
129
  # 自动播放功能
130
  if st.session_state.play_state:
131
  with st.spinner("正在播放..."):
132
+ if st.session_state.iteration_app2 < slider_max:
133
+ st.session_state.iteration_app2 += 10
134
+ st.write(f"当前迭代次数: {st.session_state.iteration_app2}")
135
  time.sleep(1/speed) # 根据速度调整等待时间
136
  st.rerun()
137
  else:
my_pages/page3.py CHANGED
@@ -1,95 +1,14 @@
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()
 
1
  from typing import Dict, List
2
  import streamlit as st
3
+ from pathlib import Path
4
+ this_file = Path(__file__).resolve()
5
+ parent_dir = this_file.parent.parent
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def main():
8
+ with open (parent_dir/"presentation.html", "r", encoding="utf-8") as f:
9
+ html = f.read()
10
+ st.html(html)
11
+ # url = "parent_dir/"presentation.html)"
12
+ # st.write("check out this [link](%s)" % url)
13
+ # st.markdown("check out this [link](%s)" % url)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  main()
presentation.html ADDED
@@ -0,0 +1,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Python中最佳的稳定交互式超图可视化库</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ margin: 0;
11
+ padding: 0;
12
+ background-color: #f5f5f5;
13
+ }
14
+ .slide-container {
15
+ max-width: 800px;
16
+ margin: 0 auto;
17
+ background-color: white;
18
+ box-shadow: 0 0 10px rgba(0,0,0,0.1);
19
+ padding: 20px;
20
+ }
21
+ .slide {
22
+ margin-bottom: 30px;
23
+ padding: 20px;
24
+ border-radius: 5px;
25
+ background-color: #fff;
26
+ box-shadow: 0 0 5px rgba(0,0,0,0.1);
27
+ }
28
+ .slide h2 {
29
+ color: #2c3e50;
30
+ margin-top: 0;
31
+ }
32
+ .slide p {
33
+ line-height: 1.6;
34
+ color: #34495e;
35
+ }
36
+ .code-block {
37
+ background-color: #f8f9fa;
38
+ padding: 10px;
39
+ border-radius: 5px;
40
+ font-family: monospace;
41
+ white-space: pre-wrap;
42
+ margin: 10px 0;
43
+ }
44
+ .highlight {
45
+ background-color: #e8f4f8;
46
+ padding: 2px 5px;
47
+ border-radius: 3px;
48
+ }
49
+ .navigation {
50
+ text-align: center;
51
+ margin-top: 20px;
52
+ }
53
+ .navigation button {
54
+ padding: 10px 20px;
55
+ margin: 0 10px;
56
+ background-color: #3498db;
57
+ color: white;
58
+ border: none;
59
+ border-radius: 5px;
60
+ cursor: pointer;
61
+ font-size: 16px;
62
+ }
63
+ .navigation button:hover {
64
+ background-color: #2980b9;
65
+ }
66
+ table {
67
+ width: 100%;
68
+ border-collapse: collapse;
69
+ margin: 15px 0;
70
+ }
71
+ th, td {
72
+ border: 1px solid #ddd;
73
+ padding: 8px;
74
+ text-align: left;
75
+ }
76
+ th {
77
+ background-color: #f2f2f2;
78
+ }
79
+ .comparison {
80
+ font-weight: bold;
81
+ color: #2c3e50;
82
+ }
83
+ </style>
84
+ </head>
85
+ <body>
86
+ <div class="slide-container">
87
+ <div class="slide" id="slide1">
88
+ <h2>Python中最佳的稳定交互式超图可视化库</h2>
89
+ <p>超图是传统图的推广,为建模以实体间多向交互为特征的复杂系统提供了一个强大的框架。与标准图中边精确连接两个节点不同,超图中的超边可以连接任意数量的节点。</p>
90
+ <p>本报告旨在确定Python库,该库在稳定性(特别是对于大型和复杂的超图)和交互功能方面提供了最佳组合,以促进对其进行探索和分析。</p>
91
+ </div>
92
+
93
+ <div class="slide" id="slide2" style="display: none;">
94
+ <h2>主要Python超图可视化库</h2>
95
+ <p>通过研究,确定了四个主要的Python库,它们提供超图可视化功能:</p>
96
+ <ul>
97
+ <li><strong>HyperNetX (HNX)</strong>:由太平洋西北国家实验室 (PNNL) 开发,专注于使用代数拓扑和组合学方法分析和可视化复杂网络。</li>
98
+ <li><strong>Hypergraphx (HGX)</strong>:较新的库,提供全面的算法用于构建、分析和可视化具有高级交互的系统。</li>
99
+ <li><strong>XGI (CompleX Group Interactions)</strong>:由网络科学家设计,专注于建模、分析和可视化具有群体交互的复杂系统。</li>
100
+ <li><strong>dhg (DeepHypergraph)</strong>:基于PyTorch的深度学习库,专门设计用于图和超图神经网络。</li>
101
+ </ul>
102
+ </div>
103
+
104
+ <div class="slide" id="slide3" style="display: none;">
105
+ <h2>HyperNetX (HNX)</h2>
106
+ <p>HyperNetX最初于2019年发布,由PNNL开发,专注于使用代数拓扑和组合学方法分析和可视化复杂网络。</p>
107
+ <p>交互功能:</p>
108
+ <ul>
109
+ <li>通过HyperNetX-Widget提供交互功能,包括力导向布局、高级选择机制(单击、多选、拖动、刷选)。</li>
110
+ <li>支持节点折叠,将具有相同边成员关系的节点分组为超级节点。</li>
111
+ <li>提供二分图视图,显示超图的替代视角。</li>
112
+ </ul>
113
+ <p>稳定性:</p>
114
+ <ul>
115
+ <li>核心库稳定,利用Pandas DataFrames提高性能。</li>
116
+ <li>HNX-Widget目前处于beta阶段,建议在Anaconda环境中使用。</li>
117
+ </ul>
118
+ </div>
119
+
120
+ <div class="slide" id="slide4" style="display: none;">
121
+ <h2>Hypergraphx (HGX)</h2>
122
+ <p>Hypergraphx于2023年发布,是一个多用途高级网络分析工具。</p>
123
+ <p>交互功能:</p>
124
+ <ul>
125
+ <li>提供“不同的可视化工具”,但具体交互功能(如缩放、平移、节点选择)未详细说明。</li>
126
+ </ul>
127
+ <p>稳定性:</p>
128
+ <ul>
129
+ <li>在分析任务中具有良好的可扩展性,适用于非常大的超图。</li>
130
+ <li>其可视化功能对于大型数据集的稳定性未明确说明。</li>
131
+ </ul>
132
+ </div>
133
+
134
+ <div class="slide" id="slide5" style="display: none;">
135
+ <h2>XGI (CompleX Group Interactions)</h2>
136
+ <p>XGI于2021年发布,专注于建模、分析和可视化具有群体交互的复杂系统。</p>
137
+ <p>交互功能:</p>
138
+ <ul>
139
+ <li>提供“方便的可视化功能”,但具体交互功能未详细说明。</li>
140
+ </ul>
141
+ <p>稳定性:</p>
142
+ <ul>
143
+ <li>已用于涉及超图的可扩展张量方法的研究。</li>
144
+ <li>缺乏其可视化对于大型超图的稳定性的直接证据。</li>
145
+ </ul>
146
+ </div>
147
+
148
+ <div class="slide" id="slide6" style="display: none;">
149
+ <h2>dhg (DeepHypergraph)</h2>
150
+ <p>dhg于2022年发布,是一个基于PyTorch的深度学习库,专注于图和超图神经网络。</p>
151
+ <p>交互功能:</p>
152
+ <ul>
153
+ <li>提供“强大的图和超图可视化工具”,但具体交互功能未详细说明。</li>
154
+ </ul>
155
+ <p>稳定性:</p>
156
+ <ul>
157
+ <li>性能重点在于超图上的深度学习。</li>
158
+ <li>缺乏关于其可视化对于广泛超图的稳定性的具体信息。</li>
159
+ </ul>
160
+ </div>
161
+
162
+ <div class="slide" id="slide7" style="display: none;">
163
+ <h2>库功能比较</h2>
164
+ <table>
165
+ <tr>
166
+ <th>功能</th>
167
+ <th>HyperNetX</th>
168
+ <th>Hypergraphx</th>
169
+ <th>XGI</th>
170
+ <th>dhg</th>
171
+ </tr>
172
+ <tr>
173
+ <td>缩放</td>
174
+ <td>是</td>
175
+ <td>否</td>
176
+ <td>否</td>
177
+ <td>否</td>
178
+ </tr>
179
+ <tr>
180
+ <td>平移</td>
181
+ <td>是</td>
182
+ <td>否</td>
183
+ <td>否</td>
184
+ <td>否</td>
185
+ </tr>
186
+ <tr>
187
+ <td>节点选择</td>
188
+ <td>是</td>
189
+ <td>否</td>
190
+ <td>否</td>
191
+ <td>否</td>
192
+ </tr>
193
+ <tr>
194
+ <td>边选择</td>
195
+ <td>是</td>
196
+ <td>否</td>
197
+ <td>否</td>
198
+ <td>否</td>
199
+ </tr>
200
+ <tr>
201
+ <td>拖拽</td>
202
+ <td>是</td>
203
+ <td>否</td>
204
+ <td>否</td>
205
+ <td>否</td>
206
+ </tr>
207
+ <tr>
208
+ <td>刷选</td>
209
+ <td>是</td>
210
+ <td>否</td>
211
+ <td>否</td>
212
+ <td>否</td>
213
+ </tr>
214
+ <tr>
215
+ <td>工具提示</td>
216
+ <td>是</td>
217
+ <td>否</td>
218
+ <td>否</td>
219
+ <td>否</td>
220
+ </tr>
221
+ <tr>
222
+ <td>节点折叠</td>
223
+ <td>是</td>
224
+ <td>否</td>
225
+ <td>否</td>
226
+ <td>否</td>
227
+ </tr>
228
+ <tr>
229
+ <td>二分图视图</td>
230
+ <td>是</td>
231
+ <td>是</td>
232
+ <td>是</td>
233
+ <td>否</td>
234
+ </tr>
235
+ <tr>
236
+ <td>属性控制</td>
237
+ <td>是</td>
238
+ <td>否</td>
239
+ <td>是</td>
240
+ <td>否</td>
241
+ </tr>
242
+ </table>
243
+ </div>
244
+
245
+ <div class="slide" id="slide8" style="display: none;">
246
+ <h2>结论与建议</h2>
247
+ <p>根据比较分析,HyperNetX (HNX) 通过其 HyperNetX-Widget 提供了最全面的超图可视化交互功能集。</p>
248
+ <ul>
249
+ <li>HNX 的交互功能包括布局调整、高级选择、可见性操作和属性控制。</li>
250
+ <li>核心 HNX 库稳定且文档完善,拥有支持性的社区和交互式教程等资源。</li>
251
+ <li>对于处理大型超图,HNX 提供节点折叠作为视觉辅助。</li>
252
+ </ul>
253
+ <p>建议:</p>
254
+ <ul>
255
+ <li>首先使用 HyperNetX,因为它具有明确的交互功能以及核心��的稳定性。</li>
256
+ <li>如果对极其庞大的超图的稳定性成为首要关注点,而交互式探索是次要的,则建议进一步评估 Hypergraphx。</li>
257
+ </ul>
258
+ </div>
259
+
260
+ <div class="navigation">
261
+ <button onclick="prevSlide()">上一页</button>
262
+ <button onclick="nextSlide()">下一页</button>
263
+ </div>
264
+ </div>
265
+
266
+ <script>
267
+ let currentSlide = 1;
268
+ const totalSlides = 8;
269
+
270
+ function showSlide(n) {
271
+ // 隐藏所有幻灯片
272
+ for (let i = 1; i <= totalSlides; i++) {
273
+ document.getElementById(`slide${i}`).style.display = 'none';
274
+ }
275
+ // 显示当前幻灯片
276
+ document.getElementById(`slide${n}`).style.display = 'block';
277
+ currentSlide = n;
278
+ }
279
+
280
+ function nextSlide() {
281
+ if (currentSlide < totalSlides) {
282
+ showSlide(currentSlide + 1);
283
+ }
284
+ }
285
+
286
+ function prevSlide() {
287
+ if (currentSlide > 1) {
288
+ showSlide(currentSlide - 1);
289
+ }
290
+ }
291
+
292
+ // 初始化显示第一页
293
+ showSlide(1);
294
+ </script>
295
+ </body>
296
+ </html>