| 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()
|
|
|
| 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
|
|
|
|
|
| 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.") |