Skip to content

Commit 562be02

Browse files
committed
Revert "Run black on all files"
This reverts commit 6e31d2a.
1 parent 6e31d2a commit 562be02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+676
-762
lines changed

axelrod/compute_finite_state_machine_memory.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def __hash__(self):
4747

4848
def __eq__(self, other_memit) -> bool:
4949
"""In action and out actions are the same."""
50-
return self.in_act == other_memit.in_act and self.out_act == other_memit.out_act
50+
return (
51+
self.in_act == other_memit.in_act
52+
and self.out_act == other_memit.out_act
53+
)
5154

5255
def __lt__(self, other_memit) -> bool:
5356
return repr(self) < repr(other_memit)
@@ -107,10 +110,9 @@ def get_accessible_transitions(
107110
accessible_transitions = dict()
108111
for trans in transition_iterator(transitions):
109112
if trans.state in accessible_states:
110-
accessible_transitions[(trans.state, trans.last_opponent_action)] = (
111-
trans.next_state,
112-
trans.next_action,
113-
)
113+
accessible_transitions[
114+
(trans.state, trans.last_opponent_action)
115+
] = (trans.next_state, trans.next_action)
114116

115117
return accessible_transitions
116118

@@ -177,7 +179,9 @@ def get_memory_from_transitions(
177179
transitions = get_accessible_transitions(transitions, initial_state)
178180

179181
# Get the incoming actions for each state.
180-
incoming_action_by_state = defaultdict(set) # type: DefaultDict[int, Set[Action]]
182+
incoming_action_by_state = defaultdict(
183+
set
184+
) # type: DefaultDict[int, Set[Action]]
181185
for trans in transition_iterator(transitions):
182186
incoming_action_by_state[trans.next_state].add(trans.next_action)
183187

@@ -189,17 +193,23 @@ def get_memory_from_transitions(
189193
# That is to say that the opponent could do anything
190194
for out_action in all_actions:
191195
# More recent in action history
192-
starting_node = Memit(trans.next_action, trans.next_state, out_action)
196+
starting_node = Memit(
197+
trans.next_action, trans.next_state, out_action
198+
)
193199
# All incoming paths to current state
194200
for in_action in incoming_action_by_state[trans.state]:
195201
# Less recent in action history
196-
ending_node = Memit(in_action, trans.state, trans.last_opponent_action)
202+
ending_node = Memit(
203+
in_action, trans.state, trans.last_opponent_action
204+
)
197205
memit_edges[starting_node].add(ending_node)
198206

199207
all_memits = list(memit_edges.keys())
200208

201209
pair_nodes = set()
202-
pair_edges = defaultdict(set) # type: DefaultDict[MemitPair, Set[MemitPair]]
210+
pair_edges = defaultdict(
211+
set
212+
) # type: DefaultDict[MemitPair, Set[MemitPair]]
203213
# Loop through all pairs of memits.
204214
for x, y in [(x, y) for x in all_memits for y in all_memits]:
205215
if x == y and x.state == y.state:
@@ -226,7 +236,9 @@ def get_memory_from_transitions(
226236
next_action_by_memit = dict()
227237
for trans in transition_iterator(transitions):
228238
for in_action in incoming_action_by_state[trans.state]:
229-
memit_key = Memit(in_action, trans.state, trans.last_opponent_action)
239+
memit_key = Memit(
240+
in_action, trans.state, trans.last_opponent_action
241+
)
230242
next_action_by_memit[memit_key] = trans.next_action
231243

232244
# Calculate the longest path.
@@ -251,3 +263,4 @@ def get_memory_from_transitions(
251263
if len(next_action_set) == 1:
252264
return 0
253265
return 1
266+

axelrod/evolvable_player.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class InsufficientParametersError(Exception):
99
"""Error indicating that insufficient parameters were specified to initialize an Evolvable Player."""
10-
1110
def __init__(self, *args):
1211
super().__init__(*args)
1312

@@ -39,7 +38,7 @@ def create_new(self, **kwargs):
3938
def serialize_parameters(self):
4039
"""Serialize parameters."""
4140
pickled = dumps(self.init_kwargs) # bytes
42-
s = base64.b64encode(pickled).decode("utf8") # string
41+
s = base64.b64encode(pickled).decode('utf8') # string
4342
return s
4443

4544
@classmethod

axelrod/graph.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def attached_complete_graphs(length, loops=True, directed=False):
155155
for cluster in range(2):
156156
for i in range(length):
157157
for j in range(i + 1, length):
158-
edges.append(("{}:{}".format(cluster, i), "{}:{}".format(cluster, j)))
158+
edges.append(("{}:{}".format(cluster, i),
159+
"{}:{}".format(cluster, j)))
159160
# Attach at one node
160161
edges.append(("0:0", "1:0"))
161162
graph = Graph(directed=directed, edges=edges)

axelrod/moran.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(
5757
reproduction_graph: Graph = None,
5858
fitness_transformation: Callable = None,
5959
mutation_method="transition",
60-
stop_on_fixation=True,
60+
stop_on_fixation=True
6161
) -> None:
6262
"""
6363
An agent based Moran process class. In each round, each player plays a
@@ -193,9 +193,7 @@ def mutate(self, index: int) -> Player:
193193

194194
if self.mutation_method == "atomic":
195195
if not issubclass(self.players[index].__class__, EvolvablePlayer):
196-
raise TypeError(
197-
"Player is not evolvable. Use a subclass of EvolvablePlayer."
198-
)
196+
raise TypeError("Player is not evolvable. Use a subclass of EvolvablePlayer.")
199197
return self.players[index].mutate()
200198

201199
# Assuming mutation_method == "transition"

axelrod/strategies/adaptor.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ class AbstractAdaptor(Player):
3939
"manipulates_state": False,
4040
}
4141

42-
def __init__(
43-
self, delta: Dict[Tuple[Action, Action], float], perr: float = 0.01
44-
) -> None:
42+
def __init__(self, delta: Dict[Tuple[Action, Action], float],
43+
perr: float = 0.01) -> None:
4544
super().__init__()
4645
self.perr = perr
4746
self.delta = delta
48-
self.s = 0.0
47+
self.s = 0.
4948

5049
def strategy(self, opponent: Player) -> Action:
5150
if self.history:
@@ -55,8 +54,7 @@ def strategy(self, opponent: Player) -> Action:
5554

5655
# Compute probability of Cooperation
5756
p = self.perr + (1.0 - 2 * self.perr) * (
58-
heaviside(self.s + 1, 1) - heaviside(self.s - 1, 1)
59-
)
57+
heaviside(self.s + 1, 1) - heaviside(self.s - 1, 1))
6058
# Draw action
6159
action = random_choice(p)
6260
return action
@@ -76,10 +74,10 @@ class AdaptorBrief(AbstractAdaptor):
7674

7775
def __init__(self) -> None:
7876
delta = {
79-
(C, C): 0.0, # R
77+
(C, C): 0., # R
8078
(C, D): -1.001505, # S
81-
(D, C): 0.992107, # T
82-
(D, D): -0.638734, # P
79+
(D, C): 0.992107, # T
80+
(D, D): -0.638734 # P
8381
}
8482
super().__init__(delta=delta)
8583

@@ -98,9 +96,9 @@ class AdaptorLong(AbstractAdaptor):
9896

9997
def __init__(self) -> None:
10098
delta = {
101-
(C, C): 0.0, # R
99+
(C, C): 0., # R
102100
(C, D): 1.888159, # S
103101
(D, C): 1.858883, # T
104-
(D, D): -0.995703, # P
102+
(D, D): -0.995703 # P
105103
}
106104
super().__init__(delta=delta)

axelrod/strategies/ann.py

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import numpy.random as random
44
from axelrod.action import Action
55
from axelrod.load_data_ import load_weights
6-
from axelrod.evolvable_player import (
7-
EvolvablePlayer,
8-
InsufficientParametersError,
9-
crossover_lists,
10-
)
6+
from axelrod.evolvable_player import EvolvablePlayer, InsufficientParametersError, crossover_lists
117
from axelrod.player import Player
128

139

@@ -195,7 +191,8 @@ class ANN(Player):
195191
}
196192

197193
def __init__(
198-
self, num_features: int, num_hidden: int, weights: List[float] = None
194+
self, num_features: int, num_hidden: int,
195+
weights: List[float] = None
199196
) -> None:
200197
super().__init__()
201198
self.num_features = num_features
@@ -225,57 +222,43 @@ def strategy(self, opponent: Player) -> Action:
225222

226223
class EvolvableANN(ANN, EvolvablePlayer):
227224
"""Evolvable version of ANN."""
228-
229225
name = "EvolvableANN"
230226

231227
def __init__(
232-
self,
233-
num_features: int,
234-
num_hidden: int,
228+
self, num_features: int, num_hidden: int,
235229
weights: List[float] = None,
236230
mutation_probability: float = None,
237231
mutation_distance: int = 5,
238232
) -> None:
239-
(
240-
num_features,
241-
num_hidden,
242-
weights,
243-
mutation_probability,
244-
) = self._normalize_parameters(
245-
num_features, num_hidden, weights, mutation_probability
246-
)
247-
ANN.__init__(
248-
self, num_features=num_features, num_hidden=num_hidden, weights=weights
249-
)
233+
num_features, num_hidden, weights, mutation_probability = self._normalize_parameters(
234+
num_features, num_hidden, weights, mutation_probability)
235+
ANN.__init__(self,
236+
num_features=num_features,
237+
num_hidden=num_hidden,
238+
weights=weights)
250239
EvolvablePlayer.__init__(self)
251240
self.mutation_probability = mutation_probability
252241
self.mutation_distance = mutation_distance
253242
self.overwrite_init_kwargs(
254243
num_features=num_features,
255244
num_hidden=num_hidden,
256245
weights=weights,
257-
mutation_probability=mutation_probability,
258-
)
246+
mutation_probability=mutation_probability)
259247

260248
@classmethod
261-
def _normalize_parameters(
262-
cls, num_features=None, num_hidden=None, weights=None, mutation_probability=None
263-
):
249+
def _normalize_parameters(cls, num_features=None, num_hidden=None, weights=None, mutation_probability=None):
264250
if not (num_features and num_hidden):
265-
raise InsufficientParametersError(
266-
"Insufficient Parameters to instantiate EvolvableANN"
267-
)
251+
raise InsufficientParametersError("Insufficient Parameters to instantiate EvolvableANN")
268252
size = num_weights(num_features, num_hidden)
269253
if not weights:
270254
weights = [random.uniform(-1, 1) for _ in range(size)]
271255
if mutation_probability is None:
272-
mutation_probability = 10.0 / size
256+
mutation_probability = 10. / size
273257
return num_features, num_hidden, weights, mutation_probability
274258

275259
@staticmethod
276-
def mutate_weights(
277-
weights, num_features, num_hidden, mutation_probability, mutation_distance
278-
):
260+
def mutate_weights(weights, num_features, num_hidden, mutation_probability,
261+
mutation_distance):
279262
size = num_weights(num_features, num_hidden)
280263
randoms = random.random(size)
281264
for i, r in enumerate(randoms):
@@ -286,12 +269,8 @@ def mutate_weights(
286269

287270
def mutate(self):
288271
weights = self.mutate_weights(
289-
self.weights,
290-
self.num_features,
291-
self.num_hidden,
292-
self.mutation_probability,
293-
self.mutation_distance,
294-
)
272+
self.weights, self.num_features, self.num_hidden,
273+
self.mutation_probability, self.mutation_distance)
295274
return self.create_new(weights=weights)
296275

297276
def crossover(self, other):
@@ -319,8 +298,9 @@ class EvolvedANN(ANN):
319298
def __init__(self) -> None:
320299
num_features, num_hidden, weights = nn_weights["Evolved ANN"]
321300
super().__init__(
322-
num_features=num_features, num_hidden=num_hidden, weights=weights
323-
)
301+
num_features=num_features,
302+
num_hidden=num_hidden,
303+
weights=weights)
324304

325305

326306
class EvolvedANN5(ANN):
@@ -341,8 +321,9 @@ class EvolvedANN5(ANN):
341321
def __init__(self) -> None:
342322
num_features, num_hidden, weights = nn_weights["Evolved ANN 5"]
343323
super().__init__(
344-
num_features=num_features, num_hidden=num_hidden, weights=weights
345-
)
324+
num_features=num_features,
325+
num_hidden=num_hidden,
326+
weights=weights)
346327

347328

348329
class EvolvedANNNoise05(ANN):
@@ -363,5 +344,7 @@ class EvolvedANNNoise05(ANN):
363344
def __init__(self) -> None:
364345
num_features, num_hidden, weights = nn_weights["Evolved ANN 5 Noise 05"]
365346
super().__init__(
366-
num_features=num_features, num_hidden=num_hidden, weights=weights
367-
)
347+
num_features=num_features,
348+
num_hidden=num_hidden,
349+
weights=weights)
350+

0 commit comments

Comments
 (0)