forked from YuxiChen25/TF-MDP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_probe_data_random.py
124 lines (94 loc) · 3.97 KB
/
parse_probe_data_random.py
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
import argparse
import re
import numpy as np
from collections import defaultdict
def main():
input_file_path = rf'random_probes/rl/test_losses.txt'
pattern = re.compile(r"Random Seed \d+ losses: ([\d\.]+),\s*([\d\.]+)")
data = defaultdict(list)
with open(input_file_path, 'r') as file:
lines = file.readlines()
for line in lines:
print(line)
match = pattern.match(line.strip())
if match:
a = float(match.group(1))
b = float(match.group(2))
data['a'].append(a)
data['b'].append(b)
output_file_path = rf'random_test_loss.txt'
with open(output_file_path, 'w') as output_file:
mean_a = np.mean(data['a'])
std_a = np.std(data['a'], ddof=1)
mean_b = np.mean(data['b'])
std_b = np.std(data['b'], ddof=1)
output_file.write(f"Random Test Loss Linear: Mean={mean_a:.6f}, Std={std_a:.6f}, "
f"Nonlinear: Mean={mean_b:.6f}, Std={std_b:.6f}\n")
input_file_path = rf'random_probes/mcts/test_losses.txt'
pattern = re.compile(r"Random Seed \d+ losses: ([\d\.]+),\s*([\d\.]+)")
data = defaultdict(list)
with open(input_file_path, 'r') as file:
lines = file.readlines()
for line in lines:
print(line)
match = pattern.match(line.strip())
if match:
a = float(match.group(1))
b = float(match.group(2))
data['a'].append(a)
data['b'].append(b)
output_file_path = rf'random_test_loss_mcts.txt'
with open(output_file_path, 'w') as output_file:
mean_a = np.mean(data['a'])
std_a = np.std(data['a'], ddof=1)
mean_b = np.mean(data['b'])
std_b = np.std(data['b'], ddof=1)
output_file.write(f"Random Test Loss Linear: Mean={mean_a:.6f}, Std={std_a:.6f}, "
f"Nonlinear: Mean={mean_b:.6f}, Std={std_b:.6f}\n")
input_file_path = rf'random_probes/rl/test_losses_mse.txt'
pattern = re.compile(r"Random Seed \d+ losses: ([\d\.]+),\s*([\d\.]+)")
data = defaultdict(list)
with open(input_file_path, 'r') as file:
lines = file.readlines()
for line in lines:
print(line)
match = pattern.match(line.strip())
if match:
a = float(match.group(1))
b = float(match.group(2))
data['a'].append(a)
data['b'].append(b)
output_file_path = rf'random_test_loss_mse.txt'
with open(output_file_path, 'w') as output_file:
mean_a = np.mean(data['a'])
std_a = np.std(data['a'], ddof=1)
mean_b = np.mean(data['b'])
std_b = np.std(data['b'], ddof=1)
output_file.write(f"Random Test Loss Linear: Mean={mean_a:.6f}, Std={std_a:.6f}, "
f"Nonlinear: Mean={mean_b:.6f}, Std={std_b:.6f}\n")
input_file_path = rf'random_probes/mcts/test_losses_mse.txt'
pattern = re.compile(r"Random Seed \d+ losses: ([\d\.]+),\s*([\d\.]+)")
data = defaultdict(list)
with open(input_file_path, 'r') as file:
lines = file.readlines()
for line in lines:
print(line)
match = pattern.match(line.strip())
if match:
a = float(match.group(1))
b = float(match.group(2))
data['a'].append(a)
data['b'].append(b)
if not match:
print(line)
print("what")
output_file_path = rf'random_test_loss_mcts_mse.txt'
with open(output_file_path, 'w') as output_file:
mean_a = np.mean(data['a'])
std_a = np.std(data['a'], ddof=1)
mean_b = np.mean(data['b'])
std_b = np.std(data['b'], ddof=1)
output_file.write(f"Random Test Loss Linear: Mean={mean_a:.6f}, Std={std_a:.6f}, "
f"Nonlinear: Mean={mean_b:.6f}, Std={std_b:.6f}\n")
if __name__ == "__main__":
main()