mirror of
https://github.com/ION606/COGMOD-HWI.git
synced 2026-05-14 22:16:57 +00:00
added combined data
This commit is contained in:
+16
-16
@@ -3,15 +3,16 @@ import json
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
BASE_DIR = "./on_GPU"
|
||||
# BASE_DIR = "./on_GPU"
|
||||
|
||||
# training diagnostics
|
||||
histories = []
|
||||
for csv in glob.glob(f"{BASE_DIR}/analytics/history_*.csv"):
|
||||
df = pd.read_csv(csv) # epochs x metrics
|
||||
tag = "_".join(csv.split("_")[1:4]) # like sgd_none_42.csv
|
||||
df['condition'] = tag.replace(".csv", "")
|
||||
histories.append(df)
|
||||
for BASE_DIR in ['./on_CPU', './on_GPU']:
|
||||
for csv in glob.glob(f"{BASE_DIR}/analytics/history_*.csv"):
|
||||
df = pd.read_csv(csv) # epochs x metrics
|
||||
tag = "_".join(csv.split("_")[1:4]) # like sgd_none_42.csv
|
||||
df['condition'] = tag.replace(".csv", "")
|
||||
histories.append(df)
|
||||
|
||||
logs = pd.concat(histories, ignore_index=True)
|
||||
|
||||
@@ -20,9 +21,9 @@ mean_log = logs.groupby('epoch').mean(numeric_only=True)
|
||||
|
||||
plt.figure()
|
||||
plt.plot(mean_log.index, mean_log['train_acc'],
|
||||
color='tab:blue', label='train')
|
||||
color='#228B22', label='train')
|
||||
plt.plot(mean_log.index, mean_log['test_acc'],
|
||||
color='tab:orange', label='validation')
|
||||
color='#800080', label='validation')
|
||||
plt.xlabel("epoch")
|
||||
plt.ylabel("accuracy")
|
||||
plt.legend()
|
||||
@@ -31,14 +32,13 @@ ax = plt.gca()
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f"{BASE_DIR}/train_val_accuracy.png")
|
||||
plt.savefig(f"train_val_accuracy.png")
|
||||
|
||||
# Plot train vs validation loss
|
||||
plt.figure()
|
||||
plt.plot(mean_log.index, mean_log['train_loss'],
|
||||
color='tab:blue', label='train')
|
||||
color='#008080', label='train') # teal
|
||||
plt.plot(mean_log.index, mean_log['test_loss'],
|
||||
color='tab:orange', label='validation')
|
||||
color='#FF00FF', label='validation') # magenta
|
||||
plt.xlabel("epoch")
|
||||
plt.ylabel("cross‑entropy loss")
|
||||
plt.legend()
|
||||
@@ -47,10 +47,10 @@ ax = plt.gca()
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f"{BASE_DIR}/train_val_loss.png")
|
||||
plt.savefig(f"train_val_loss.png")
|
||||
|
||||
# robustness curves
|
||||
with open(f"{BASE_DIR}/results.json") as f:
|
||||
with open(f"./combined_results.json") as f:
|
||||
res = json.load(f)
|
||||
|
||||
df = pd.DataFrame(res)
|
||||
@@ -68,7 +68,7 @@ for _, row in df.iterrows():
|
||||
rob_df = pd.DataFrame(records)
|
||||
pivot = rob_df.groupby(['optimizer', 'sigma']).acc.mean().unstack(0)
|
||||
|
||||
ax = pivot.plot(marker='o', linestyle='-', color=['#0072B2', '#D55E00'])
|
||||
ax = pivot.plot(marker='o', linestyle='-', color=['#FF0000', '#00008B'])
|
||||
plt.xlabel("Gaussian noise sigma")
|
||||
plt.ylabel("accuracy")
|
||||
plt.title("Noise robustness")
|
||||
@@ -76,5 +76,5 @@ plt.grid(True)
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f"{BASE_DIR}/robustness_curve.png")
|
||||
plt.savefig(f"./robustness_curve.png")
|
||||
print("saved robustness_curve.png")
|
||||
|
||||
Reference in New Issue
Block a user