22Functions to calculate results from interactions. Interactions are lists of the
33form:
44
5- [('C', 'D' ), ('D', 'C' ),...]
5+ [(C, D ), (D, C ),...]
66
77This is used by both the Match class and the ResultSet class which analyse
88interactions.
@@ -145,7 +145,7 @@ def compute_state_to_action_distribution(interactions):
145145 Implying that from a state of (C, D) (the first player having played C and
146146 the second playing D) the player in question then played C.
147147
148- The following counter object, implies that the player in question was in
148+ The following counter object implies that the player in question was in
149149 state (C, D) for a total of 12 times, subsequently cooperating 4 times and
150150 defecting 8 times.
151151
@@ -167,8 +167,8 @@ def compute_state_to_action_distribution(interactions):
167167 if not interactions :
168168 return None
169169
170- distributions = [Counter ([(state , outcome [j ]) for state , outcome in zip ( interactions ,
171- interactions [1 :])])
170+ distributions = [Counter ([(state , outcome [j ])
171+ for state , outcome in zip ( interactions , interactions [1 :])])
172172 for j in range (2 )]
173173 return distributions
174174
@@ -180,13 +180,12 @@ def compute_normalised_state_to_action_distribution(interactions):
180180
181181 ((C, D), C)
182182
183- Implying that from a state of (C, D) (the first player having played C and
183+ implying that from a state of (C, D) (the first player having played C and
184184 the second playing D) the player in question then played C.
185185
186186 The following counter object, implies that the player in question was only
187- ever in
188- state (C, D), subsequently cooperating 1/3 of the time and
189- defecting 2/3 times.
187+ ever in state (C, D), subsequently cooperating 1/3 of the time and defecting
188+ 2/3 times.
190189
191190 Counter({((C, D), C): 0.333333, ((C, D), D): 0.66666667})
192191
@@ -197,11 +196,11 @@ def compute_normalised_state_to_action_distribution(interactions):
197196 this file.
198197
199198 Returns
200- ----------
199+ -------
201200 normalised_state_to_C_distributions : List of Counter Object
202201 List of Counter objects where the keys are the states and actions and
203- the values the normalized counts.. The
204- first/second Counter corresponds to the first/second player.
202+ the values the normalized counts. The first/second Counter corresponds
203+ to the first/second player.
205204 """
206205 if not interactions :
207206 return None
@@ -210,22 +209,22 @@ def compute_normalised_state_to_action_distribution(interactions):
210209 normalized_distribution = []
211210 for player in range (2 ):
212211 counter = {}
213- for state in [('C' , 'C' ), ('C' , 'D' ), ('D' , 'C' ), ('D' , 'D' )]:
214- C_count = distribution [player ].get ((state , 'C' ), 0 )
215- D_count = distribution [player ].get ((state , 'D' ), 0 )
212+ for state in [(C , C ), (C , D ), (D , C ), (D , D )]:
213+ C_count = distribution [player ].get ((state , C ), 0 )
214+ D_count = distribution [player ].get ((state , D ), 0 )
216215 total = C_count + D_count
217216 if total > 0 :
218217 if C_count > 0 :
219- counter [(state , 'C' )] = C_count / (C_count + D_count )
218+ counter [(state , C )] = C_count / (C_count + D_count )
220219 if D_count > 0 :
221- counter [(state , 'D' )] = D_count / (C_count + D_count )
220+ counter [(state , D )] = D_count / (C_count + D_count )
222221 normalized_distribution .append (Counter (counter ))
223222 return normalized_distribution
224223
225224
226225def sparkline (actions , c_symbol = '█' , d_symbol = ' ' ):
227226 return '' .join ([
228- c_symbol if play == 'C' else d_symbol for play in actions ])
227+ c_symbol if play == C else d_symbol for play in actions ])
229228
230229
231230def compute_sparklines (interactions , c_symbol = '█' , d_symbol = ' ' ):
0 commit comments