-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganize_attack_results.py
More file actions
197 lines (134 loc) · 6.32 KB
/
organize_attack_results.py
File metadata and controls
197 lines (134 loc) · 6.32 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import pandas as pd
import matplotlib.pyplot as plt
# --- CONFIG -------------------------------------------------------------
CSV_PATH = "new_results_with_seed.csv" # ← change to your file name if different
OUT_PNG = "graficos/Acurácia por Ruido.png"
# ------------------------------------------------------------------------
# 1) Load the CSV
df = pd.read_csv(CSV_PATH)
# Helper function to plot and save MSE for Noise Scale 50
def plot_MSE(data, method, title, filename):
filtered = data[(data['Round'] == 50) & (data['Method'] == method) & (data['Noise Scale'] == 0.0)]
# Group by Label and take mean MSE (in case there are multiple entries)
grouped = filtered.groupby('Label')['MSE'].mean()
plt.figure()
grouped.plot(kind='bar', rot=0)
plt.xlabel('Classe', fontsize=25)
plt.ylabel('MSE', fontsize=25)
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.grid(True)
plt.savefig(filename, bbox_inches='tight')
plt.close()
# Plot and save for each requested condition
plot_MSE(df, method='loss', title='MSE for Min Client - Loss Attack at Round 50', filename='graficos/MSE_por_classe.png')
def plot_MSE_over_Noise_Scales(data, filename):
filtered = data[(data['Round'] == 50) & (data['Noise Scale'] < 0.06)]
# Mapeamento de nomes e estilos
name_mapping = {'loss': 'Gradiente', 'naive': 'Ingênua'}
style_mapping = {'loss': '-', 'naive': '--'}
# Agrupa por Noise Scale e Method, tirando a média do MSE (média sobre todas as labels)
grouped = filtered.groupby(['Noise Scale', 'Method'])['MSE'].mean().reset_index()
plt.figure()
for method in grouped['Method'].unique():
method_data = grouped[grouped['Method'] == method]
plt.plot(
method_data['Noise Scale'],
method_data['MSE'],
label=name_mapping.get(method, method),
linestyle=style_mapping.get(method, '-'),
linewidth=2.5 # Aumenta a espessura da linha
)
plt.xlabel('Ruído', fontsize=25)
plt.ylabel('MSE', fontsize=25)
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.grid(True)
plt.legend(fontsize=16)
plt.savefig(filename, bbox_inches='tight')
plt.close()
plot_MSE_over_Noise_Scales(df, filename='graficos/MSE_por_ruido_médio.png')
# Helper function to plot and save PSNR for Noise Scale 50
def plot_PSNR(data, method, title, filename):
filtered = data[(data['Round'] == 50) & (data['Method'] == method) & (data['Noise Scale'] == 0.0)]
# Group by Label and take mean PSNR (in case there are multiple entries)
grouped = filtered.groupby('Label')['PSNR'].mean()
plt.figure()
grouped.plot(kind='bar', rot=0)
plt.xlabel('Classe', fontsize=25)
plt.ylabel('PSNR', fontsize=25)
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.grid(True)
plt.savefig(filename, bbox_inches='tight')
plt.close()
# Plot and save for each requested condition
plot_PSNR(df, method='loss', title='PSNR for Min Client - Loss Attack at Round 50', filename='graficos/PSNR_por_classe.png')
def plot_PSNR_over_Noise_Scales(data, filename):
filtered = data[(data['Round'] == 50) & (data['Noise Scale'] < 0.06)]
# Mapeamento de nomes e estilos
name_mapping = {'loss': 'Gradiente', 'naive': 'Ingênua'}
style_mapping = {'loss': '-', 'naive': '--'}
# Agrupa por Noise Scale e Method, tirando a média do PSNR (média sobre todas as labels)
grouped = filtered.groupby(['Noise Scale', 'Method'])['PSNR'].mean().reset_index()
plt.figure()
for method in grouped['Method'].unique():
method_data = grouped[grouped['Method'] == method]
plt.plot(
method_data['Noise Scale'],
method_data['PSNR'],
label=name_mapping.get(method, method),
linestyle=style_mapping.get(method, '-'),
linewidth=2.5 # Aumenta a espessura da linha
)
plt.xlabel('Ruído', fontsize=25)
plt.ylabel('PSNR', fontsize=25)
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.grid(True)
plt.legend(fontsize=16)
plt.savefig(filename, bbox_inches='tight')
plt.close()
plot_PSNR_over_Noise_Scales(df, filename='graficos/PSNR_por_ruido_médio.png')
# Helper function to plot and save SSIM for Noise Scale 50
def plot_SSIM(data, method, title, filename):
filtered = data[(data['Round'] == 50) & (data['Method'] == method) & (data['Noise Scale'] == 0.0)]
# Group by Label and take mean SSIM (in case there are multiple entries)
grouped = filtered.groupby('Label')['SSIM'].mean()
plt.figure()
grouped.plot(kind='bar', rot=0)
plt.xlabel('Classe', fontsize=25)
plt.ylabel('SSIM', fontsize=25)
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.grid(True)
plt.savefig(filename, bbox_inches='tight')
plt.close()
# Plot and save for each requested condition
plot_SSIM(df, method='loss', title='SSIM for Min Client - Loss Attack at Round 50', filename='graficos/SSIM_por_classe.png')
def plot_SSIM_over_Noise_Scales(data, filename):
filtered = data[(data['Round'] == 50) & (data['Noise Scale'] < 0.06)]
# Mapeamento de nomes e estilos
name_mapping = {'loss': 'Gradiente', 'naive': 'Ingênua'}
style_mapping = {'loss': '-', 'naive': '--'}
# Agrupa por Noise Scale e Method, tirando a média do SSIM (média sobre todas as labels)
grouped = filtered.groupby(['Noise Scale', 'Method'])['SSIM'].mean().reset_index()
plt.figure()
for method in grouped['Method'].unique():
method_data = grouped[grouped['Method'] == method]
plt.plot(
method_data['Noise Scale'],
method_data['SSIM'],
label=name_mapping.get(method, method),
linestyle=style_mapping.get(method, '-'),
linewidth=2.5 # Aumenta a espessura da linha
)
plt.xlabel('Ruído', fontsize=25)
plt.ylabel('SSIM', fontsize=25)
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.grid(True)
plt.legend(fontsize=16)
plt.savefig(filename, bbox_inches='tight')
plt.close()
plot_SSIM_over_Noise_Scales(df, filename='graficos/SSIM_por_ruido_médio.png')