-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_test.py
More file actions
66 lines (54 loc) · 2.07 KB
/
plot_test.py
File metadata and controls
66 lines (54 loc) · 2.07 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
import os
import sys
import json
import time
import matplotlib.pyplot as plt
def plot_results(choices, correctness, model_name="model"):
output_dir = "plot_results"
os.makedirs(output_dir, exist_ok=True)
timestamp = time.strftime("%Y%m%d-%H%M%S")
safe_model_name = model_name.replace("/", "_")
iterations = list(range(1, len(choices) + 1))
# Plot 1: Choices Over Iterations
plt.figure(figsize=(10, 4))
plt.step(iterations, choices, where='post')
plt.xlabel('Iteration')
plt.ylabel('AI Choice (Slot Machine)')
plt.title(f'AI Slot Machine Choices Over Iterations\nModel: {model_name}')
plt.yticks(sorted(set(choices)))
plt.grid(True)
choice_path = os.path.join(output_dir, f"choices_plot_{safe_model_name}_{timestamp}.png")
plt.savefig(choice_path)
plt.close()
print(f"Saved choices plot to: {choice_path}")
# Plot 2: Correctness Over Iterations
plt.figure(figsize=(10, 4))
plt.plot(iterations, correctness, marker='o')
plt.xlabel('Iteration')
plt.ylabel('Cumulative Correct Choice Ratio')
plt.title(f"AI's Correct Choice Ratio Over Iterations\nModel: {model_name}")
plt.ylim(0, 1)
plt.grid(True)
correctness_path = os.path.join(output_dir, f"correctness_plot_{safe_model_name}_{timestamp}.png")
plt.savefig(correctness_path)
plt.close()
print(f"Saved correctness plot to: {correctness_path}")
def main():
if len(sys.argv) < 2:
print("Usage: python plot_test.py <results_file.json>")
sys.exit(1)
results_file = sys.argv[1]
if not os.path.isfile(results_file):
print(f"File not found: {results_file}")
sys.exit(1)
with open(results_file, "r") as f:
data = json.load(f)
model_name = data.get("model", "unknown_model")
choices = data.get("choices", [])
correctness = data.get("correctness", [])
if not choices or not correctness:
print("Error: 'choices' or 'correctness' data missing or empty in JSON.")
sys.exit(1)
plot_results(choices, correctness, model_name)
if __name__ == "__main__":
main()