-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_all_FedAsync.py
More file actions
62 lines (53 loc) · 2.06 KB
/
Copy pathplot_all_FedAsync.py
File metadata and controls
62 lines (53 loc) · 2.06 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
import json
import matplotlib.pyplot as plt
import numpy as np
# Use consistent, paper-style appearance
plt.rcParams.update({
"font.size": 13,
"axes.labelweight": "bold",
"axes.titleweight": "bold",
"axes.grid": True,
"grid.linestyle": "--",
"grid.alpha": 0.3,
"figure.dpi": 150,
})
def smooth_curve(y, window=5):
if len(y) < window:
return y
return np.convolve(y, np.ones(window)/window, mode='valid')
# Map of constellation name to result file
files = {
"Baseline (All Visible)": "results/results_FedAsync/FedAsync_baseline.json",
"Walker Star": "results/results_FedAsync/FedAsync_walker_star.json",
"Polar SSO": "results/results_FedAsync/FedAsync_polar_sso.json",
"Inclined Sparse": "results/results_FedAsync/FedAsync_inclined_sparse.json",
"Retrograde Polar": "results/results_FedAsync/FedAsync_retrograde_polar.json",
"Equatorial": "results/results_FedAsync/FedAsync_equatorial.json",
}
# Square-shaped figure (equal width and height)
plt.figure(figsize=(8, 6)) # Increased width from 6 to 8
legend_labels = []
for label, path in files.items():
with open(path, "r") as f:
data = json.load(f)
times = np.array(data["times"])
accs = np.array(data["accuracies"])
accs_smooth = smooth_curve(accs, window=3)
times_smooth = times[1:-1] # Align with smoothing
# Calculate average round time for this constellation
wall_clock_durations = data.get("wall_clock_durations", [])
avg_time = np.mean(wall_clock_durations) if wall_clock_durations else None
if avg_time:
legend_label = f"{label} (Avg. round time: {avg_time:.1f}s)"
else:
legend_label = label
plt.plot(times_smooth, accs_smooth, label=legend_label, linewidth=2)
plt.title("FedAsync: Central Test Accuracy Across Constellations")
plt.xlabel("Simulated Time (hours)")
plt.ylabel("Central Test Accuracy")
plt.legend(fontsize=10, loc="lower right")
plt.grid(True)
plt.tight_layout()
plt.xlim(times[1], times[-2]) # Set x-axis to data range
plt.margins(x=0)
plt.savefig("FedAsync_all_constellations.png", dpi=300)