|
1 | 1 | # Axelrod Evolvers
|
2 | 2 |
|
3 |
| -This repository contains training code for the strategies LookerUp, PSOGambler, and EvolvedANN (feed-forward neural network). |
4 |
| -There are three scripts, one for each strategy: |
5 |
| -* looker_evolve.py |
6 |
| -* pso_evolve.py |
7 |
| -* ann_evolve.py |
8 |
| - |
9 |
| -In the original iteration the strategies were run against all the default strategies in the Axelrod library. This is slow and probably not necessary. For example the Meta players are just combinations of the other players, and very computationally intensive; it's probably ok to remove those. |
| 3 | +This repository contains reinforcement learning training code for the following |
| 4 | +strategy types: |
| 5 | +* Lookup tables (LookerUp) |
| 6 | +* Particle Swarm algorithms (PSOGambler) |
| 7 | +* Feed Forward Neural Network (EvolvedANN) |
| 8 | +* Finite State Machine (FSMPlayer) |
| 9 | + |
| 10 | +The training is done by evolutionary algorithms or particle swarm algorithms. There |
| 11 | +is another repository that trains Neural Networks with gradient descent. In this |
| 12 | +repository there are scripts for each strategy type: |
| 13 | + |
| 14 | +* [looker_evolve.py](looker_evolve.py) |
| 15 | +* [pso_evolve.py](pso_evolve.py) |
| 16 | +* [ann_evolve.py](ann_evolve.py) |
| 17 | +* [fsm_evolve.py](fsm_evolve.py) |
| 18 | + |
| 19 | +In the original iteration the strategies were run against all the default |
| 20 | +strategies in the Axelrod library. This is slow and probably not necessary. For |
| 21 | +example the Meta players are just combinations of the other players, and very |
| 22 | +computationally intensive; it's probably ok to remove those. So by default the |
| 23 | +training strategies are the `short_run_time_strategies` from the Axelrod library. |
10 | 24 |
|
11 | 25 | ## The Strategies
|
12 | 26 |
|
13 |
| -The LookerUp strategies are based on lookup tables with two parameters: |
14 |
| -* n, the number of rounds of trailing history to use and |
| 27 | +The LookerUp strategies are based on lookup tables with three parameters: |
| 28 | +* n1, the number of rounds of trailing history to use and |
| 29 | +* n2, the number of rounds of trailing opponent history to use |
15 | 30 | * m, the number of rounds of initial opponent play to use
|
16 | 31 |
|
17 |
| -PSOGambler is a stochastic version of LookerUp, trained with a particle swarm algorithm. |
| 32 | +PSOGambler is a stochastic version of LookerUp, trained with a particle swarm |
| 33 | +algorithm. The resulting strategies are generalizations of memory-N strategies. |
18 | 34 |
|
19 | 35 | EvolvedANN is one hidden layer feed forward neural network based algorithm.
|
| 36 | +Various features are derived from the history of play. The number of nodes in |
| 37 | +the hidden layer can be changed. |
20 | 38 |
|
21 |
| -All three strategies are trained with an evolutionary algorithm and are examples of reinforcement learning. |
| 39 | +EvolvedFSM searches over finite state machines with a given number of states. |
22 | 40 |
|
23 |
| -### Open questions |
| 41 | +Note that large values of the parameters will make the strategies prone to |
| 42 | +overfitting. |
24 | 43 |
|
25 |
| -* What's the best table for n, m for LookerUp and PSOGambler? |
26 |
| -* What's the best table against parameterized strategies? For example, if the opponents are `[RandomPlayer(x) for x in np.arange(0, 1, 0.01)], what lookup table is best? Is it much different from the generic table? |
27 |
| -* Can we separate n into n1 and n2 where different amounts of history are used for the player and the opponent? |
28 |
| -* Are there other features that would improve the performance of EvolvedANN? |
| 44 | +## Optimization Functions |
29 | 45 |
|
| 46 | +There are three objective functions: |
| 47 | +* Maximize mean match score over all opponents with `objective_match_score` |
| 48 | +* Maximize mean match score difference over all opponents with `objective_match_score_difference` |
| 49 | +* Maximize Moran process fixation probability with `objective_match_moran_win` |
30 | 50 |
|
31 | 51 | ## Running
|
32 | 52 |
|
33 |
| -`python lookup-evolve.py -h` |
34 |
| - |
35 |
| -will display help. There are a number of options and you'll want to set the mutation rate appropriately. The number of keys defining the strategy is `2**{n + m + 1}` so you want a mutation rate in the neighborhood of `2**(-n-m)` so that there's enough variation introduced. |
36 |
| - |
37 |
| - |
38 |
| -Here are some recommended defaults: |
| 53 | +### Look up Tables |
| 54 | + |
| 55 | +```bash |
| 56 | +$ python lookup_evolve.py -h |
| 57 | +Lookup Evolve. |
| 58 | + |
| 59 | +Usage: |
| 60 | + lookup_evolve.py [-h] [-p PLAYS] [-o OPP_PLAYS] [-s STARTING_PLAYS] |
| 61 | + [-g GENERATIONS] [-k STARTING_POPULATION] [-u MUTATION_RATE] [-b BOTTLENECK] |
| 62 | + [-i PROCESSORS] [-f OUTPUT_FILE] [-z INITIAL_POPULATION_FILE] [-n NOISE] |
| 63 | + |
| 64 | +Options: |
| 65 | + -h --help show this |
| 66 | + -p PLAYS number of recent plays in the lookup table [default: 2] |
| 67 | + -o OPP_PLAYS number of recent plays in the lookup table [default: 2] |
| 68 | + -s STARTING_PLAYS number of opponent starting plays in the lookup table [default: 2] |
| 69 | + -g GENERATIONS how many generations to run the program for [default: 500] |
| 70 | + -k STARTING_POPULATION starting population size for the simulation [default: 20] |
| 71 | + -u MUTATION_RATE mutation rate i.e. probability that a given value will flip [default: 0.1] |
| 72 | + -b BOTTLENECK number of individuals to keep from each generation [default: 10] |
| 73 | + -i PROCESSORS number of processors to use [default: 1] |
| 74 | + -f OUTPUT_FILE file to write data to [default: tables.csv] |
| 75 | + -z INITIAL_POPULATION_FILE file to read an initial population from [default: None] |
| 76 | + -n NOISE match noise [default: 0.00] |
39 | 77 | ```
|
40 |
| -python lookup_evolve.py -p 3 -s 3 -g 100000 -k 20 -u 0.01 -b 20 -i 4 -o evolve3-3.csv |
41 | 78 |
|
42 |
| -python lookup_evolve.py -p 3 -s 2 -g 100000 -k 20 -u 0.03 -b 20 -i 4 -o evolve3-2.csv |
| 79 | +There are a number of options and you'll want to set the |
| 80 | +mutation rate appropriately. The number of keys defining the strategy is |
| 81 | +`2**{n + m + 1}` so you want a mutation rate in the neighborhood of `2**(-n-m)` |
| 82 | +so that there's enough variation introduced. |
43 | 83 |
|
44 |
| -python lookup_evolve.py -p 3 -s 1 -g 100000 -k 20 -u 0.06 -b 20 -i 4 -o evolve3-1.csv |
| 84 | +### Particle Swarm |
45 | 85 |
|
46 |
| -python lookup_evolve.py -p 1 -s 3 -g 100000 -k 20 -u 0.03 -b 20 -i 4 -o evolve1-3.csv |
| 86 | +```bash |
| 87 | +$ python pso_evolve.py -h |
| 88 | +Particle Swarm strategy training code. |
47 | 89 |
|
48 |
| -python lookup_evolve.py -p 2 -s 3 -g 100000 -k 20 -u 0.03 -b 20 -i 4 -o evolve2-3.csv |
49 |
| -``` |
50 |
| -### 2, 2 is the current winner: |
51 |
| -``` |
52 |
| -python lookup_evolve.py -p 2 -s 2 -g 100000 -k 20 -u 0.06 -b 20 -i 4 -o evolve2-2.csv |
53 |
| -
|
54 |
| -python lookup_evolve.py -p 1 -s 2 -g 100000 -k 20 -u 0.1 -b 20 -i 2 -o evolve1-2.csv |
55 |
| -
|
56 |
| -python lookup_evolve.py -p 1 -s 2 -g 100000 -k 20 -u 0.1 -b 20 -i 2 -o evolve2-1.csv |
| 90 | +Usage: |
| 91 | + pso_evolve.py [-h] [-p PLAYS] [-s STARTING_PLAYS] [-g GENERATIONS] |
| 92 | + [-i PROCESSORS] [-o OPP_PLAYS] [-n NOISE] |
57 | 93 |
|
| 94 | +Options: |
| 95 | + -h --help show help |
| 96 | + -p PLAYS number of recent plays in the lookup table [default: 2] |
| 97 | + -o OPP_PLAYS number of recent opponent's plays in the lookup table [default: 2] |
| 98 | + -s STARTING_PLAYS number of opponent starting plays in the lookup table [default: 2] |
| 99 | + -i PROCESSORS number of processors to use [default: 1] |
| 100 | + -n NOISE match noise [default: 0.0] |
58 | 101 | ```
|
59 |
| -### 4, 4 (might take for ever / need a ton of ram) |
| 102 | +
|
| 103 | +Note that to use the multiprocessor version you'll need to install pyswarm 0.70 |
| 104 | +directly (pip installs 0.60 which lacks mutiprocessing support). |
| 105 | + |
| 106 | +### Neural Network |
| 107 | + |
| 108 | +```bash |
| 109 | +$ python ann_evolve.py -h |
| 110 | +Training ANN strategies with an evolutionary algorithm. |
| 111 | +
|
| 112 | +Usage: |
| 113 | + ann_evolve.py [-h] [-g GENERATIONS] [-u MUTATION_RATE] [-b BOTTLENECK] |
| 114 | + [-d MUTATION_DISTANCE] [-i PROCESSORS] [-o OUTPUT_FILE] |
| 115 | + [-k STARTING_POPULATION] [-n NOISE] |
| 116 | +
|
| 117 | +Options: |
| 118 | + -h --help show this |
| 119 | + -g GENERATIONS how many generations to run the program for [default: 10000] |
| 120 | + -u MUTATION_RATE mutation rate i.e. probability that a given value will flip [default: 0.4] |
| 121 | + -d MUTATION_DISTANCE amount of change a mutation will cause [default: 10] |
| 122 | + -b BOTTLENECK number of individuals to keep from each generation [default: 6] |
| 123 | + -i PROCESSORS number of processors to use [default: 4] |
| 124 | + -o OUTPUT_FILE file to write statistics to [default: weights.csv] |
| 125 | + -k STARTING_POPULATION starting population size for the simulation [default: 5] |
| 126 | + -n NOISE match noise [default: 0.0] |
60 | 127 | ```
|
61 |
| -python lookup_evolve.py -p 4 -s 4 -g 100000 -k 20 -u 0.002 -b 20 -i 4 -o evolve4-4.csv |
| 128 | + |
| 129 | +### Finite State Machines |
| 130 | + |
| 131 | +```bash |
| 132 | +$ python fsm_evolve.py -h |
| 133 | +FSM Evolve. |
| 134 | +
|
| 135 | +Usage: |
| 136 | + fsm_evolve.py [-h] [-s NUM_STATES] [-g GENERATIONS] |
| 137 | + [-k STARTING_POPULATION] [-u MUTATION_RATE] [-b BOTTLENECK] |
| 138 | + [-i PROCESSORS] [-f OUTPUT_FILE] [-n NOISE] |
| 139 | +
|
| 140 | +Options: |
| 141 | + -h --help show this |
| 142 | + -s NUM_STATES number FSM states [default: 16] |
| 143 | + -g GENERATIONS how many generations to run the program for [default: 500] |
| 144 | + -k STARTING_POPULATION starting population size for the simulation [default: 20] |
| 145 | + -u MUTATION_RATE mutation rate i.e. probability that a given value will flip [default: 0.1] |
| 146 | + -b BOTTLENECK number of individuals to keep from each generation [default: 10] |
| 147 | + -i PROCESSORS number of processors to use [default: 1] |
| 148 | + -f OUTPUT_FILE file to write data to [default: fsm_tables.csv] |
| 149 | + -n NOISE match noise [default: 0.00] |
62 | 150 | ```
|
63 |
| -## Analyzing |
64 | 151 |
|
65 |
| -The output files `evolve{n}-{m}.csv` can be easily sorted by `analyze_data.py`, which will output the best performing tables. These can be added back into Axelrod. |
| 152 | +## Open questions |
| 153 | + |
| 154 | +* What's the best table for n1, n2, m for LookerUp and PSOGambler? What's the |
| 155 | +smallest value of the parameters that gives good results? |
| 156 | +* Similarly what's the optimal number of states for a finite state machine |
| 157 | +strategy? |
| 158 | +* What's the best table against parameterized strategies? For example, if the |
| 159 | +opponents are `[RandomPlayer(x) for x in np.arange(0, 1, 0.01)], what lookup |
| 160 | +table is best? Is it much different from the generic table? |
| 161 | +* Are there other features that would improve the performance of EvolvedANN? |
0 commit comments