Spaces:
No application file
No application file
File size: 2,589 Bytes
0033d19 | 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 | import json
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
def plot():
with open("results.json") as f:
data = json.load(f)
rl_rewards = [r[0] for r in data["rl_episodes"]]
base_rewards = [r[0] for r in data["baseline_episodes"]]
rl = data["rl"]
base = data["baseline"]
fig, axes = plt.subplots(2, 2, figsize=(12, 8))
fig.suptitle("RL Study Scheduler vs Heuristic Baseline", fontsize=14, fontweight="bold")
# 1. Reward over episodes
ax = axes[0][0]
ax.plot(rl_rewards, color="#1D9E75", label="RL Agent", linewidth=1.5)
ax.plot(base_rewards, color="#D85A30", label="Baseline", linewidth=1.5, linestyle="--")
ax.set_title("Reward per Episode")
ax.set_xlabel("Episode")
ax.set_ylabel("Total Reward")
ax.legend()
ax.grid(True, alpha=0.3)
# 2. Tasks completed
ax = axes[0][1]
bars = ax.bar(["RL Agent", "Baseline"],
[rl["avg_tasks_completed"], base["avg_tasks_completed"]],
color=["#1D9E75", "#D85A30"])
ax.set_title("Avg Tasks Completed")
ax.set_ylabel("Tasks")
for bar in bars:
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.05,
f'{bar.get_height():.2f}', ha='center', va='bottom', fontsize=11)
ax.grid(True, alpha=0.3, axis='y')
# 3. Efficiency score
ax = axes[1][0]
bars = ax.bar(["RL Agent", "Baseline"],
[rl["avg_efficiency_score"], base["avg_efficiency_score"]],
color=["#1D9E75", "#D85A30"])
ax.set_title("Avg Efficiency Score (0–1)")
ax.set_ylabel("Efficiency")
ax.set_ylim(0, 1.1)
for bar in bars:
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.01,
f'{bar.get_height():.2f}', ha='center', va='bottom', fontsize=11)
ax.grid(True, alpha=0.3, axis='y')
# 4. Stress comparison
ax = axes[1][1]
bars = ax.bar(["RL Agent", "Baseline"],
[rl["avg_stress"], base["avg_stress"]],
color=["#1D9E75", "#D85A30"])
ax.set_title("Avg Final Stress (lower = better)")
ax.set_ylabel("Stress (0–100)")
ax.set_ylim(0, 100)
for bar in bars:
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.5,
f'{bar.get_height():.1f}', ha='center', va='bottom', fontsize=11)
ax.grid(True, alpha=0.3, axis='y')
plt.tight_layout()
plt.savefig("comparison_results.png", dpi=150, bbox_inches="tight")
print("Saved: comparison_results.png")
plt.show()
if __name__ == "__main__":
plot()
|