@@ -118,9 +118,12 @@ def _reshape_out(
118118 alternative = 0 ,
119119 )
120120
121- self .wins = self ._reshape_two_dim_list (sum_per_player_repetition_df ["Win" ])
122- self .scores = self ._reshape_two_dim_list (sum_per_player_repetition_df ["Score" ])
123- self .normalised_scores = self ._reshape_two_dim_list (normalised_scores_series )
121+ self .wins = self ._reshape_two_dim_list (
122+ sum_per_player_repetition_df ["Win" ])
123+ self .scores = self ._reshape_two_dim_list (
124+ sum_per_player_repetition_df ["Score" ])
125+ self .normalised_scores = self ._reshape_two_dim_list (
126+ normalised_scores_series )
124127
125128 self .cooperation = self ._build_cooperation (
126129 sum_per_player_opponent_df ["Cooperation count" ]
@@ -167,7 +170,8 @@ def _reshape_out(
167170 self .ranked_names = self ._build_ranked_names ()
168171
169172 self .payoff_matrix = self ._build_summary_matrix (self .payoffs )
170- self .payoff_stddevs = self ._build_summary_matrix (self .payoffs , func = np .std )
173+ self .payoff_stddevs = self ._build_summary_matrix (self .payoffs ,
174+ func = np .std )
171175
172176 self .payoff_diffs_means = self ._build_payoff_diffs_means ()
173177 self .cooperating_rating = self ._build_cooperating_rating ()
@@ -267,7 +271,9 @@ def _build_good_partner_matrix(self, good_partner_series):
267271 # interactions.
268272 row .append (0 )
269273 else :
270- row .append (good_partner_dict .get ((player_index , opponent_index ), 0 ))
274+ row .append (
275+ good_partner_dict .get ((player_index , opponent_index ),
276+ 0 ))
271277 good_partner_matrix .append (row )
272278 return good_partner_matrix
273279
@@ -335,13 +341,15 @@ def _build_normalised_state_distribution(self):
335341 for counter in player :
336342 total = sum (counter .values ())
337343 counters .append (
338- Counter ({key : value / total for key , value in counter .items ()})
344+ Counter (
345+ {key : value / total for key , value in counter .items ()})
339346 )
340347 normalised_state_distribution .append (counters )
341348 return normalised_state_distribution
342349
343350 @update_progress_bar
344- def _build_state_to_action_distribution (self , state_to_action_distribution_series ):
351+ def _build_state_to_action_distribution (self ,
352+ state_to_action_distribution_series ):
345353 state_to_action_key_map = {
346354 "CC to C count" : ((C , C ), C ),
347355 "CC to D count" : ((C , C ), D ),
@@ -397,7 +405,8 @@ def _build_normalised_state_to_action_distribution(self):
397405 return normalised_state_to_action_distribution
398406
399407 @update_progress_bar
400- def _build_initial_cooperation_count (self , initial_cooperation_count_series ):
408+ def _build_initial_cooperation_count (self ,
409+ initial_cooperation_count_series ):
401410 initial_cooperation_count_dict = initial_cooperation_count_series .to_dict ()
402411 initial_cooperation_count = [
403412 initial_cooperation_count_dict .get (player_index , 0 )
@@ -412,7 +421,7 @@ def _build_normalised_cooperation(self):
412421 normalised_cooperation = [
413422 list (np .nan_to_num (row ))
414423 for row in np .array (self .cooperation )
415- / sum (map (np .array , self .match_lengths ))
424+ / sum (map (np .array , self .match_lengths ))
416425 ]
417426 return normalised_cooperation
418427
@@ -427,7 +436,8 @@ def _build_initial_cooperation_rate(self, interactions_series):
427436 with warnings .catch_warnings ():
428437 warnings .simplefilter ("ignore" )
429438 initial_cooperation_rate = list (
430- np .nan_to_num (np .array (self .initial_cooperation_count ) / interactions_array )
439+ np .nan_to_num (np .array (
440+ self .initial_cooperation_count ) / interactions_array )
431441 )
432442 return initial_cooperation_rate
433443
@@ -452,7 +462,8 @@ def _build_eigenmoses_rating(self):
452462 The eigenmoses rating as defined in:
453463 http://www.scottaaronson.com/morality.pdf
454464 """
455- eigenvector , eigenvalue = eigen .principal_eigenvector (self .vengeful_cooperation )
465+ eigenvector , eigenvalue = eigen .principal_eigenvector (
466+ self .vengeful_cooperation )
456467
457468 return eigenvector .tolist ()
458469
@@ -576,7 +587,8 @@ def _build_tasks(self, df):
576587 ]
577588 sum_per_player_opponent_task = df .groupby (groups )[columns ].sum ()
578589
579- ignore_self_interactions_task = df ["Player index" ] != df ["Opponent index" ]
590+ ignore_self_interactions_task = df ["Player index" ] != df [
591+ "Opponent index" ]
580592 adf = df [ignore_self_interactions_task ]
581593
582594 groups = ["Player index" , "Repetition" ]
@@ -590,7 +602,8 @@ def _build_tasks(self, df):
590602 groups = ["Player index" ]
591603 column = "Initial cooperation"
592604 initial_cooperation_count_task = adf .groupby (groups )[column ].sum ()
593- interactions_count_task = adf .groupby ("Player index" )["Player index" ].count ()
605+ interactions_count_task = adf .groupby ("Player index" )[
606+ "Player index" ].count ()
594607
595608 return (
596609 mean_per_reps_player_opponent_task ,
@@ -610,7 +623,8 @@ def __eq__(self, other):
610623 other : axelrod.ResultSet
611624 Another results set against which to check equality
612625 """
613- def list_equal (v1 : List [float ], v2 : List [float ]) -> bool :
626+
627+ def list_equal_with_nans (v1 : List [float ], v2 : List [float ]) -> bool :
614628 """Matches lists, accounting for NaNs."""
615629 if len (v1 ) != len (v2 ):
616630 return False
@@ -640,8 +654,10 @@ def list_equal(v1: List[float], v2: List[float]) -> bool:
640654 self .cooperating_rating == other .cooperating_rating ,
641655 self .good_partner_matrix == other .good_partner_matrix ,
642656 self .good_partner_rating == other .good_partner_rating ,
643- list_equal (self .eigenmoses_rating , other .eigenmoses_rating ),
644- list_equal (self .eigenjesus_rating , other .eigenjesus_rating ),
657+ list_equal_with_nans (self .eigenmoses_rating ,
658+ other .eigenmoses_rating ),
659+ list_equal_with_nans (self .eigenjesus_rating ,
660+ other .eigenjesus_rating ),
645661 ]
646662 )
647663
@@ -711,7 +727,8 @@ def summarise(self):
711727 rates = []
712728 for state in states :
713729 counts = [
714- counter [(state , C )] for counter in player if counter [(state , C )] > 0
730+ counter [(state , C )] for counter in player if
731+ counter [(state , C )] > 0
715732 ]
716733
717734 if len (counts ) > 0 :
@@ -734,7 +751,8 @@ def summarise(self):
734751
735752 summary_data = []
736753 for rank , i in enumerate (self .ranking ):
737- data = list (summary_measures [i ]) + state_prob [i ] + state_to_C_prob [i ]
754+ data = list (summary_measures [i ]) + state_prob [i ] + state_to_C_prob [
755+ i ]
738756 summary_data .append (self .player (rank , * data ))
739757
740758 return summary_data
0 commit comments