-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_example.py
More file actions
133 lines (104 loc) · 5.1 KB
/
run_example.py
File metadata and controls
133 lines (104 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python3
"""
NGDB benchmark运行示例脚本
"""
import sys
import os
import yaml
from ngdb_framework import NGDBBench
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
def main():
"""主函数"""
print("🚀 欢迎使用NGDB benchmark框架!")
print("=" * 50)
# 从配置文件读取配置
config_path = os.path.join(os.path.dirname(__file__), 'configs', 'default_config.yaml')
with open(config_path, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
print(f"📄 已加载配置文件: {config_path}")
try:
print("📊 创建NGDB框架实例...")
framework = NGDBBench(config)
print("🔄 开始运行基准测试...")
results = framework.run_benchmark()
print("\n" + "=" * 50)
print("📈 基准测试结果摘要")
print("=" * 50)
# 执行信息
exec_metadata = results.get('execution_metadata', {})
print(f"⏱️ 执行时间: {exec_metadata.get('total_time', 0):.2f}秒")
# 数据信息
data_info = results.get('data_info', {})
original_stats = data_info.get('original_graph_stats', {})
perturbed_stats = data_info.get('perturbed_graph_stats', {})
print(f"📊 原始图: {original_stats.get('num_nodes', 0)}个节点, {original_stats.get('num_edges', 0)}条边")
print(f"🔀 扰动图: {perturbed_stats.get('num_nodes', 0)}个节点, {perturbed_stats.get('num_edges', 0)}条边")
# 扰动信息
perturbation_info = data_info.get('perturbation_info', {})
if 'operations' in perturbation_info:
print(f"🎯 扰动操作: {len(perturbation_info['operations'])}个")
# 查询信息
queries_info = results.get('queries_info', {})
print(f"❓ 查询数量: {queries_info.get('total_queries', 0)}")
# 评估结果
evaluation_results = results.get('evaluation_results', {})
print("\n📋 评估结果:")
if 'accuracy_evaluation' in evaluation_results:
acc_metrics = evaluation_results['accuracy_evaluation'].get('metrics', {})
accuracy = acc_metrics.get('accuracy', 0)
match_rate = acc_metrics.get('match_rate', 0)
print(f" ✅ 准确性: {accuracy:.3f}")
print(f" 🎯 匹配率: {match_rate:.3f}")
if 'robustness_evaluation' in evaluation_results:
rob_metrics = evaluation_results['robustness_evaluation'].get('robustness_metrics', {})
overall_robustness = rob_metrics.get('overall_robustness', 0)
print(f" 🛡️ 鲁棒性: {overall_robustness:.3f}")
if 'performance_evaluation' in evaluation_results:
perf_metrics = evaluation_results['performance_evaluation'].get('execution_metrics', {})
avg_query_time = perf_metrics.get('average_query_time', 0)
print(f" ⚡ 平均查询时间: {avg_query_time:.4f}秒")
# 综合报告
reports = results.get('reports', {})
if 'comprehensive_report' in reports:
comp_report = reports['comprehensive_report']
exec_summary = comp_report.get('executive_summary', {})
overall_perf = exec_summary.get('overall_performance', {})
score = overall_perf.get('score', 0)
grade = overall_perf.get('grade', 'N/A')
print(f"\n🏆 总体性能评分: {score:.3f} (等级: {grade})")
# 关键发现
key_findings = exec_summary.get('key_findings', [])
if key_findings:
print("\n🔍 关键发现:")
for finding in key_findings[:3]: # 显示前3个
print(f" • {finding}")
# 主要关注点
main_concerns = exec_summary.get('main_concerns', [])
if main_concerns:
print("\n⚠️ 主要关注点:")
for concern in main_concerns[:2]: # 显示前2个
print(f" • {concern.get('description', 'N/A')}")
print("\n" + "=" * 50)
print("✅ 基准测试完成!")
# 保存结果
framework.save_results("ngdb_example_results.json")
print("💾 结果已保存到: ngdb_example_results.json")
# 性能评级
if 'comprehensive_report' in reports:
score = reports['comprehensive_report'].get('executive_summary', {}).get('overall_performance', {}).get('score', 0)
if score >= 0.8:
print("🌟 算法性能优秀!")
elif score >= 0.6:
print("👍 算法性能良好!")
elif score >= 0.4:
print("⚡ 算法性能一般,有改进空间")
else:
print("🔧 算法性能需要显著改进")
except Exception as e:
print(f"❌ 运行失败: {e}")
import traceback
traceback.print_exc()
return 1
return 0
if __name__ == "__main__":
exit(main())