Skip to content

Commit 90a7a38

Browse files
committed
Add NiceTransformer to the docs and alphabetize the transformers
1 parent 8210363 commit 90a7a38

File tree

1 file changed

+53
-46
lines changed

1 file changed

+53
-46
lines changed

docs/tutorials/advanced/strategy_transformers.rst

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Strategy Transformers
44
=====================
55

6-
What is a Strategy Transfomer?
7-
------------------------------
6+
What is a Strategy Transformer?
7+
-------------------------------
88

99
A strategy transformer is a function that modifies an existing strategy. For
1010
example, :code:`FlipTransformer` takes a strategy and flips the actions from
@@ -50,91 +50,98 @@ Included Transformers
5050

5151
The library includes the following transformers:
5252

53-
* :code:`FlipTransformer`: Flips all actions::
53+
* :code:`ApologizingTransformer`: Apologizes after a round of :code:`(D, C)`::
5454

55-
>>> FlippedCooperator = FlipTransformer()(axl.Cooperator)
56-
>>> player = FlippedCooperator()
55+
>>> ApologizingDefector = ApologyTransformer([D], [C])(axl.Defector)
56+
>>> player = ApologizingDefector()
5757

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)`::
5960

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()
6268

6369
* :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]_::
6470

6571
>>> DualWSLS = DualTransformer()(axl.WinStayLoseShift)
6672
>>> player = DualWSLS()
6773

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::
6975

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()
7283

7384
* :code:`ForgiverTransformer(p)`: Flips defections with probability :code:`p`::
7485

7586
>>> ForgivinDefector = ForgiverTransformer(0.1)(axl.Defector)
7687
>>> player = ForgivinDefector()
7788

89+
* :code:`GrudgeTransformer(N)`: Defections unconditionally after more than N defections::
90+
91+
>>> GrudgingCooperator = GrudgeTransformer(2)(axl.Cooperator)
92+
>>> player = GrudgingCooperator()
93+
7894
* :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::
7995

8096
>>> InitiallyCooperatingDefector = InitialTransformer([C, C])(axl.Defector)
8197
>>> player = InitiallyCooperatingDefector()
8298

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]_::
84100

85-
>>> FinallyDefectingCooperator = FinalTransformer([D, D])(axl.Cooperator)
86-
>>> player = FinallyDefectingCooperator()
101+
>>> JossAnnTFT = JossAnnTransformer((0.2, 0.3))(axl.TitForTat)
102+
>>> player = JossAnnTFT()
87103

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::
89106

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)
92110

93-
* :code:`RetaliateUntilApologyTransformer()`: adds TitForTat-style retaliation::
111+
Here is the syntax when passing a single strategy::
94112

95-
>>> TFT = RetaliateUntilApologyTransformer()(axl.Cooperator)
96-
>>> player = TFT()
113+
>>> strategy = axl.Grudger
114+
>>> probability = .2
115+
>>> player = MixedTransformer(probability, strategy)(axl.Cooperator)
97116

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::
99119

100-
>>> ApologizingDefector = ApologyTransformer([D], [C])(axl.Defector)
101-
>>> player = ApologizingDefector()
120+
>>> NiceDefector = NiceTransformer()(axl.Defector)
121+
>>> player = NiceDefector()
102122

103-
You can pass any two sequences in. In this example the player would apologize
104-
after two consequtive rounds of `(D, C)`::
105123

106-
>>> ApologizingDefector = ApologyTransformer([D, D], [C, C])(axl.Defector)
107-
>>> player = ApologizingDefector()
124+
* :code:`NoisyTransformer(noise)`: Flips actions with probability :code:`noise`::
108125

109-
* :code:`DeadlockBreakingTransformer`: Attempts to break :code:`(D, C) -> (C, D)` deadlocks by cooperating::
126+
>>> NoisyCooperator = NoisyTransformer(0.5)(axl.Cooperator)
127+
>>> player = NoisyCooperator()
110128

111-
>>> DeadlockBreakingTFT = DeadlockBreakingTransformer()(axl.TitForTat)
112-
>>> player = DeadlockBreakingTFT()
129+
* :code:`RetaliateTransformer(N)`: Retaliation N times after a defection::
113130

114-
* :code:`GrudgeTransformer(N)`: Defections unconditionally after more than N defections::
131+
>>> TwoTitsForTat = RetaliationTransformer(2)(axl.Cooperator)
132+
>>> player = TwoTitsForTat()
115133

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()
118138

119139
* :code:`TrackHistoryTransformer`: Tracks History internally in the
120140
:code:`Player` instance in a variable :code:`_recorded_history`. This allows a
121141
player to e.g. detect noise.::
122142

123143
>>> player = TrackHistoryTransformer()(axl.Random)()
124144

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-
138145

139146
Composing Transformers
140147
----------------------

0 commit comments

Comments
 (0)