Cut-Aware Augmentation Filtering / robustness.py
Mechanism confirmed, baseline not beaten
1import json
2import numpy as np
3from experiment import make_data, graph_from_x, cut_ratio, train_once, SEED
4
5def run(seed):
6 X, y = make_data(seed)
7 rng = np.random.RandomState(seed + 101)
8 policies = [X, X + rng.randn(*X.shape).astype('float32') * 0.18,
9 X[rng.permutation(len(X))]]
10 graphs = [graph_from_x(z, k=10, sigma=0.8) for z in policies]
11 cuts = [cut_ratio(W, y) for W in graphs]
12 uniform = train_once('uniform', X, y, graphs, cuts, seed + 17)
13 cut = train_once('cut', X, y, graphs, cuts, seed + 17)
14 return {
15 'seed': seed, 'cuts': cuts,
16 'uniform_accuracy': uniform['accuracy'],
17 'cut_accuracy': cut['accuracy'],
18 'uniform_pred_cut': uniform['pred_cut_uniform_graph'],
19 'cut_pred_cut': cut['pred_cut_uniform_graph'],
20 'cut_q': cut['q']
21 }
22
23rows = [run(s) for s in [SEED, SEED + 1, SEED + 2]]
24out = {'runs': rows}
25for key in ['uniform_accuracy', 'cut_accuracy', 'uniform_pred_cut', 'cut_pred_cut']:
26 values = np.array([r[key] for r in rows])
27 out[key + '_mean'] = float(values.mean())
28 out[key + '_std'] = float(values.std())
29print(json.dumps(out, indent=2))
30with open('robustness.json', 'w') as f:
31 json.dump(out, f, indent=2)