1 | import sys
|
---|
2 |
|
---|
3 | import numpy as np
|
---|
4 |
|
---|
5 |
|
---|
6 | # Function of the metric to use
|
---|
7 | # data -> dictionary of collected information
|
---|
8 | # output -> dictionary of each agent with a float metric assigned to them, and the counter
|
---|
9 | def metric(data):
|
---|
10 | ranking = {}
|
---|
11 | # Utility averages in domains
|
---|
12 | utilities = dict()
|
---|
13 | welfare = dict()
|
---|
14 | for result in data:
|
---|
15 | for thing in result:
|
---|
16 | counter = sys.maxsize
|
---|
17 | for key in thing:
|
---|
18 | if 'agent_' in key:
|
---|
19 | temp = key.split('_')
|
---|
20 | if int(temp[1]) < counter:
|
---|
21 | counter = int(temp[1])
|
---|
22 | if thing['result'] != 'failed':
|
---|
23 | first_agent = thing['agent_' + str(counter)]
|
---|
24 | other_agent = thing['agent_' + str(counter + 1)]
|
---|
25 | if other_agent not in utilities:
|
---|
26 | utilities[other_agent] = []
|
---|
27 | welfare[other_agent] = []
|
---|
28 | if first_agent not in utilities:
|
---|
29 | utilities[first_agent] = []
|
---|
30 | welfare[first_agent] = []
|
---|
31 | utilities[first_agent].append(thing['utility_' + str(counter)])
|
---|
32 | welfare[first_agent].append(thing['social_welfare'])
|
---|
33 | utilities[other_agent].append(thing['utility_' + str(counter + 1)])
|
---|
34 | welfare[other_agent].append(thing['social_welfare'])
|
---|
35 | # Metric of Z-Score of each agent
|
---|
36 | # Ideal mean should be 0.75
|
---|
37 | ideal_utility = 0.75
|
---|
38 | ideal_welfare = 1.2
|
---|
39 | for agent in utilities:
|
---|
40 | utility_mean = np.mean(utilities[agent])
|
---|
41 | welfare_mean = np.mean(welfare[agent])
|
---|
42 | utility_std = np.std(utilities[agent])
|
---|
43 | welfare_std = np.std(welfare[agent])
|
---|
44 | z_score_utility = (utility_mean - ideal_utility) / max(0.0001, utility_std)
|
---|
45 | z_score_welfare = (welfare_mean - ideal_welfare) / max(0.0001, welfare_std)
|
---|
46 | # Average Z-score between Z-score of utility and Z-score of welfare
|
---|
47 | ranking[agent] = (z_score_utility + z_score_welfare) / 2
|
---|
48 | return ranking
|
---|