2catycm commited on
Commit
0ef56b6
·
1 Parent(s): 78e4509

feat: performance

Browse files
experiments/performance_comparison.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import plotly.graph_objects as go
2
+ import pandas as pd
3
+ import numpy as np
4
+
5
+ # 生成符合学术规范的模拟数据
6
+ np.random.seed(42) # 确保可重复性
7
+ methods = ['RSM', 'PSRN', 'NGGP', 'PySR', 'BMS', 'uDSR', 'AIF',
8
+ 'DGSR', 'E2E', 'SymINDy', 'physo', 'TPSR', 'SPL',
9
+ 'DEAP', 'SINDy', 'NSRS', 'gplearn', 'SNIP', 'KAN', 'EQL']
10
+
11
+ # 生成0-1之间的RMSE数据(保持原图分布模式)
12
+ rmse_values = np.clip(np.abs(np.random.normal(0.3, 0.15, len(methods))), 0.05, 0.95)
13
+ uncertainty = np.random.uniform(0.02, 0.08, len(methods))
14
+ param_sizes = np.array([1e3, 1e4, 5e4, 1e5, 5e5, 1e6, 2e6]) # 定义标准参数规模
15
+
16
+ # 构建分类系统(基于方法原理)
17
+ method_categories = {
18
+ 'Symbolic': ['RSM', 'PySR', 'SymINDy', 'gplearn', 'EQL'],
19
+ 'Neural': ['NGGP', 'DGSR', 'E2E', 'KAN'],
20
+ 'Evolutionary': ['PSRN', 'DEAP', 'NSRS'],
21
+ 'Physics-based': ['physo', 'TPSR', 'SPL'],
22
+ 'Hybrid': ['BMS', 'uDSR', 'AIF', 'SINDy', 'SNIP']
23
+ }
24
+
25
+ # 创建数据框架
26
+ df = pd.DataFrame({
27
+ 'Method': methods,
28
+ 'RMSE': rmse_values,
29
+ 'Uncertainty': uncertainty,
30
+ 'ParamSize': np.random.choice(param_sizes, len(methods))
31
+ }).sort_values('RMSE', ascending=True)
32
+
33
+ # 添加分类信息
34
+ df['Category'] = df['Method'].apply(lambda x: next((k for k,v in method_categories.items() if x in v), 'Other'))
35
+
36
+ # 颜色映射系统(学术级调色板)
37
+ category_colors = {
38
+ 'Symbolic': '#1f77b4',
39
+ 'Neural': '#ff7f0e',
40
+ 'Evolutionary': '#2ca02c',
41
+ 'Physics-based': '#d62728',
42
+ 'Hybrid': '#9467bd'
43
+ }
44
+
45
+ # 创建基础图表
46
+ fig = go.Figure()
47
+
48
+ # 动态尺寸计算系统
49
+ size_min = np.log(df['ParamSize'].min())
50
+ size_max = np.log(df['ParamSize'].max())
51
+ sizes = 15 + 25 * (np.log(df['ParamSize']) - size_min) / (size_max - size_min) # 动态尺寸范围
52
+
53
+ # 添加主数据轨迹
54
+ for category in df['Category'].unique():
55
+ df_sub = df[df['Category'] == category]
56
+ fig.add_trace(go.Scatter(
57
+ x=df_sub['RMSE'],
58
+ y=df_sub['Method'],
59
+ mode='markers',
60
+ name=category,
61
+ marker=dict(
62
+ size=sizes[df_sub.index],
63
+ color=category_colors[category],
64
+ opacity=0.9,
65
+ line=dict(width=1, color='black')
66
+ ),
67
+ error_x=dict(
68
+ type='data',
69
+ array=df_sub['Uncertainty'],
70
+ color='rgba(40,40,40,0.6)',
71
+ thickness=1.2,
72
+ width=10
73
+ ),
74
+ hoverinfo='text',
75
+ hovertext=df_sub.apply(lambda r: f"{r['Method']}<br>RMSE: {r['RMSE']:.3f} ± {r['Uncertainty']:.3f}<br>Params: {r['ParamSize']:,.0f}", axis=1)
76
+ ))
77
+
78
+ # 动态轴范围计算
79
+ data_min = (df['RMSE'] - df['Uncertainty']).min()
80
+ x_min = max(data_min - 0.05, 0) # 保证最小值不低于0
81
+ x_max = 1.0
82
+
83
+ # 专业级布局配置
84
+ fig.update_layout(
85
+ title='Methods RMSE Comparison with Parameter Scale',
86
+ xaxis=dict(
87
+ title='Root Mean Square Error (RMSE) → Lower is better',
88
+ range=[x_min, x_max],
89
+ tickvals=np.arange(0, 1.1, 0.1),
90
+ gridcolor='#F0F0F0',
91
+ zeroline=False,
92
+ showspikes=True
93
+ ),
94
+ yaxis=dict(
95
+ categoryorder='array',
96
+ categoryarray=df['Method'].tolist(),
97
+ tickfont=dict(size=12),
98
+ showticklabels=False # 禁用默认标签
99
+ ),
100
+ plot_bgcolor='white',
101
+ width=1100,
102
+ height=700,
103
+ margin=dict(l=180, r=50, t=80, b=40),
104
+ legend=dict(
105
+ title='Method Categories',
106
+ orientation='v',
107
+ yanchor="top",
108
+ y=0.98,
109
+ xanchor="left",
110
+ x=1.02
111
+ )
112
+ )
113
+
114
+ # 添加自定义y轴标签(分类着色)
115
+ y_positions = np.linspace(0.03, 0.97, len(methods)) # 动态计算标签位置
116
+ for idx, method in enumerate(df['Method']):
117
+ category = df[df['Method'] == method]['Category'].values[0]
118
+ fig.add_annotation(
119
+ x=0.01,
120
+ y=y_positions[idx],
121
+ xref='paper',
122
+ yref='paper',
123
+ text=method,
124
+ showarrow=False,
125
+ font=dict(
126
+ size=12,
127
+ color=category_colors[category]
128
+ ),
129
+ xanchor='right'
130
+ )
131
+
132
+ # 添加专业级尺寸图例系统
133
+ size_legend_values = [1e3, 1e4, 1e5, 1e6] # 定义标准参数规模
134
+ size_legend_sizes = 15 + 25 * (np.log(size_legend_values) - size_min) / (size_max - size_min)
135
+
136
+ fig.add_trace(go.Scatter(
137
+ x=[0.82, 0.85, 0.88, 0.91],
138
+ y=[0.15, 0.20, 0.25, 0.30],
139
+ mode='markers',
140
+ marker=dict(
141
+ size=size_legend_sizes,
142
+ color='#444444',
143
+ opacity=0.8
144
+ ),
145
+ showlegend=False
146
+ ))
147
+
148
+ # 添加尺寸图例标注
149
+ size_labels = ['1K', '10K', '100K', '1M']
150
+ for i, (x, y, label) in enumerate(zip([0.95]*4, [0.15,0.20,0.25,0.30], size_labels)):
151
+ fig.add_annotation(
152
+ x=x,
153
+ y=y,
154
+ xref="paper",
155
+ yref="paper",
156
+ text=label,
157
+ showarrow=False,
158
+ font=dict(size=10),
159
+ xanchor='left'
160
+ )
161
+
162
+ # 添加最终标注
163
+ fig.add_annotation(
164
+ x=0.98, y=0.02,
165
+ xref='paper', yref='paper',
166
+ text='叶璨铭 | Parameters (log scale)',
167
+ showarrow=False,
168
+ font=dict(size=10, color='#666666'),
169
+ bgcolor='white'
170
+ )
171
+
172
+ fig.show()
experiments/test.py DELETED
@@ -1,69 +0,0 @@
1
- import plotly.graph_objects as go
2
-
3
- # 示例数据(请替换为实际数据)
4
- methods = ['RSRM', 'PSRN', 'NGGP', 'PySR', 'BMS', 'uDSR', 'AIF',
5
- 'DGSR', 'E2E', 'SymINDy', 'PhySO', 'TPSR', 'SPL',
6
- 'DEAP', 'SINDy', 'NSRS', 'gplearn', 'SNIP', 'KAN', 'EQL']
7
- recovery_rates = [85, 78, 92, 88, 76, 83, 95, 81, 89, 77, 84, 86, 80,
8
- 79, 82, 87, 75, 88, 90, 84] # 恢复率百分比
9
- errors = [3, 4, 2, 3, 5, 2, 1, 3, 2, 4, 3, 2, 3, 4, 2, 3, 5, 2, 3, 2] # 误差范围
10
-
11
- # 创建图形对象
12
- fig = go.Figure()
13
-
14
- # 添加带误差线的数据点
15
- fig.add_trace(go.Scatter(
16
- x=recovery_rates,
17
- y=methods,
18
- mode='markers',
19
- error_x=dict(
20
- type='data',
21
- array=errors,
22
- visible=True,
23
- color='#FF5733',
24
- thickness=2,
25
- width=10
26
- ),
27
- marker=dict(
28
- size=12,
29
- color=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd',
30
- '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf',
31
- '#aec7e8', '#ffbb78', '#98df8a', '#ff9896', '#c5b0d5',
32
- '#c49c94', '#f7b6d2', '#c7c7c7', '#dbdb8d', '#9edae5'],
33
- opacity=0.8
34
- )
35
- ))
36
-
37
- # 设置布局
38
- fig.update_layout(
39
- title='不同方法的恢复率比较',
40
- xaxis=dict(
41
- title='恢复率 (%)',
42
- range=[0, 100],
43
- dtick=20,
44
- title_standoff=25
45
- ),
46
- yaxis=dict(
47
- title='Methods',
48
- title_font=dict(size=14),
49
- tickfont=dict(size=12),
50
- autorange="reversed" # 使第一个方法显示在最上方
51
- ),
52
- hovermode='closest',
53
- width=1000,
54
- height=600,
55
- showlegend=False
56
- )
57
-
58
- # 添加注释(可选)
59
- fig.add_annotation(
60
- x=0,
61
- y=0.95,
62
- xref='paper',
63
- yref='paper',
64
- text='知乎 @x66ccff',
65
- showarrow=False,
66
- font=dict(size=10)
67
- )
68
-
69
- fig.show()