-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
35 lines (26 loc) · 1.01 KB
/
utils.py
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
import argparse
import collections
import functools
import operator
from typing import List
def create_experiment_name(args: argparse.Namespace) -> str:
"""
Create an experiment name according to the specified arguments `args`.
Args:
args: the arguments that define the experiment being run
"""
experiment_name = f'{args.dataset}_{args.attack}_{args.eps}'
if args.attack == 'IAF':
experiment_name += f'{args.lamda}'
return experiment_name
def get_average_results(results: List[dict], num_runs: int) -> dict:
"""
Calculate the average values for each metric in the results.
Args:
results: a list of dicts with the results of every run
num_runs: the number of successful runs that were executed
Returns: a dict with the average results
"""
average_results = dict(functools.reduce(operator.add, map(collections.Counter, results)))
average_results = {k: v / num_runs for k, v in average_results.items()}
return average_results