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

Method _step_acc

domainbed/model_selection.py:107–131  ·  view source on GitHub ↗

Return the {val_acc, test_acc} for a group of records corresponding to a single step.

(self, records)

Source from the content-addressed store, hash-verified

105
106 @classmethod
107 def _step_acc(self, records):
108 """Return the {val_acc, test_acc} for a group of records corresponding
109 to a single step."""
110 test_records = get_test_records(records)
111 if len(test_records) != 1:
112 return None
113
114 test_env = test_records[0]['args']['test_envs'][0]
115 n_envs = 0
116 for i in itertools.count():
117 if f'env{i}_out_acc' not in records[0]:
118 break
119 n_envs += 1
120 val_accs = np.zeros(n_envs) - 1
121 for r in records.filter(lambda r: len(r['args']['test_envs']) == 2):
122 val_env = (set(r['args']['test_envs']) - set([test_env])).pop()
123 val_accs[val_env] = r['env{}_in_acc'.format(val_env)]
124 val_accs = list(val_accs[:test_env]) + list(val_accs[test_env+1:])
125 if any([v==-1 for v in val_accs]):
126 return None
127 val_acc = np.sum(val_accs) / (n_envs-1)
128 return {
129 'val_acc': val_acc,
130 'test_acc': test_records[0]['env{}_in_acc'.format(test_env)]
131 }
132
133 @classmethod
134 def run_acc(self, records):

Callers 1

run_accMethod · 0.95

Calls 3

get_test_recordsFunction · 0.85
filterMethod · 0.80
sumMethod · 0.80

Tested by

no test coverage detected