@@ -42,7 +42,7 @@ def _create_points(step: float, progress_bar: bool = True) -> List[Point]:
42
42
num = int ((1 / step ) // 1 ) + 1
43
43
44
44
if progress_bar :
45
- p_bar = tqdm .tqdm (total = num ** 2 , desc = "Generating points" )
45
+ p_bar = tqdm .tqdm (total = num ** 2 , desc = "Generating points" )
46
46
47
47
points = []
48
48
for x in np .linspace (0 , 1 , num ):
@@ -88,8 +88,8 @@ def _create_jossann(point: Point, probe: Any) -> Player:
88
88
89
89
if x + y >= 1 :
90
90
joss_ann = DualTransformer ()(
91
- JossAnnTransformer ((1 - x , 1 - y ))(
92
- probe_class ) )(** init_kwargs )
91
+ JossAnnTransformer ((1 - x , 1 - y ))(probe_class )
92
+ )(** init_kwargs )
93
93
else :
94
94
joss_ann = JossAnnTransformer ((x , y ))(probe_class )(** init_kwargs )
95
95
return joss_ann
@@ -177,7 +177,10 @@ def _generate_data(interactions: dict, points: list, edges: list) -> dict:
177
177
"""
178
178
edge_scores = [
179
179
np .mean (
180
- [compute_final_score_per_turn (scores )[0 ] for scores in interactions [edge ]]
180
+ [
181
+ compute_final_score_per_turn (scores )[0 ]
182
+ for scores in interactions [edge ]
183
+ ]
181
184
)
182
185
for edge in edges
183
186
]
@@ -215,7 +218,9 @@ def _reshape_data(data: dict, points: list, size: int) -> np.ndarray:
215
218
216
219
class AshlockFingerprint (object ):
217
220
def __init__ (
218
- self , strategy : Union [type , Player ], probe : Union [type , Player ] = axl .TitForTat
221
+ self ,
222
+ strategy : Union [type , Player ],
223
+ probe : Union [type , Player ] = axl .TitForTat ,
219
224
) -> None :
220
225
"""
221
226
Parameters
@@ -277,7 +282,7 @@ def fingerprint(
277
282
processes : int = None ,
278
283
filename : str = None ,
279
284
progress_bar : bool = True ,
280
- seed : int = None
285
+ seed : int = None ,
281
286
) -> dict :
282
287
"""Build and play the spatial tournament.
283
288
@@ -323,8 +328,11 @@ def fingerprint(
323
328
324
329
self .step = step
325
330
self .spatial_tournament = axl .Tournament (
326
- tourn_players , turns = turns , repetitions = repetitions , edges = edges ,
327
- seed = seed
331
+ tourn_players ,
332
+ turns = turns ,
333
+ repetitions = repetitions ,
334
+ edges = edges ,
335
+ seed = seed ,
328
336
)
329
337
self .spatial_tournament .play (
330
338
build_results = False ,
@@ -432,7 +440,7 @@ def fingerprint(
432
440
processes : int = None ,
433
441
filename : str = None ,
434
442
progress_bar : bool = True ,
435
- seed : int = None
443
+ seed : int = None ,
436
444
) -> np .array :
437
445
"""Creates a spatial tournament to run the necessary matches to obtain
438
446
fingerprint data.
@@ -479,7 +487,7 @@ def fingerprint(
479
487
turns = turns ,
480
488
noise = noise ,
481
489
repetitions = repetitions ,
482
- seed = seed
490
+ seed = seed ,
483
491
)
484
492
tournament .play (
485
493
filename = filename ,
@@ -516,7 +524,9 @@ def analyse_cooperation_ratio(filename):
516
524
opponent in each turn. The ith row corresponds to the ith opponent
517
525
and the jth column the jth turn.
518
526
"""
519
- did_c = np .vectorize (lambda actions : [int (action == "C" ) for action in actions ])
527
+ did_c = np .vectorize (
528
+ lambda actions : [int (action == "C" ) for action in actions ]
529
+ )
520
530
521
531
cooperation_rates = {}
522
532
df = dd .read_csv (filename )
@@ -525,7 +535,10 @@ def analyse_cooperation_ratio(filename):
525
535
df = df [df ["Player index" ] == 0 ][["Opponent index" , "Actions" ]]
526
536
527
537
for _ , row in df .iterrows ():
528
- opponent_index , player_history = row ["Opponent index" ], row ["Actions" ]
538
+ opponent_index , player_history = (
539
+ row ["Opponent index" ],
540
+ row ["Actions" ],
541
+ )
529
542
if opponent_index in cooperation_rates :
530
543
cooperation_rates [opponent_index ].append (did_c (player_history ))
531
544
else :
@@ -590,7 +603,8 @@ def plot(
590
603
591
604
if display_names :
592
605
plt .yticks (
593
- range (len (self .opponents )), [str (player ) for player in self .opponents ]
606
+ range (len (self .opponents )),
607
+ [str (player ) for player in self .opponents ],
594
608
)
595
609
else :
596
610
plt .yticks ([0 , len (self .opponents ) - 1 ], [0 , 1 ])
0 commit comments