-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_mp.py
More file actions
117 lines (100 loc) · 3.41 KB
/
Copy pathplot_mp.py
File metadata and controls
117 lines (100 loc) · 3.41 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
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import math
# Sample data: Replace with your 10 lists of training losses
np.random.seed(0)
epochs = list(range(1, 1001))
num_mp = [1, 5, 9, 12]
# for i in range(35, 81, 5):
# num_dim.append(i)
training_loss = []
val_loss = []
for num in num_mp:
path = "plots/MNISTSuperpixels/4000_no_lr_decay/dln_mp_dim_100/mp_"+str(num)+"_dln_fl_dim_300/fl_1"
loss_list = [0] * 1000
val_loss_list = [0] * 1000
for i in range(10):
with open(path + "/train_loss_fold_" + str(i+1) + ".txt", "r") as f:
lines = f.readlines()
for j in range(1000):
loss_list[j] += math.log10(float(lines[j].strip()))
with open(path + "/test_loss_fold_" + str(i+1) + ".txt", "r") as f:
lines = f.readlines()
for j in range(1000):
val_loss_list[j] += math.log10(float(lines[j].strip()))
loss_list = [x / 10 for x in loss_list]
val_loss_list = [x / 10 for x in val_loss_list]
training_loss.append(loss_list)
val_loss.append(val_loss_list)
# Set the seaborn style to "whitegrid"
sns.set(style="whitegrid", font_scale=1.2, rc={"lines.linewidth": 1.5})
# Plot the figure
plt.figure(figsize=(10, 6))
# palette = sns.color_palette("coolwarm", 40) # High-contrast palette
# palette = sns.color_palette("Set1", 10) # Colorblind-friendly palette
# palette = sns.color_palette("Blues", 10)
# palette = sns.color_palette("Dark2", 10)
palette = [
'#FF00FF', '#00FFFF',
'#FFFF00',
'#0000FF',
'#00FF00',
# '#FF0000',
# "#FFA500",
# "#FF4500",
"#ADFF2F",
"#7FFF00",
"#00BFFF",
"#1E90FF",
"#FF69B4",
"#FF1493",
"#DA70D6",
"#BA55D3",
"#32CD32",
"#FFD700"
]
for idx, loss in enumerate(training_loss):
sns.lineplot(x=epochs, y=loss, label=f'train_mp={num_mp[idx]}', color=palette[idx])
v_loss = val_loss[idx]
sns.lineplot(x=epochs, y=v_loss, label=f'test_mp={num_mp[idx]}', color=palette[idx], linestyle='--')
# Labeling and aesthetics
plt.title('Loss Across Epochs for Our Model with Untrained MP', fontsize=16, weight='bold')
plt.xlabel('Epoch', fontsize=14)
plt.ylabel('Loss (log scale)', fontsize=14)
plt.ylim(-5, 3)
plt.legend(title='Models', fontsize=10, title_fontsize=12)
# plt.grid(True, linestyle='--', alpha=0.7)
plt.tight_layout()
plt.savefig('loss_non_linear_untrained_n_mp_mnist.pdf', format='pdf', bbox_inches='tight')
plt.show()
# sns.set(style="whitegrid", font_scale=1.2, rc={"lines.linewidth": 1.5})
# # Plot the figure
# plt.figure(figsize=(10, 6))
# palette = [
# '#FF00FF', '#00FFFF', '#FFFF00', '#0000FF', '#00FF00', '#FF0000',
# "#FFA500",
# "#FF4500",
# "#ADFF2F",
# "#7FFF00",
# "#00BFFF",
# "#1E90FF",
# "#FF69B4",
# "#FF1493",
# "#DA70D6",
# "#BA55D3",
# "#32CD32",
# "#FFD700"
# ]
# for idx, loss in enumerate(val_loss):
# sns.lineplot(x=epochs, y=loss, label=f'n_mp={num_mp[idx]}', color=palette[idx])
# # Labeling and aesthetics
# plt.title('Testing Loss Across Epochs for ours', fontsize=16, weight='bold')
# plt.xlabel('Epoch', fontsize=14)
# plt.ylabel('Testing Loss', fontsize=14)
# plt.ylim(-1, 1.5)
# plt.legend(title='Models', fontsize=10, title_fontsize=12)
# plt.grid(True, linestyle='--', alpha=0.7)
# plt.tight_layout()
# plt.savefig('ours_val_loss_non_linear_n_mp.png', dpi=300, bbox_inches='tight')
# plt.show()