Skip to content

Commit 4b3369c

Browse files
authored
Add EvolvedAttention: A transformer-based neural network strategy for Prisoner's Dilemma (#1471)
* Adding attention strategy * Adding deadline=None * Adding verbosity to see which test is stalling the CI on ubuntu * Use spawn instead of fork for new process * Removing pytest-xdist -n auto * Long run time * Adding evolved attentio to long run strategies * Adding min_value for s = 0 * Changing max_examples=5 to max_examples=2 * Adding test against strategies * Removing stochastic strategy in test * Fixing randomize test * Lazy loading of model weights * mypy compliance * Shorter run time for test_meta * Adding coverage to frequency analyzer
1 parent 8fa56d2 commit 4b3369c

30 files changed

+624
-45
lines changed

axelrod/data/all_classifiers.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
$\phi$:
1+
$\\phi$:
22
inspects_source: false
33
long_run_time: false
44
makes_use_of: !!set {}
55
manipulates_source: false
66
manipulates_state: false
77
memory_depth: .inf
88
stochastic: false
9-
$\pi$:
9+
$\\pi$:
1010
inspects_source: false
1111
long_run_time: false
1212
makes_use_of: !!set {}
@@ -439,6 +439,14 @@ Evolved ANN 5 Noise 05:
439439
manipulates_state: false
440440
memory_depth: .inf
441441
stochastic: false
442+
EvolvedAttention:
443+
inspects_source: false
444+
long_run_time: True
445+
makes_use_of: !!set {}
446+
manipulates_source: false
447+
manipulates_state: false
448+
memory_depth: 200
449+
stochastic: false
442450
Evolved FSM 16:
443451
inspects_source: false
444452
long_run_time: false

axelrod/data/model_attention.pth

48.9 MB
Binary file not shown.

axelrod/load_data_.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import pkgutil
33
from typing import Callable, Dict, List, Optional, Tuple
44

5+
import torch
6+
57

68
def axl_filename(path: pathlib.Path) -> pathlib.Path:
79
"""Given a path under Axelrod/, return absolute filepath.
@@ -77,3 +79,14 @@ def load_pso_tables(filename="pso_gambler.csv", directory="data"):
7779
values = list(map(float, row[4:]))
7880
d[(name, int(a), int(b), int(c))] = values
7981
return d
82+
83+
84+
def load_attention_model_weights(
85+
filename="model_attention.pth", directory="axelrod/data"
86+
):
87+
"""Load attention model weights."""
88+
path = str(axl_filename(pathlib.Path(directory) / filename))
89+
weights = torch.load(
90+
path, map_location=torch.device("cpu"), weights_only=True
91+
)
92+
return weights

axelrod/strategies/_strategies.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .ann import ANN, EvolvableANN # pylint: disable=unused-import
3131
from .apavlov import APavlov2006, APavlov2011
3232
from .appeaser import Appeaser
33+
from .attention import EvolvedAttention
3334
from .averagecopier import AverageCopier, NiceAverageCopier
3435
from .axelrod_first import (
3536
FirstByDavis,
@@ -348,6 +349,7 @@
348349
EvolvedHMM5,
349350
EvolvedLookerUp1_1_1,
350351
EvolvedLookerUp2_2_2,
352+
EvolvedAttention,
351353
FirmButFair,
352354
FirstByAnonymous,
353355
FirstByDavis,

0 commit comments

Comments
 (0)