@@ -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,9 +93,7 @@ def __init__(
9393 if m in ["atomic" , "transition" ]:
9494 self .mutation_method = m
9595 else :
96- raise ValueError (
97- "Invalid mutation method {}" .format (mutation_method )
98- )
96+ raise ValueError ("Invalid mutation method {}" .format (mutation_method ))
9997 assert (mutation_rate >= 0 ) and (mutation_rate <= 1 )
10098 assert (noise >= 0 ) and (noise <= 1 )
10199 mode = mode .lower ()
@@ -129,9 +127,7 @@ def __init__(
129127 d [str (p )] = p
130128 mutation_targets = dict ()
131129 for key in sorted (keys ):
132- mutation_targets [key ] = [
133- v for (k , v ) in sorted (d .items ()) if k != key
134- ]
130+ mutation_targets [key ] = [v for (k , v ) in sorted (d .items ()) if k != key ]
135131 self .mutation_targets = mutation_targets
136132
137133 if interaction_graph is None :
@@ -150,18 +146,14 @@ def __init__(
150146 self .fitness_transformation = fitness_transformation
151147 # Map players to graph vertices
152148 self .locations = sorted (interaction_graph .vertices )
153- self .index = dict (
154- zip (sorted (interaction_graph .vertices ), range (len (players )))
155- )
149+ self .index = dict (zip (sorted (interaction_graph .vertices ), range (len (players ))))
156150 self .fixated = self .fixation_check ()
157151
158152 def set_players (self ) -> None :
159153 """Copy the initial players into the first population, setting seeds as needed."""
160154 self .players = []
161155 for player in self .initial_players :
162- if (self .mutation_method == "atomic" ) and issubclass (
163- player .__class__ , EvolvablePlayer
164- ):
156+ if (self .mutation_method == "atomic" ) and issubclass (player .__class__ , EvolvablePlayer ):
165157 # For reproducibility, we generate random seeds for evolvable players.
166158 seed = next (self ._bulk_random )
167159 new_player = player .create_new (seed = seed )
@@ -171,9 +163,8 @@ def set_players(self) -> None:
171163 self .players .append (player )
172164 self .populations = [self .population_distribution ()]
173165
174- def fitness_proportionate_selection (
175- self , scores : List , fitness_transformation : Callable = None
176- ) -> int :
166+ def fitness_proportionate_selection (self ,
167+ scores : List , fitness_transformation : Callable = None ) -> int :
177168 """Randomly selects an individual proportionally to score.
178169
179170 Parameters
@@ -209,9 +200,7 @@ def mutate(self, index: int) -> Player:
209200
210201 if self .mutation_method == "atomic" :
211202 if not issubclass (self .players [index ].__class__ , EvolvablePlayer ):
212- raise TypeError (
213- "Player is not evolvable. Use a subclass of EvolvablePlayer."
214- )
203+ raise TypeError ("Player is not evolvable. Use a subclass of EvolvablePlayer." )
215204 return self .players [index ].mutate ()
216205
217206 # Assuming mutation_method == "transition"
@@ -248,9 +237,7 @@ def death(self, index: int = None) -> int:
248237 # Select locally
249238 # index is not None in this case
250239 vertex = self ._random .choice (
251- sorted (
252- self .reproduction_graph .out_vertices (self .locations [index ])
253- )
240+ sorted (self .reproduction_graph .out_vertices (self .locations [index ]))
254241 )
255242 i = self .index [vertex ]
256243 return i
@@ -383,7 +370,7 @@ def score_all(self) -> List:
383370 noise = self .noise ,
384371 game = self .game ,
385372 deterministic_cache = self .deterministic_cache ,
386- seed = next (self ._bulk_random ),
373+ seed = next (self ._bulk_random )
387374 )
388375 match .play ()
389376 match_scores = match .final_score_per_turn ()
@@ -497,11 +484,8 @@ class ApproximateMoranProcess(MoranProcess):
497484 """
498485
499486 def __init__ (
500- self ,
501- players : List [Player ],
502- cached_outcomes : dict ,
503- mutation_rate : float = 0 ,
504- seed : Optional [int ] = None ,
487+ self , players : List [Player ], cached_outcomes : dict , mutation_rate : float = 0 ,
488+ seed : Optional [int ] = None
505489 ) -> None :
506490 """
507491 Parameters
@@ -519,7 +503,7 @@ def __init__(
519503 noise = 0 ,
520504 deterministic_cache = None ,
521505 mutation_rate = mutation_rate ,
522- seed = seed ,
506+ seed = seed
523507 )
524508 self .cached_outcomes = cached_outcomes
525509
@@ -545,9 +529,7 @@ def score_all(self) -> List:
545529 scores = [0 ] * N
546530 for i in range (N ):
547531 for j in range (i + 1 , N ):
548- player_names = tuple (
549- [str (self .players [i ]), str (self .players [j ])]
550- )
532+ player_names = tuple ([str (self .players [i ]), str (self .players [j ])])
551533 cached_score = self ._get_scores_from_cache (player_names )
552534 scores [i ] += cached_score [0 ]
553535 scores [j ] += cached_score [1 ]
0 commit comments