|
3 | 3 | Strategy Transformers |
4 | 4 | ===================== |
5 | 5 |
|
6 | | -What is a Strategy Transfomer? |
7 | | ------------------------------- |
| 6 | +What is a Strategy Transformer? |
| 7 | +------------------------------- |
8 | 8 |
|
9 | 9 | A strategy transformer is a function that modifies an existing strategy. For |
10 | 10 | example, :code:`FlipTransformer` takes a strategy and flips the actions from |
@@ -50,91 +50,98 @@ Included Transformers |
50 | 50 |
|
51 | 51 | The library includes the following transformers: |
52 | 52 |
|
53 | | -* :code:`FlipTransformer`: Flips all actions:: |
| 53 | +* :code:`ApologizingTransformer`: Apologizes after a round of :code:`(D, C)`:: |
54 | 54 |
|
55 | | - >>> FlippedCooperator = FlipTransformer()(axl.Cooperator) |
56 | | - >>> player = FlippedCooperator() |
| 55 | + >>> ApologizingDefector = ApologyTransformer([D], [C])(axl.Defector) |
| 56 | + >>> player = ApologizingDefector() |
57 | 57 |
|
58 | | -* :code:`NoisyTransformer(noise)`: Flips actions with probability :code:`noise`:: |
| 58 | + You can pass any two sequences in. In this example the player would apologize |
| 59 | + after two consequtive rounds of `(D, C)`:: |
59 | 60 |
|
60 | | - >>> NoisyCooperator = NoisyTransformer(0.5)(axl.Cooperator) |
61 | | - >>> player = NoisyCooperator() |
| 61 | + >>> ApologizingDefector = ApologyTransformer([D, D], [C, C])(axl.Defector) |
| 62 | + >>> player = ApologizingDefector() |
| 63 | + |
| 64 | +* :code:`DeadlockBreakingTransformer`: Attempts to break :code:`(D, C) -> (C, D)` deadlocks by cooperating:: |
| 65 | + |
| 66 | + >>> DeadlockBreakingTFT = DeadlockBreakingTransformer()(axl.TitForTat) |
| 67 | + >>> player = DeadlockBreakingTFT() |
62 | 68 |
|
63 | 69 | * :code:`DualTransformer`: The Dual of a strategy will return the exact opposite set of moves to the original strategy when both are faced with the same history. [Ashlock2008]_:: |
64 | 70 |
|
65 | 71 | >>> DualWSLS = DualTransformer()(axl.WinStayLoseShift) |
66 | 72 | >>> player = DualWSLS() |
67 | 73 |
|
68 | | -* :code:`JossAnnTransformer(probability)`: Where :code:`probability = (x, y)`, the Joss-Ann of a strategy is a new strategy which has a probability :code:`x` of choosing the move C, a probability :code:`y` of choosing the move D, and otherwise uses the response appropriate to the original strategy. [Ashlock2008]_:: |
| 74 | +* :code:`FlipTransformer`: Flips all actions:: |
69 | 75 |
|
70 | | - >>> JossAnnTFT = JossAnnTransformer((0.2, 0.3))(axl.TitForTat) |
71 | | - >>> player = JossAnnTFT() |
| 76 | + >>> FlippedCooperator = FlipTransformer()(axl.Cooperator) |
| 77 | + >>> player = FlippedCooperator() |
| 78 | + |
| 79 | +* :code:`FinalTransformer(seq=None)`: Ends the tournament with the moves in the sequence :code:`seq`, if the tournament_length is known. For example, to obtain a cooperator that defects on the last two rounds:: |
| 80 | + |
| 81 | + >>> FinallyDefectingCooperator = FinalTransformer([D, D])(axl.Cooperator) |
| 82 | + >>> player = FinallyDefectingCooperator() |
72 | 83 |
|
73 | 84 | * :code:`ForgiverTransformer(p)`: Flips defections with probability :code:`p`:: |
74 | 85 |
|
75 | 86 | >>> ForgivinDefector = ForgiverTransformer(0.1)(axl.Defector) |
76 | 87 | >>> player = ForgivinDefector() |
77 | 88 |
|
| 89 | +* :code:`GrudgeTransformer(N)`: Defections unconditionally after more than N defections:: |
| 90 | + |
| 91 | + >>> GrudgingCooperator = GrudgeTransformer(2)(axl.Cooperator) |
| 92 | + >>> player = GrudgingCooperator() |
| 93 | + |
78 | 94 | * :code:`InitialTransformer(seq=None)`: First plays the moves in the sequence :code:`seq`, then plays as usual. For example, to obtain a defector that cooperates on the first two rounds:: |
79 | 95 |
|
80 | 96 | >>> InitiallyCooperatingDefector = InitialTransformer([C, C])(axl.Defector) |
81 | 97 | >>> player = InitiallyCooperatingDefector() |
82 | 98 |
|
83 | | -* :code:`FinalTransformer(seq=None)`: Ends the tournament with the moves in the sequence :code:`seq`, if the tournament_length is known. For example, to obtain a cooperator that defects on the last two rounds:: |
| 99 | +* :code:`JossAnnTransformer(probability)`: Where :code:`probability = (x, y)`, the Joss-Ann of a strategy is a new strategy which has a probability :code:`x` of choosing the move C, a probability :code:`y` of choosing the move D, and otherwise uses the response appropriate to the original strategy. [Ashlock2008]_:: |
84 | 100 |
|
85 | | - >>> FinallyDefectingCooperator = FinalTransformer([D, D])(axl.Cooperator) |
86 | | - >>> player = FinallyDefectingCooperator() |
| 101 | + >>> JossAnnTFT = JossAnnTransformer((0.2, 0.3))(axl.TitForTat) |
| 102 | + >>> player = JossAnnTFT() |
87 | 103 |
|
88 | | -* :code:`RetaliateTransformer(N)`: Retaliation N times after a defection:: |
| 104 | +* :code:`MixedTransformer`: Randomly plays a mutation to another strategy (or |
| 105 | + set of strategies. Here is the syntax to do this with a set of strategies:: |
89 | 106 |
|
90 | | - >>> TwoTitsForTat = RetaliationTransformer(2)(axl.Cooperator) |
91 | | - >>> player = TwoTitsForTat() |
| 107 | + >>> strategies = [axl.Grudger, axl.TitForTat] |
| 108 | + >>> probability = [.2, .3] # .5 chance of mutated to one of above |
| 109 | + >>> player = MixedTransformer(probability, strategies)(axl.Cooperator) |
92 | 110 |
|
93 | | -* :code:`RetaliateUntilApologyTransformer()`: adds TitForTat-style retaliation:: |
| 111 | + Here is the syntax when passing a single strategy:: |
94 | 112 |
|
95 | | - >>> TFT = RetaliateUntilApologyTransformer()(axl.Cooperator) |
96 | | - >>> player = TFT() |
| 113 | + >>> strategy = axl.Grudger |
| 114 | + >>> probability = .2 |
| 115 | + >>> player = MixedTransformer(probability, strategy)(axl.Cooperator) |
97 | 116 |
|
98 | | -* :code:`ApologizingTransformer`: Apologizes after a round of :code:`(D, C)`:: |
| 117 | +* :code:`NiceTransformer()`: Prevents a strategy from defecting if the opponent |
| 118 | + has not yet defected:: |
99 | 119 |
|
100 | | - >>> ApologizingDefector = ApologyTransformer([D], [C])(axl.Defector) |
101 | | - >>> player = ApologizingDefector() |
| 120 | + >>> NiceDefector = NiceTransformer()(axl.Defector) |
| 121 | + >>> player = NiceDefector() |
102 | 122 |
|
103 | | - You can pass any two sequences in. In this example the player would apologize |
104 | | - after two consequtive rounds of `(D, C)`:: |
105 | 123 |
|
106 | | - >>> ApologizingDefector = ApologyTransformer([D, D], [C, C])(axl.Defector) |
107 | | - >>> player = ApologizingDefector() |
| 124 | +* :code:`NoisyTransformer(noise)`: Flips actions with probability :code:`noise`:: |
108 | 125 |
|
109 | | -* :code:`DeadlockBreakingTransformer`: Attempts to break :code:`(D, C) -> (C, D)` deadlocks by cooperating:: |
| 126 | + >>> NoisyCooperator = NoisyTransformer(0.5)(axl.Cooperator) |
| 127 | + >>> player = NoisyCooperator() |
110 | 128 |
|
111 | | - >>> DeadlockBreakingTFT = DeadlockBreakingTransformer()(axl.TitForTat) |
112 | | - >>> player = DeadlockBreakingTFT() |
| 129 | +* :code:`RetaliateTransformer(N)`: Retaliation N times after a defection:: |
113 | 130 |
|
114 | | -* :code:`GrudgeTransformer(N)`: Defections unconditionally after more than N defections:: |
| 131 | + >>> TwoTitsForTat = RetaliationTransformer(2)(axl.Cooperator) |
| 132 | + >>> player = TwoTitsForTat() |
115 | 133 |
|
116 | | - >>> GrudgingCooperator = GrudgeTransformer(2)(axl.Cooperator) |
117 | | - >>> player = GrudgingCooperator() |
| 134 | +* :code:`RetaliateUntilApologyTransformer()`: adds TitForTat-style retaliation:: |
| 135 | + |
| 136 | + >>> TFT = RetaliateUntilApologyTransformer()(axl.Cooperator) |
| 137 | + >>> player = TFT() |
118 | 138 |
|
119 | 139 | * :code:`TrackHistoryTransformer`: Tracks History internally in the |
120 | 140 | :code:`Player` instance in a variable :code:`_recorded_history`. This allows a |
121 | 141 | player to e.g. detect noise.:: |
122 | 142 |
|
123 | 143 | >>> player = TrackHistoryTransformer()(axl.Random)() |
124 | 144 |
|
125 | | -* :code:`MixedTransformer`: Randomly plays a mutation to another strategy (or |
126 | | - set of strategies. Here is the syntax to do this with a set of strategies:: |
127 | | - |
128 | | - >>> strategies = [axl.Grudger, axl.TitForTat] |
129 | | - >>> probability = [.2, .3] # .5 chance of mutated to one of above |
130 | | - >>> player = MixedTransformer(probability, strategies)(axl.Cooperator) |
131 | | - |
132 | | - Here is the syntax when passing a single strategy:: |
133 | | - |
134 | | - >>> strategy = axl.Grudger |
135 | | - >>> probability = .2 |
136 | | - >>> player = MixedTransformer(probability, strategy)(axl.Cooperator) |
137 | | - |
138 | 145 |
|
139 | 146 | Composing Transformers |
140 | 147 | ---------------------- |
|
0 commit comments