@@ -91,26 +91,51 @@ def compute_normalised_cooperation(interactions):
91
91
def compute_state_distribution (interactions ):
92
92
"""
93
93
Returns the count of each state for a set of interactions.
94
+
95
+ Parameters
96
+ ----------
97
+ interactions : list of tuples
98
+ A list containing the interactions of the match as shown at the top of
99
+ this file.
100
+
101
+ Returns
102
+ ----------
103
+ Counter(interactions) : Counter Object
104
+ Dictionary where the keys are the states and the values are the number
105
+ of times that state occurs.
94
106
"""
95
- if len ( interactions ) == 0 :
107
+ if not interactions :
96
108
return None
97
109
return Counter (interactions )
98
110
99
111
100
112
def compute_normalised_state_distribution (interactions ):
101
113
"""
102
114
Returns the normalized count of each state for a set of interactions.
115
+
116
+ Parameters
117
+ ----------
118
+ interactions : list of tuples
119
+ A list containing the interactions of the match as shown at the top of
120
+ this file.
121
+
122
+ Returns
123
+ ----------
124
+ normalized_count : Counter Object
125
+ Dictionary where the keys are the states and the values are a normalized
126
+ count of the number of times that state occurs.
103
127
"""
104
- if len ( interactions ) == 0 :
128
+ if not interactions :
105
129
return None
106
130
107
- normalized_count = Counter (interactions )
108
- total = sum (normalized_count .values (), 0.0 )
131
+ interactions_count = Counter (interactions )
132
+ total = sum (interactions_count .values (), 0.0 )
109
133
# By starting the sum with 0.0 we make sure total is a floating point value,
110
- # avoiding the Python 2 floor division behaviour of / with integer operands (Stack Overflow)
134
+ # avoiding the Python 2 floor division behaviour of / with integer operands
135
+ # (Stack Overflow)
111
136
112
- for key in normalized_count :
113
- normalized_count [ key ] /= total
137
+ normalized_count = Counter ({ key : value / total for key , value in
138
+ interactions_count . items ()})
114
139
return normalized_count
115
140
116
141
0 commit comments