File size: 2,362 Bytes
34e468d | 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 | import os
import argparse
def analyze_predictions(file_path):
total = 0
correct = 0
incorrect_start_end = 0
non_existence = 0
wrong_syntax = 0
with open(file_path, 'r') as f:
for line in f:
line = line.strip()
if not line:
continue
total += 1
parts = line.split()
# Find where symbol starts (first non-digit, non-'x')
symbol_start = len(parts)
for i, p in enumerate(parts):
if not (p.isdigit() or p == 'x'):
symbol_start = i
break
symbol = ' '.join(parts[symbol_start:]).strip()
if symbol == '':
correct += 1
elif symbol == 'incorrect start/end':
incorrect_start_end += 1
elif symbol.startswith('non-existence path'):
non_existence += 1
elif symbol == 'wrong syntax':
wrong_syntax += 1
# else: other, but according to code, only these
print(f"Total paths: {total}")
print(f"Correct paths: {correct} ({correct/total*100:.2f}%)")
print(f"Incorrect start/end: {incorrect_start_end} ({incorrect_start_end/total*100:.2f}%)")
print(f"Non-existence path: {non_existence} ({non_existence/total*100:.2f}%)")
print(f"Wrong syntax: {wrong_syntax} ({wrong_syntax/total*100:.2f}%)")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Analyze prediction results from test_simple.py')
parser.add_argument('--ckpt_iter', type=int, default=10000, help='Checkpoint iteration')
parser.add_argument('--config', type=str, default='1_1_120', help='Model config')
parser.add_argument('--dataset', type=str, default='simple_graph', help='Dataset name')
parser.add_argument('--num_nodes', type=int, default=100, help='Number of nodes')
parser.add_argument('--num_of_paths', type=int, default=20, help='Number of paths')
args = parser.parse_args()
out_dir = f'out/{args.dataset}_{args.config}_{args.num_nodes}/'
file_path = os.path.join(out_dir, f'pred_test_{args.ckpt_iter}.txt')
if os.path.exists(file_path):
analyze_predictions(file_path)
else:
print(f"File {file_path} not found.") |