-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgen_sensitivity.py
More file actions
63 lines (51 loc) · 1.88 KB
/
gen_sensitivity.py
File metadata and controls
63 lines (51 loc) · 1.88 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
import matplotlib.pyplot as plt
import numpy as np
# --------------------------
# 1. Sensitivity Data
# --------------------------
labels = [
"Population Size",
"Generations",
"Tournament Size",
"Crossover Probability",
"Mutation Rate"
]
cost_sensitivity = np.array([0.081, 0.065, 0.034, 0.141, 0.132])
runtime_sensitivity = np.array([0.15, 0.110, 0.004, 0.003, 0.003])
# --------------------------
# 2. Prepare Data for Radar Chart
# --------------------------
labels_radar = labels + [labels[0]]
cost_radar = np.append(cost_sensitivity, cost_sensitivity[0])
runtime_radar = np.append(runtime_sensitivity, runtime_sensitivity[0])
angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()
angles += angles[:1]
# --------------------------
# 3. Create Radar Plot
# --------------------------
plt.style.use("ggplot")
fig, ax = plt.subplots(figsize=(14, 8), subplot_kw=dict(polar=True))
# Plot lines
ax.plot(angles, cost_radar, 'o-', linewidth=3, color='steelblue', label='Cost Sensitivity')
ax.fill(angles, cost_radar, color='steelblue', alpha=0.2)
ax.plot(angles, runtime_radar, 's--', linewidth=3, color='darkorange', label='Runtime Sensitivity')
ax.fill(angles, runtime_radar, color='darkorange', alpha=0.2)
# Axis labels
ax.set_thetagrids(np.degrees(angles[:-1]), labels, fontsize=30, fontweight='bold')
# Radial tick settings
ax.set_ylim(0, 0.15)
ax.set_yticks([0.05, 0.10, 0.15])
ax.set_yticklabels(["0.05", "0.10", "0.15"], fontsize=30, fontweight='bold')
ax.set_rlabel_position(200)
# Title and Legend
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.1), ncol=2, fontsize=24)
plt.subplots_adjust(bottom=0.2)
# Clean layout
plt.tight_layout()
# --------------------------
# 4. Save and Show Plot
# --------------------------
output_file = 'hyperparameter_sensitivity_radar.png'
plt.savefig(output_file, dpi=300)
plt.show()
print(f"Saved radar chart to: {output_file}")