This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathaccum_scores.py
executable file
·74 lines (64 loc) · 2.68 KB
/
accum_scores.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
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import os
import sys
import torch
import math
"""
A little utility script to accumulate average scores from logs across multiple runs
"""
def calc_scores(filenames):
scores = []
num_moves = []
expected_delta = []
expected_delta_win = []
scores_bomb0 = scores[:]
num_bombs = 0
my_expected_delta = 0
my_expected_delta_win = 0
for filename in filenames:
og, eg = 0, 0
for line in open(filename, 'r'):
fields = line.split()
if 'Final score' in line:
score, bomb = int(fields[4]), int(fields[6])
scores.append(score)
scores_bomb0.append(0 if bomb else score)
num_bombs += 1 if bomb else 0
expected_delta.append(my_expected_delta)
expected_delta_win.append(my_expected_delta_win)
my_expected_delta = 0
my_expected_delta_win = 0
if 'changed' in line:
num_moves.append(float(fields[-1]))
my_expected_delta += float(fields[5])
#expected_delta.append(float(fields[5]))
if len(fields) > 14:
my_expected_delta_win += float(fields[11])
#expected_delta_win.append(float(fields[11]))
scores = torch.Tensor(scores)
scores_bomb0 = torch.Tensor(scores_bomb0)
num_moves = torch.Tensor(num_moves)
expected_delta = torch.Tensor(expected_delta)
expected_delta_win = torch.Tensor(expected_delta_win)
N = scores.nelement()
win_frac = scores.eq(25).float().mean()
print(os.getcwd())
print("Count: %g Score: %g +/- %g Win: %g +/- %g" % (N, scores.mean(), scores.std() / math.sqrt(N), win_frac, math.sqrt(win_frac * (1 - win_frac) / N)))
print("# moves: %g Expected delta: %g +/- %g Win: %g +/- %g" % (num_moves.mean(), expected_delta.mean(), expected_delta.std() / math.sqrt(N), expected_delta_win.mean(), expected_delta_win.std() / math.sqrt(N)))
print("Bomb0 Score: %g +/- %g bomb: %g%% (%d / %d)" % (scores_bomb0.mean(), scores_bomb0.std() / math.sqrt(N), num_bombs / N * 100, num_bombs, N))
if __name__ == "__main__":
paths = sys.argv[1:]
files = []
for path in paths:
if os.path.isdir(path):
for filename in os.listdir(path):
if filename.startswith('task') and filename.endswith('.out'):
files.append(path + '/' + filename)
else:
files.append(path)
calc_scores(files)