@@ -28,7 +28,7 @@ def __init__(
2828 fitness_transformation : Callable = None ,
2929 mutation_method = "transition" ,
3030 stop_on_fixation = True ,
31- seed = None
31+ seed = None ,
3232 ) -> None :
3333 """
3434 An agent based Moran process class. In each round, each player plays a
@@ -93,7 +93,9 @@ def __init__(
9393 if m in ["atomic" , "transition" ]:
9494 self .mutation_method = m
9595 else :
96- raise ValueError ("Invalid mutation method {}" .format (mutation_method ))
96+ raise ValueError (
97+ "Invalid mutation method {}" .format (mutation_method )
98+ )
9799 assert (mutation_rate >= 0 ) and (mutation_rate <= 1 )
98100 assert (noise >= 0 ) and (noise <= 1 )
99101 mode = mode .lower ()
@@ -127,7 +129,9 @@ def __init__(
127129 d [str (p )] = p
128130 mutation_targets = dict ()
129131 for key in sorted (keys ):
130- mutation_targets [key ] = [v for (k , v ) in sorted (d .items ()) if k != key ]
132+ mutation_targets [key ] = [
133+ v for (k , v ) in sorted (d .items ()) if k != key
134+ ]
131135 self .mutation_targets = mutation_targets
132136
133137 if interaction_graph is None :
@@ -146,14 +150,18 @@ def __init__(
146150 self .fitness_transformation = fitness_transformation
147151 # Map players to graph vertices
148152 self .locations = sorted (interaction_graph .vertices )
149- self .index = dict (zip (sorted (interaction_graph .vertices ), range (len (players ))))
153+ self .index = dict (
154+ zip (sorted (interaction_graph .vertices ), range (len (players )))
155+ )
150156 self .fixated = self .fixation_check ()
151157
152158 def set_players (self ) -> None :
153159 """Copy the initial players into the first population, setting seeds as needed."""
154160 self .players = []
155161 for player in self .initial_players :
156- if (self .mutation_method == "atomic" ) and issubclass (player .__class__ , EvolvablePlayer ):
162+ if (self .mutation_method == "atomic" ) and issubclass (
163+ player .__class__ , EvolvablePlayer
164+ ):
157165 # For reproducibility, we generate random seeds for evolvable players.
158166 seed = next (self ._bulk_random )
159167 new_player = player .create_new (seed = seed )
@@ -163,8 +171,9 @@ def set_players(self) -> None:
163171 self .players .append (player )
164172 self .populations = [self .population_distribution ()]
165173
166- def fitness_proportionate_selection (self ,
167- scores : List , fitness_transformation : Callable = None ) -> int :
174+ def fitness_proportionate_selection (
175+ self , scores : List , fitness_transformation : Callable = None
176+ ) -> int :
168177 """Randomly selects an individual proportionally to score.
169178
170179 Parameters
@@ -200,7 +209,9 @@ def mutate(self, index: int) -> Player:
200209
201210 if self .mutation_method == "atomic" :
202211 if not issubclass (self .players [index ].__class__ , EvolvablePlayer ):
203- raise TypeError ("Player is not evolvable. Use a subclass of EvolvablePlayer." )
212+ raise TypeError (
213+ "Player is not evolvable. Use a subclass of EvolvablePlayer."
214+ )
204215 return self .players [index ].mutate ()
205216
206217 # Assuming mutation_method == "transition"
@@ -237,7 +248,9 @@ def death(self, index: int = None) -> int:
237248 # Select locally
238249 # index is not None in this case
239250 vertex = self ._random .choice (
240- sorted (self .reproduction_graph .out_vertices (self .locations [index ]))
251+ sorted (
252+ self .reproduction_graph .out_vertices (self .locations [index ])
253+ )
241254 )
242255 i = self .index [vertex ]
243256 return i
@@ -370,7 +383,7 @@ def score_all(self) -> List:
370383 noise = self .noise ,
371384 game = self .game ,
372385 deterministic_cache = self .deterministic_cache ,
373- seed = next (self ._bulk_random )
386+ seed = next (self ._bulk_random ),
374387 )
375388 match .play ()
376389 match_scores = match .final_score_per_turn ()
@@ -484,8 +497,11 @@ class ApproximateMoranProcess(MoranProcess):
484497 """
485498
486499 def __init__ (
487- self , players : List [Player ], cached_outcomes : dict , mutation_rate : float = 0 ,
488- seed : Optional [int ] = None
500+ self ,
501+ players : List [Player ],
502+ cached_outcomes : dict ,
503+ mutation_rate : float = 0 ,
504+ seed : Optional [int ] = None ,
489505 ) -> None :
490506 """
491507 Parameters
@@ -503,7 +519,7 @@ def __init__(
503519 noise = 0 ,
504520 deterministic_cache = None ,
505521 mutation_rate = mutation_rate ,
506- seed = seed
522+ seed = seed ,
507523 )
508524 self .cached_outcomes = cached_outcomes
509525
@@ -529,7 +545,9 @@ def score_all(self) -> List:
529545 scores = [0 ] * N
530546 for i in range (N ):
531547 for j in range (i + 1 , N ):
532- player_names = tuple ([str (self .players [i ]), str (self .players [j ])])
548+ player_names = tuple (
549+ [str (self .players [i ]), str (self .players [j ])]
550+ )
533551 cached_score = self ._get_scores_from_cache (player_names )
534552 scores [i ] += cached_score [0 ]
535553 scores [j ] += cached_score [1 ]
0 commit comments