MCPcopy Create free account
hub / github.com/alexrame/fishr / SelectionMethod

Class SelectionMethod

domainbed/model_selection.py:11–52  ·  view source on GitHub ↗

Abstract class whose subclasses implement strategies for model selection across hparams and timesteps.

Source from the content-addressed store, hash-verified

9 return records.filter(lambda r: len(r['args']['test_envs']) == 1)
10
11class SelectionMethod:
12 """Abstract class whose subclasses implement strategies for model
13 selection across hparams and timesteps."""
14
15 def __init__(self):
16 raise TypeError
17
18 @classmethod
19 def run_acc(self, run_records):
20 """
21 Given records from a run, return a {val_acc, test_acc} dict representing
22 the best val-acc and corresponding test-acc for that run.
23 """
24 raise NotImplementedError
25
26 @classmethod
27 def hparams_accs(self, records):
28 """
29 Given all records from a single (dataset, algorithm, test env) pair,
30 return a sorted list of (run_acc, records) tuples.
31 """
32 return (records.group('args.hparams_seed')
33 .map(lambda _, run_records:
34 (
35 self.run_acc(run_records),
36 run_records
37 )
38 ).filter(lambda x: x[0] is not None)
39 .sorted(key=lambda x: x[0]['val_acc'])[::-1]
40 )
41
42 @classmethod
43 def sweep_acc(self, records):
44 """
45 Given all records from a single (dataset, algorithm, test env) pair,
46 return the mean test acc of the k runs with the top val accs.
47 """
48 _hparams_accs = self.hparams_accs(records)
49 if len(_hparams_accs):
50 return _hparams_accs[0][0]['test_acc']
51 else:
52 return None
53
54class OracleSelectionMethod(SelectionMethod):
55 """Like Selection method which picks argmax(test_out_acc) across all hparams

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected