Skip to content

Commit f68cb0d

Browse files
committed
Remove custom serialization methods for evolvable players
1 parent 4013bf2 commit f68cb0d

File tree

6 files changed

+0
-158
lines changed

6 files changed

+0
-158
lines changed

axelrod/strategies/ann.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,6 @@ def crossover(self, other):
278278
weights = crossover_lists(self.weights, other.weights)
279279
return self.create_new(weights=weights)
280280

281-
def serialize_parameters(self):
282-
return "{}:{}:{}".format(
283-
self.num_features,
284-
self.num_hidden,
285-
':'.join(map(str, self.weights))
286-
)
287-
288-
@classmethod
289-
def deserialize_parameters(cls, serialized):
290-
elements = list(map(float, serialized.split(':')))
291-
num_features = int(elements[0])
292-
num_hidden = int(elements[1])
293-
weights = elements[2:]
294-
return cls(num_features, num_hidden, weights)
295-
296281

297282
class EvolvedANN(ANN):
298283
"""

axelrod/strategies/cycler.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,6 @@ def crossover(self, other):
165165
cycle, _ = self._normalize_parameters(cycle)
166166
return self.create_new(cycle=cycle)
167167

168-
def serialize_parameters(self):
169-
return "{}:{}:{}".format(
170-
actions_to_str(self.cycle),
171-
str(self.mutation_probability),
172-
str(self.mutation_potency)
173-
)
174-
175-
@classmethod
176-
def deserialize_parameters(cls, serialized):
177-
cycle, mutation_probability, mutation_potency = list(serialized.split(':'))
178-
return cls(
179-
cycle=cycle,
180-
mutation_probability=float(mutation_probability),
181-
mutation_potency=int(mutation_potency)
182-
)
183-
184168

185169
class CyclerDC(Cycler):
186170
"""

axelrod/strategies/finite_state_machines.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -290,44 +290,6 @@ def create_vector_bounds(self):
290290
ub = [1] * size
291291
return lb, ub
292292

293-
@staticmethod
294-
def repr_rows(rows):
295-
ss = []
296-
for row in rows:
297-
ss.append("_".join(list(map(str, row))))
298-
return "|".join(ss)
299-
300-
def serialize_parameters(self):
301-
return "{}:{}:{}:{}".format(
302-
self.num_states,
303-
self.initial_state,
304-
self.initial_action,
305-
self.repr_rows(self.fsm.transitions())
306-
)
307-
308-
@classmethod
309-
def deserialize_parameters(cls, serialized):
310-
rows = []
311-
lines = serialized.split(':')
312-
num_states = int(lines[0])
313-
initial_state = int(lines[1])
314-
initial_action = Action.from_char(lines[2])
315-
316-
for line in lines[3].split('|'):
317-
row = []
318-
for element in line.split('_'):
319-
try:
320-
row.append(Action.from_char(element))
321-
except UnknownActionError:
322-
row.append(int(element))
323-
rows.append(tuple(row))
324-
return cls(
325-
transitions=tuple(rows),
326-
initial_state=initial_state,
327-
initial_action=initial_action,
328-
num_states=num_states
329-
)
330-
331293

332294
class Fortress3(FSMPlayer):
333295
"""Finite state machine player specified in http://DOI.org/10.1109/CEC.2006.1688322.

axelrod/strategies/gambler.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,6 @@ def mutate_value(cls, value):
9999
value = 1
100100
return value
101101

102-
def serialize_parameters(self):
103-
self_depth, op_depth, op_openings_depth = self.parameters
104-
return "{}:{}:{}:{}:{}".format(
105-
self_depth,
106-
op_depth,
107-
op_openings_depth,
108-
'|'.join(str(v) for v in self.pattern),
109-
actions_to_str(self.initial_actions)
110-
)
111-
112-
@classmethod
113-
def deserialize_parameters(cls, serialized):
114-
s = serialized.split(':')
115-
parameters = tuple(map(int, s[0:3]))
116-
pattern = list(map(float, s[3].split('|')))
117-
initial_actions = str_to_actions(s[4])
118-
return cls(parameters=parameters, pattern=pattern, initial_actions=initial_actions)
119-
120102
def receive_vector(self, vector):
121103
"""Receives a vector and updates the player's pattern. Ignores extra parameters."""
122104
self.pattern = vector

axelrod/strategies/hmm.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -346,53 +346,6 @@ def create_vector_bounds(self):
346346
ub = [1.0] * vec_len
347347
return lb, ub
348348

349-
@classmethod
350-
def repr_rows(cls, rows):
351-
ss = []
352-
for row in rows:
353-
ss.append("_".join(list(map(str, row))))
354-
return "|".join(ss)
355-
356-
def serialize_parameters(self):
357-
return "{}:{}:{}:{}:{}".format(
358-
self.initial_state,
359-
self.initial_action,
360-
self.repr_rows(self.hmm.transitions_C),
361-
self.repr_rows(self.hmm.transitions_D),
362-
self.repr_rows([self.hmm.emission_probabilities])
363-
)
364-
365-
@classmethod
366-
def parse_vector(cls, line):
367-
row = line.split('_')
368-
row = list(map(float, row))
369-
return row
370-
371-
@classmethod
372-
def parse_matrix(cls, sm):
373-
rows = []
374-
lines = sm.split('|')
375-
for line in lines:
376-
rows.append(cls.parse_vector(line))
377-
return rows
378-
379-
@classmethod
380-
def deserialize_parameters(cls, serialized):
381-
lines = serialized.split(':')
382-
initial_state = int(lines[0])
383-
initial_action = Action.from_char(lines[1])
384-
t_C = cls.parse_matrix(lines[2])
385-
t_D = cls.parse_matrix(lines[3])
386-
p = cls.parse_vector(lines[4])
387-
num_states = len(t_C)
388-
389-
return cls(num_states=num_states,
390-
transitions_C=t_C,
391-
transitions_D=t_D,
392-
emission_probabilities=p,
393-
initial_state=initial_state,
394-
initial_action=initial_action)
395-
396349

397350
class EvolvedHMM5(HMMPlayer):
398351
"""

axelrod/strategies/lookerup.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -505,30 +505,6 @@ def crossover(self, other):
505505
lookup_dict = crossover_dictionaries(self.lookup_dict, other.lookup_dict)
506506
return self.create_new(lookup_dict=lookup_dict)
507507

508-
def serialize_parameters(self):
509-
plays, op_plays, op_start_plays = self.parameters
510-
return "{}:{}:{}:{}:{}".format(
511-
plays,
512-
op_plays,
513-
op_start_plays,
514-
actions_to_str(self.initial_actions),
515-
actions_to_str([v for k, v in sorted(self.lookup_dict.items())])
516-
)
517-
518-
@classmethod
519-
def deserialize_parameters(cls, serialized):
520-
elements = serialized.split(':')
521-
plays, op_plays, op_start_plays = list(map(int, elements[:3]))
522-
parameters = (plays, op_plays, op_start_plays)
523-
initial_actions = str_to_actions(elements[3])
524-
pattern = str_to_actions(elements[4])
525-
keys = create_lookup_table_keys(plays, op_plays, op_start_plays)
526-
lookup_dict = dict(zip(keys, pattern))
527-
return cls(parameters=parameters,
528-
pattern=pattern,
529-
initial_actions=initial_actions,
530-
lookup_dict=lookup_dict)
531-
532508

533509
class EvolvedLookerUp1_1_1(LookerUp):
534510
"""

0 commit comments

Comments
 (0)