-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_dim.py
More file actions
122 lines (105 loc) · 3.55 KB
/
Copy pathplot_dim.py
File metadata and controls
122 lines (105 loc) · 3.55 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
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_dim = [2, 8, 32, 128]
# for i in range(35, 81, 5):
# num_dim.append(i)
print(num_dim)
print(len(num_dim))
training_loss = []
val_loss = []
for num in num_dim:
path = "plots/REDDIT-BINARY/dln"+str(num)+"/mp_3/fl_5"
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()))
# loss_list[j] += float(lines[j].strip())
with open(path + "/val_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()))
# val_loss_list[j] += 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=(12, 8))
# 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_width={num_dim[idx]}', color=palette[idx])
v_loss = val_loss[idx]
sns.lineplot(x=epochs, y=v_loss, label=f'test_width={num_dim[idx]}', color=palette[idx], linestyle='--')
# Labeling and aesthetics
plt.title('Training and Testing 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(-0.7, 1.0)
plt.legend(title='Models', fontsize=10, title_fontsize=12)
# plt.grid(True, linestyle='--', alpha=0.7)
plt.tight_layout()
plt.savefig('ours_loss_non_linear_untrained_mp_n_dim.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_dim={num_dim[idx]}', color=palette[idx])
# # Labeling and aesthetics
# plt.title('Testing Loss Across Epochs for GCN', fontsize=16, weight='bold')
# plt.xlabel('Epoch', fontsize=14)
# plt.ylabel('Testing Loss', fontsize=14)
# plt.ylim(-2.7, -1)
# plt.legend(title='Models', fontsize=10, title_fontsize=12)
# plt.grid(True, linestyle='--', alpha=0.7)
# plt.tight_layout()
# plt.savefig('gcn_val_loss_n_dim.png', dpi=300, bbox_inches='tight')
# plt.show()