feat: performance
Browse filesFiles changed (2)
- experiments/performance_comparison.pyAdded+172
- experiments/test.pyDeleted-69
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172import plotly.graph_objects as goimport pandas as pdimport numpy as np
# 生成符合学术规范的模拟数据np.random.seed(42) # 确保可重复性methods = ['RSM', 'PSRN', 'NGGP', 'PySR', 'BMS', 'uDSR', 'AIF', 'DGSR', 'E2E', 'SymINDy', 'physo', 'TPSR', 'SPL', 'DEAP', 'SINDy', 'NSRS', 'gplearn', 'SNIP', 'KAN', 'EQL']
# 生成0-1之间的RMSE数据(保持原图分布模式)rmse_values = np.clip(np.abs(np.random.normal(0.3, 0.15, len(methods))), 0.05, 0.95)uncertainty = np.random.uniform(0.02, 0.08, len(methods))param_sizes = np.array([1e3, 1e4, 5e4, 1e5, 5e5, 1e6, 2e6]) # 定义标准参数规模
# 构建分类系统(基于方法原理)method_categories = { 'Symbolic': ['RSM', 'PySR', 'SymINDy', 'gplearn', 'EQL'], 'Neural': ['NGGP', 'DGSR', 'E2E', 'KAN'], 'Evolutionary': ['PSRN', 'DEAP', 'NSRS'], 'Physics-based': ['physo', 'TPSR', 'SPL'], 'Hybrid': ['BMS', 'uDSR', 'AIF', 'SINDy', 'SNIP']}
# 创建数据框架df = pd.DataFrame({ 'Method': methods, 'RMSE': rmse_values, 'Uncertainty': uncertainty, 'ParamSize': np.random.choice(param_sizes, len(methods))}).sort_values('RMSE', ascending=True)
# 添加分类信息df['Category'] = df['Method'].apply(lambda x: next((k for k,v in method_categories.items() if x in v), 'Other'))
# 颜色映射系统(学术级调色板)category_colors = { 'Symbolic': '#1f77b4', 'Neural': '#ff7f0e', 'Evolutionary': '#2ca02c', 'Physics-based': '#d62728', 'Hybrid': '#9467bd'}
# 创建基础图表fig = go.Figure()
# 动态尺寸计算系统size_min = np.log(df['ParamSize'].min())size_max = np.log(df['ParamSize'].max())sizes = 15 + 25 * (np.log(df['ParamSize']) - size_min) / (size_max - size_min) # 动态尺寸范围
# 添加主数据轨迹for category in df['Category'].unique(): df_sub = df[df['Category'] == category] fig.add_trace(go.Scatter( x=df_sub['RMSE'], y=df_sub['Method'], mode='markers', name=category, marker=dict( size=sizes[df_sub.index], color=category_colors[category], opacity=0.9, line=dict(width=1, color='black') ), error_x=dict( type='data', array=df_sub['Uncertainty'], color='rgba(40,40,40,0.6)', thickness=1.2, width=10 ), hoverinfo='text', hovertext=df_sub.apply(lambda r: f"{r['Method']}<br>RMSE: {r['RMSE']:.3f} ± {r['Uncertainty']:.3f}<br>Params: {r['ParamSize']:,.0f}", axis=1) ))
# 动态轴范围计算data_min = (df['RMSE'] - df['Uncertainty']).min()x_min = max(data_min - 0.05, 0) # 保证最小值不低于0x_max = 1.0
# 专业级布局配置fig.update_layout( title='Methods RMSE Comparison with Parameter Scale', xaxis=dict( title='Root Mean Square Error (RMSE) → Lower is better', range=[x_min, x_max], tickvals=np.arange(0, 1.1, 0.1), gridcolor='#F0F0F0', zeroline=False, showspikes=True ), yaxis=dict( categoryorder='array', categoryarray=df['Method'].tolist(), tickfont=dict(size=12), showticklabels=False # 禁用默认标签 ), plot_bgcolor='white', width=1100, height=700, margin=dict(l=180, r=50, t=80, b=40), legend=dict( title='Method Categories', orientation='v', yanchor="top", y=0.98, xanchor="left", x=1.02 ))
# 添加自定义y轴标签(分类着色)y_positions = np.linspace(0.03, 0.97, len(methods)) # 动态计算标签位置for idx, method in enumerate(df['Method']): category = df[df['Method'] == method]['Category'].values[0] fig.add_annotation( x=0.01, y=y_positions[idx], xref='paper', yref='paper', text=method, showarrow=False, font=dict( size=12, color=category_colors[category] ), xanchor='right' )
# 添加专业级尺寸图例系统size_legend_values = [1e3, 1e4, 1e5, 1e6] # 定义标准参数规模size_legend_sizes = 15 + 25 * (np.log(size_legend_values) - size_min) / (size_max - size_min)
fig.add_trace(go.Scatter( x=[0.82, 0.85, 0.88, 0.91], y=[0.15, 0.20, 0.25, 0.30], mode='markers', marker=dict( size=size_legend_sizes, color='#444444', opacity=0.8 ), showlegend=False))
# 添加尺寸图例标注size_labels = ['1K', '10K', '100K', '1M']for i, (x, y, label) in enumerate(zip([0.95]*4, [0.15,0.20,0.25,0.30], size_labels)): fig.add_annotation( x=x, y=y, xref="paper", yref="paper", text=label, showarrow=False, font=dict(size=10), xanchor='left' )
# 添加最终标注fig.add_annotation( x=0.98, y=0.02, xref='paper', yref='paper', text='叶璨铭 | Parameters (log scale)', showarrow=False, font=dict(size=10, color='#666666'), bgcolor='white')
fig.show()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869import plotly.graph_objects as go
# 示例数据(请替换为实际数据)methods = ['RSRM', 'PSRN', 'NGGP', 'PySR', 'BMS', 'uDSR', 'AIF', 'DGSR', 'E2E', 'SymINDy', 'PhySO', 'TPSR', 'SPL', 'DEAP', 'SINDy', 'NSRS', 'gplearn', 'SNIP', 'KAN', 'EQL']recovery_rates = [85, 78, 92, 88, 76, 83, 95, 81, 89, 77, 84, 86, 80, 79, 82, 87, 75, 88, 90, 84] # 恢复率百分比errors = [3, 4, 2, 3, 5, 2, 1, 3, 2, 4, 3, 2, 3, 4, 2, 3, 5, 2, 3, 2] # 误差范围
# 创建图形对象fig = go.Figure()
# 添加带误差线的数据点fig.add_trace(go.Scatter( x=recovery_rates, y=methods, mode='markers', error_x=dict( type='data', array=errors, visible=True, color='#FF5733', thickness=2, width=10 ), marker=dict( size=12, color=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf', '#aec7e8', '#ffbb78', '#98df8a', '#ff9896', '#c5b0d5', '#c49c94', '#f7b6d2', '#c7c7c7', '#dbdb8d', '#9edae5'], opacity=0.8 )))
# 设置布局fig.update_layout( title='不同方法的恢复率比较', xaxis=dict( title='恢复率 (%)', range=[0, 100], dtick=20, title_standoff=25 ), yaxis=dict( title='Methods', title_font=dict(size=14), tickfont=dict(size=12), autorange="reversed" # 使第一个方法显示在最上方 ), hovermode='closest', width=1000, height=600, showlegend=False)
# 添加注释(可选)fig.add_annotation( x=0, y=0.95, xref='paper', yref='paper', text='知乎 @x66ccff', showarrow=False, font=dict(size=10))
fig.show()experiments/performance_comparison.pyAdded+172
experiments/test.pyDeleted-69