-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_step_aligned.py
More file actions
44 lines (36 loc) · 1.5 KB
/
Copy pathplot_step_aligned.py
File metadata and controls
44 lines (36 loc) · 1.5 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
import torch
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams.update({
"font.size": 16, # 默认文字
"axes.titlesize": 16, # 子图标题
"axes.labelsize": 16, # x/y 轴标题
"xtick.labelsize": 16, # x 轴刻度
"ytick.labelsize": 16, # y 轴刻度
"legend.fontsize": 16,
})
h_sgd = torch.load("hist_sgd.pt")
h_cover = torch.load("hist_cover.pt")
h_civr = torch.load("hist_civr.pt")
fig, axes = plt.subplots(2, 1, figsize=(6, 6), sharex=True)
# =====================================================
# (1) Test Accuracy
# =====================================================
axes[0].plot(h_sgd["step"], h_sgd["test_acc"], label="ERM-SGD", linewidth=2)
axes[0].plot(h_cover["step"], h_cover["test_acc"], label="COVER", linewidth=2)
axes[0].plot(h_civr["step"], h_civr["test_acc"], label="CIVR", linewidth=2)
axes[0].set_ylabel("Test Accuracy (%)")
axes[0].legend()
axes[0].grid(alpha=0.3)
# =====================================================
# (2) Train CE Loss
# =====================================================
axes[1].plot(h_sgd["step"], h_sgd["train_ce"], label="ERM-SGD", linewidth=2)
axes[1].plot(h_cover["step"], h_cover["train_ce"], label="COVER", linewidth=2)
axes[1].plot(h_civr["step"], h_civr["train_ce"], label="CIVR", linewidth=2)
axes[1].set_xlabel("Oracle calls (samples)")
axes[1].set_ylabel("Train CE Loss")
axes[1].grid(alpha=0.3)
plt.tight_layout()
plt.savefig("step_aligned_acc_ce.png", dpi=200)
plt.show()