Closed drvinceknight closed 7 years ago
Yes, it should. Do we want to change the name, or the __repr__
function?
We're currently adding a prefix to the name so I suggest doing that?
I think name is fine for now although we do have some redundancy / overlap with the class name and the __repr__
method, and it might be better for the transformer to wrap the __repr__
method.
Instead of making it the strategy responsibility to change its __repr__
method according to its parameters like Random does, wouldn't it be more efficient to change Player.__repr__
to something like this :
def __repr__(self):
name = self.name
sig = inspect.signature(self.__init__)
prefix = ': '
for param in sig.parameters:
if param != 'self':
name += prefix+str(getattr(self,param, ''))
prefix = ', '
return name
Tested on Random, returns Random: 0.5
Interesting idea! For some strategies this could produce very long names depending on the parameters. I think we need to check that this produces good results for all strategies. We'd also need to document the automatic name generation and give instructions on how to override.
I recommend rewriting the function a bit to use the stored __init__
parameters that Player.__new__
places in self.init_args
and self.kwargs
, which I think eliminates the need for inspect
in this case. The parameter extraction should have already been done before __repr__
is called. We should also probably check that class.name
makes sense for unsubstantiated players.
Interesting idea! For some strategies this could produce very long names depending on the parameters. I think we need to check that this produces good results for all strategies. We'd also need to document the automatic name generation and give instructions on how to override.
I really like this idea and @marcharper's suggestions too. :+1:
Using self.init_args
is even better yes, but it only store the specified parameters we use to call the constructor ; so, not default ones. So we need to choose if the expected behavior is to have __repr__
of Random()
return "Random" and __repr__
of Random(0.5)
return "Random: 0.5" , or if we want "Random: 0.5" for the first one also. Then we'd need to use inspect or to store also default arguments in self.init_args
, but right now I don't see a good way to do that since __new__
only receive the parameter we specify.
Anyway, this matter, doesn't solve the initial question, so I've opened another issue about it Axelrod-Python/Axelrod#920
Anyway, this matter, doesn't solve the initial question, so I've opened another issue about it Axelrod-Python/Axelrod#920
I think it's ok to keep the discussion on these topics here, in essence the original question has evolved in to "what's best way to do this" (we can always rename this issue which is nicer because we see the evolution of the discussion). I've closed #920 (but we can always reopen it if we feel that it's worth compartmentalising things). :+1:
So we need to choose if the expected behavior is to have repr of Random() return "Random" and repr of Random(0.5) return "Random: 0.5"
My initial thought is that it would be ok to keep defaults "silent": although Random()
returning "Random"
and Random(0.5)
returning Random: 0.5
is not ideal...
I think that if the strategy has init args, then they should appear in its representation even if they weren't specified and are just the defaults. Not doing so make the strategy look as if there are no init args at all.
I see 3 approaches to doing this:
self.kwargs
idea to pick up defaults (am I right?)I don't think 3 is a good option at all. 1 or 2 can be complemented by the possibility of overriding if need be in some specific cases so I suggest one of those. In fact I guess that "any" of those would be good and can be refactored if need be.
Ok for the original problem in StrategyTransformer
, since this wouldn't solve it anyway, We could just add something like :
strategy_transformer : L111
name = name_prefix + ' ' + PlayerClass.name
prefix = ': '
for arg in args:
name += prefix+str(arg)
prefix = ', '
Which then give
In [3]: player = axl.strategy_transformers.NoisyTransformer(0.5)(axl.Cooperator)()
In [4]: player
Out[4]: Noisy Cooperator: 0.5
As for the basic strategies, I tested with inspect what the output would be :
Adaptive: ['C', 'C', 'C', 'C', 'C', 'C', 'D', 'D', 'D', 'D', 'D']
Adaptive Tit For Tat: 0.5
Aggravater
ALLCorALLD
Alternator
Alternator Hunter
AntiCycler
Anti Tit For Tat
Adaptive Pavlov 2006
Adaptive Pavlov 2011
Appeaser
Arrogant QLearner
Average Copier
Better and Better
BackStabber
Bully
Calculator
Cautious QLearner
Champion
CollectiveStrategy
Contrite Tit For Tat
Cooperator
Cooperator Hunter
Cycle Hunter
Cycler CCCCCD: CCCCCD
Cycler CCCD: CCCD
Cycler CCD: CCD
Cycler DC: DC
Cycler DDC: DDC
Cycler CCCDCD: CCCDCD
Darwin
Davis:
Defector
Defector Hunter
Desperate
DoubleCrosser
Doubler
EasyGo
Eatherley
Eventual Cycle Hunter
Evolved ANN
Evolved ANN 5
Evolved ANN 5 Noise 05
Evolved FSM 4
Evolved FSM 16
Evolved FSM 16 Noise 05
EvolvedLookerUp1_1_1
EvolvedLookerUp2_2_2
Evolved HMM 5
Feld: , ,
Firm But Fair
Fool Me Forever
Fool Me Once
Forgetful Fool Me Once: 0.05
Forgetful Grudger
Forgiver
Forgiving Tit For Tat
Fortress3
Fortress4
GTFT: 0.33333333333333337
Geller
Geller Cooperator
Geller Defector
Soft Go By Majority: , True
Soft Go By Majority: 10: , True
Soft Go By Majority: 20: , True
Soft Go By Majority: 40: , True
Soft Go By Majority: 5: , True
$\phi$
Gradual
Gradual Killer
Grofman
Grudger
GrudgerAlternator
Grumpy: Nice, 10, -10
Handshake: ['C', 'D']
Hard Go By Majority: , False
Hard Go By Majority: 10: , False
Hard Go By Majority: 20: , False
Hard Go By Majority: 40: , False
Hard Go By Majority: 5: , False
Hard Prober
Hard Tit For 2 Tats
Hard Tit For Tat
Hesitant QLearner
Hopeless
Inverse
Inverse Punisher
Joss: 0.9
Knowledgeable Worse and Worse
Level Punisher
Limited Retaliate (0.1/20): 0.1, 20
Limited Retaliate (0.08/15): 0.08, 15
Limited Retaliate (0.05/20): 0.05, 20
Math Constant Hunter
Naive Prober: 0.1
MEM2
Mind Bender
Mind Controller
Mind Reader
Mind Warper
Mirror Mind Reader
Negation
Nice Average Copier
Nydegger
Omega TFT: 3, 8
Once Bitten
Opposite Grudger
$\pi$
Predator
Prober
Prober 2
Prober 3
Prober 4
Protected Mind Reader
Pun1
PSO Gambler 1_1_1
PSO Gambler 2_2_2
PSO Gambler 2_2_2 Noise 05
PSO Gambler Mem1
Punisher
Raider
Random: 0.5
Random Hunter
Remorseful Prober: 0.1
Resurrection
Retaliate (0.1): 0.1
Retaliate (0.08): 0.08
Retaliate (0.05): 0.05
Revised Downing: True
Ripoff
Risky QLearner
SelfSteem
ShortMem
Shubik
Slow Tit For Two Tats
Sneaky Tit For Tat
Soft Grudger
Soft Joss: 0.9
SolutionB1
SolutionB5
Spiteful Tit For Tat
Stalker
Stochastic Cooperator
Stochastic WSLS: 0.05
Suspicious Tit For Tat
Tester
ThueMorse
ThueMorseInverse
Thumper
Tit For Tat
Tit For 2 Tats
Tricky Cooperator
Tricky Defector
Tullock:
Two Tits For Tat
VeryBad
Willing
Winner12
Winner21
Win-Shift Lose-Stay:
Win-Stay Lose-Shift:
Worse and Worse
Worse and Worse 2
Worse and Worse 3
ZD-Extort-2: 0.1111111111111111, 0.5
ZD-Extort-2 v2: 0.125, 0.5, 1
ZD-Extort-4: 0.23529411764705882, 0.25, 1
ZD-GTFT-2: 0.25, 0.5
ZD-GEN-2: 0.125, 0.5, 3
ZD-SET-2: 0.25, 0.0, 2
$e$
Meta Hunter
Meta Hunter Aggressive: [Defector Hunter, Alternator Hunter, Random Hunter, Math Constant Hunter, Cycle Hunter, Eventual Cycle Hunter, Cooperator Hunter]
Meta Majority: [Adaptive, Adaptive Tit For Tat: 0.5, Aggravater, ALLCorALLD, Alternator, Alternator Hunter, AntiCycler, Anti Tit For Tat, Adaptive Pavlov 2006, Adaptive Pavlov 2011, Appeaser, Arrogant QLearner, Average Copier, Better and Better, BackStabber, Bully, Calculator, Cautious QLearner, Champion, CollectiveStrategy, Contrite Tit For Tat, Cooperator, Cooperator Hunter, Cycle Hunter, Cycler CCCCCD, Cycler CCCD, Cycler CCD, Cycler DC, Cycler DDC, Cycler CCCDCD, Davis, Defector, Defector Hunter, Desperate, DoubleCrosser, Doubler, EasyGo, Eatherley, Eventual Cycle Hunter, Evolved ANN, Evolved ANN 5, Evolved ANN 5 Noise 05, Evolved FSM 4, Evolved FSM 16, Evolved FSM 16 Noise 05, EvolvedLookerUp1_1_1, EvolvedLookerUp2_2_2, Evolved HMM 5, Feld, Firm But Fair, Fool Me Forever, Fool Me Once, Forgetful Fool Me Once, Forgetful Grudger, Forgiver, Forgiving Tit For Tat, Fortress3, Fortress4, GTFT: 0.33, Soft Go By Majority, Soft Go By Majority: 10, Soft Go By Majority: 20, Soft Go By Majority: 40, Soft Go By Majority: 5, $\phi$, Gradual, Gradual Killer, Grofman, Grudger, GrudgerAlternator, Grumpy, Handshake, Hard Go By Majority, Hard Go By Majority: 10, Hard Go By Majority: 20, Hard Go By Majority: 40, Hard Go By Majority: 5, Hard Prober, Hard Tit For 2 Tats, Hard Tit For Tat, Hesitant QLearner, Hopeless, Inverse, Inverse Punisher, Joss: 0.9, Knowledgeable Worse and Worse, Level Punisher, Limited Retaliate (0.1/20), Limited Retaliate (0.08/15), Limited Retaliate (0.05/20), Math Constant Hunter, Naive Prober: 0.1, MEM2, Negation, Nice Average Copier, Nydegger, Omega TFT, Once Bitten, Opposite Grudger, $\pi$, Predator, Prober, Prober 2, Prober 3, Prober 4, Pun1, PSO Gambler 1_1_1, PSO Gambler 2_2_2, PSO Gambler 2_2_2 Noise 05, PSO Gambler Mem1, Punisher, Raider, Random: 0.5, Random Hunter, Remorseful Prober: 0.1, Resurrection, Retaliate (0.1), Retaliate (0.08), Retaliate (0.05), Revised Downing, Ripoff, Risky QLearner, SelfSteem, ShortMem, Shubik, Slow Tit For Two Tats, Sneaky Tit For Tat, Soft Grudger, Soft Joss: 0.9, SolutionB1, SolutionB5, Spiteful Tit For Tat, Stalker, Stochastic Cooperator, Stochastic WSLS, Suspicious Tit For Tat, Tester, ThueMorse, ThueMorseInverse, Thumper, Tit For Tat, Tit For 2 Tats, Tricky Cooperator, Tricky Defector, Tullock, Two Tits For Tat, VeryBad, Willing, Winner12, Winner21, Win-Shift Lose-Stay, Win-Stay Lose-Shift, Worse and Worse, Worse and Worse 2, Worse and Worse 3, ZD-Extort-2, ZD-Extort-2 v2, ZD-Extort-4, ZD-GTFT-2, ZD-GEN-2, ZD-SET-2, $e$]
Meta Majority Memory One
Meta Majority Finite Memory
Meta Majority Long Memory
Meta Minority: [Adaptive, Adaptive Tit For Tat: 0.5, Aggravater, ALLCorALLD, Alternator, Alternator Hunter, AntiCycler, Anti Tit For Tat, Adaptive Pavlov 2006, Adaptive Pavlov 2011, Appeaser, Arrogant QLearner, Average Copier, Better and Better, BackStabber, Bully, Calculator, Cautious QLearner, Champion, CollectiveStrategy, Contrite Tit For Tat, Cooperator, Cooperator Hunter, Cycle Hunter, Cycler CCCCCD, Cycler CCCD, Cycler CCD, Cycler DC, Cycler DDC, Cycler CCCDCD, Davis, Defector, Defector Hunter, Desperate, DoubleCrosser, Doubler, EasyGo, Eatherley, Eventual Cycle Hunter, Evolved ANN, Evolved ANN 5, Evolved ANN 5 Noise 05, Evolved FSM 4, Evolved FSM 16, Evolved FSM 16 Noise 05, EvolvedLookerUp1_1_1, EvolvedLookerUp2_2_2, Evolved HMM 5, Feld, Firm But Fair, Fool Me Forever, Fool Me Once, Forgetful Fool Me Once, Forgetful Grudger, Forgiver, Forgiving Tit For Tat, Fortress3, Fortress4, GTFT: 0.33, Soft Go By Majority, Soft Go By Majority: 10, Soft Go By Majority: 20, Soft Go By Majority: 40, Soft Go By Majority: 5, $\phi$, Gradual, Gradual Killer, Grofman, Grudger, GrudgerAlternator, Grumpy, Handshake, Hard Go By Majority, Hard Go By Majority: 10, Hard Go By Majority: 20, Hard Go By Majority: 40, Hard Go By Majority: 5, Hard Prober, Hard Tit For 2 Tats, Hard Tit For Tat, Hesitant QLearner, Hopeless, Inverse, Inverse Punisher, Joss: 0.9, Knowledgeable Worse and Worse, Level Punisher, Limited Retaliate (0.1/20), Limited Retaliate (0.08/15), Limited Retaliate (0.05/20), Math Constant Hunter, Naive Prober: 0.1, MEM2, Negation, Nice Average Copier, Nydegger, Omega TFT, Once Bitten, Opposite Grudger, $\pi$, Predator, Prober, Prober 2, Prober 3, Prober 4, Pun1, PSO Gambler 1_1_1, PSO Gambler 2_2_2, PSO Gambler 2_2_2 Noise 05, PSO Gambler Mem1, Punisher, Raider, Random: 0.5, Random Hunter, Remorseful Prober: 0.1, Resurrection, Retaliate (0.1), Retaliate (0.08), Retaliate (0.05), Revised Downing, Ripoff, Risky QLearner, SelfSteem, ShortMem, Shubik, Slow Tit For Two Tats, Sneaky Tit For Tat, Soft Grudger, Soft Joss: 0.9, SolutionB1, SolutionB5, Spiteful Tit For Tat, Stalker, Stochastic Cooperator, Stochastic WSLS, Suspicious Tit For Tat, Tester, ThueMorse, ThueMorseInverse, Thumper, Tit For Tat, Tit For 2 Tats, Tricky Cooperator, Tricky Defector, Tullock, Two Tits For Tat, VeryBad, Willing, Winner12, Winner21, Win-Shift Lose-Stay, Win-Stay Lose-Shift, Worse and Worse, Worse and Worse 2, Worse and Worse 3, ZD-Extort-2, ZD-Extort-2 v2, ZD-Extort-4, ZD-GTFT-2, ZD-GEN-2, ZD-SET-2, $e$]
Meta Mixer: [Adaptive, Adaptive Tit For Tat: 0.5, Aggravater, ALLCorALLD, Alternator, Alternator Hunter, AntiCycler, Anti Tit For Tat, Adaptive Pavlov 2006, Adaptive Pavlov 2011, Appeaser, Arrogant QLearner, Average Copier, Better and Better, BackStabber, Bully, Calculator, Cautious QLearner, Champion, CollectiveStrategy, Contrite Tit For Tat, Cooperator, Cooperator Hunter, Cycle Hunter, Cycler CCCCCD, Cycler CCCD, Cycler CCD, Cycler DC, Cycler DDC, Cycler CCCDCD, Davis, Defector, Defector Hunter, Desperate, DoubleCrosser, Doubler, EasyGo, Eatherley, Eventual Cycle Hunter, Evolved ANN, Evolved ANN 5, Evolved ANN 5 Noise 05, Evolved FSM 4, Evolved FSM 16, Evolved FSM 16 Noise 05, EvolvedLookerUp1_1_1, EvolvedLookerUp2_2_2, Evolved HMM 5, Feld, Firm But Fair, Fool Me Forever, Fool Me Once, Forgetful Fool Me Once, Forgetful Grudger, Forgiver, Forgiving Tit For Tat, Fortress3, Fortress4, GTFT: 0.33, Soft Go By Majority, Soft Go By Majority: 10, Soft Go By Majority: 20, Soft Go By Majority: 40, Soft Go By Majority: 5, $\phi$, Gradual, Gradual Killer, Grofman, Grudger, GrudgerAlternator, Grumpy, Handshake, Hard Go By Majority, Hard Go By Majority: 10, Hard Go By Majority: 20, Hard Go By Majority: 40, Hard Go By Majority: 5, Hard Prober, Hard Tit For 2 Tats, Hard Tit For Tat, Hesitant QLearner, Hopeless, Inverse, Inverse Punisher, Joss: 0.9, Knowledgeable Worse and Worse, Level Punisher, Limited Retaliate (0.1/20), Limited Retaliate (0.08/15), Limited Retaliate (0.05/20), Math Constant Hunter, Naive Prober: 0.1, MEM2, Negation, Nice Average Copier, Nydegger, Omega TFT, Once Bitten, Opposite Grudger, $\pi$, Predator, Prober, Prober 2, Prober 3, Prober 4, Pun1, PSO Gambler 1_1_1, PSO Gambler 2_2_2, PSO Gambler 2_2_2 Noise 05, PSO Gambler Mem1, Punisher, Raider, Random: 0.5, Random Hunter, Remorseful Prober: 0.1, Resurrection, Retaliate (0.1), Retaliate (0.08), Retaliate (0.05), Revised Downing, Ripoff, Risky QLearner, SelfSteem, ShortMem, Shubik, Slow Tit For Two Tats, Sneaky Tit For Tat, Soft Grudger, Soft Joss: 0.9, SolutionB1, SolutionB5, Spiteful Tit For Tat, Stalker, Stochastic Cooperator, Stochastic WSLS, Suspicious Tit For Tat, Tester, ThueMorse, ThueMorseInverse, Thumper, Tit For Tat, Tit For 2 Tats, Tricky Cooperator, Tricky Defector, Tullock, Two Tits For Tat, VeryBad, Willing, Winner12, Winner21, Win-Shift Lose-Stay, Win-Stay Lose-Shift, Worse and Worse, Worse and Worse 2, Worse and Worse 3, ZD-Extort-2, ZD-Extort-2 v2, ZD-Extort-4, ZD-GTFT-2, ZD-GEN-2, ZD-SET-2, $e$], None
Meta Winner: [Adaptive, Adaptive Tit For Tat: 0.5, Aggravater, ALLCorALLD, Alternator, Alternator Hunter, AntiCycler, Anti Tit For Tat, Adaptive Pavlov 2006, Adaptive Pavlov 2011, Appeaser, Arrogant QLearner, Average Copier, Better and Better, BackStabber, Bully, Calculator, Cautious QLearner, Champion, CollectiveStrategy, Contrite Tit For Tat, Cooperator, Cooperator Hunter, Cycle Hunter, Cycler CCCCCD, Cycler CCCD, Cycler CCD, Cycler DC, Cycler DDC, Cycler CCCDCD, Davis, Defector, Defector Hunter, Desperate, DoubleCrosser, Doubler, EasyGo, Eatherley, Eventual Cycle Hunter, Evolved ANN, Evolved ANN 5, Evolved ANN 5 Noise 05, Evolved FSM 4, Evolved FSM 16, Evolved FSM 16 Noise 05, EvolvedLookerUp1_1_1, EvolvedLookerUp2_2_2, Evolved HMM 5, Feld, Firm But Fair, Fool Me Forever, Fool Me Once, Forgetful Fool Me Once, Forgetful Grudger, Forgiver, Forgiving Tit For Tat, Fortress3, Fortress4, GTFT: 0.33, Soft Go By Majority, Soft Go By Majority: 10, Soft Go By Majority: 20, Soft Go By Majority: 40, Soft Go By Majority: 5, $\phi$, Gradual, Gradual Killer, Grofman, Grudger, GrudgerAlternator, Grumpy, Handshake, Hard Go By Majority, Hard Go By Majority: 10, Hard Go By Majority: 20, Hard Go By Majority: 40, Hard Go By Majority: 5, Hard Prober, Hard Tit For 2 Tats, Hard Tit For Tat, Hesitant QLearner, Hopeless, Inverse, Inverse Punisher, Joss: 0.9, Knowledgeable Worse and Worse, Level Punisher, Limited Retaliate (0.1/20), Limited Retaliate (0.08/15), Limited Retaliate (0.05/20), Math Constant Hunter, Naive Prober: 0.1, MEM2, Negation, Nice Average Copier, Nydegger, Omega TFT, Once Bitten, Opposite Grudger, $\pi$, Predator, Prober, Prober 2, Prober 3, Prober 4, Pun1, PSO Gambler 1_1_1, PSO Gambler 2_2_2, PSO Gambler 2_2_2 Noise 05, PSO Gambler Mem1, Punisher, Raider, Random: 0.5, Random Hunter, Remorseful Prober: 0.1, Resurrection, Retaliate (0.1), Retaliate (0.08), Retaliate (0.05), Revised Downing, Ripoff, Risky QLearner, SelfSteem, ShortMem, Shubik, Slow Tit For Two Tats, Sneaky Tit For Tat, Soft Grudger, Soft Joss: 0.9, SolutionB1, SolutionB5, Spiteful Tit For Tat, Stalker, Stochastic Cooperator, Stochastic WSLS, Suspicious Tit For Tat, Tester, ThueMorse, ThueMorseInverse, Thumper, Tit For Tat, Tit For 2 Tats, Tricky Cooperator, Tricky Defector, Tullock, Two Tits For Tat, VeryBad, Willing, Winner12, Winner21, Win-Shift Lose-Stay, Win-Stay Lose-Shift, Worse and Worse, Worse and Worse 2, Worse and Worse 3, ZD-Extort-2, ZD-Extort-2 v2, ZD-Extort-4, ZD-GTFT-2, ZD-GEN-2, ZD-SET-2, $e$]
Meta Winner Deterministic
Meta Winner Ensemble: [Adaptive, Adaptive Tit For Tat: 0.5, Aggravater, ALLCorALLD, Alternator, Alternator Hunter, AntiCycler, Anti Tit For Tat, Adaptive Pavlov 2006, Adaptive Pavlov 2011, Appeaser, Arrogant QLearner, Average Copier, Better and Better, BackStabber, Bully, Calculator, Cautious QLearner, Champion, CollectiveStrategy, Contrite Tit For Tat, Cooperator, Cooperator Hunter, Cycle Hunter, Cycler CCCCCD, Cycler CCCD, Cycler CCD, Cycler DC, Cycler DDC, Cycler CCCDCD, Davis, Defector, Defector Hunter, Desperate, DoubleCrosser, Doubler, EasyGo, Eatherley, Eventual Cycle Hunter, Evolved ANN, Evolved ANN 5, Evolved ANN 5 Noise 05, Evolved FSM 4, Evolved FSM 16, Evolved FSM 16 Noise 05, EvolvedLookerUp1_1_1, EvolvedLookerUp2_2_2, Evolved HMM 5, Feld, Firm But Fair, Fool Me Forever, Fool Me Once, Forgetful Fool Me Once, Forgetful Grudger, Forgiver, Forgiving Tit For Tat, Fortress3, Fortress4, GTFT: 0.33, Soft Go By Majority, Soft Go By Majority: 10, Soft Go By Majority: 20, Soft Go By Majority: 40, Soft Go By Majority: 5, $\phi$, Gradual, Gradual Killer, Grofman, Grudger, GrudgerAlternator, Grumpy, Handshake, Hard Go By Majority, Hard Go By Majority: 10, Hard Go By Majority: 20, Hard Go By Majority: 40, Hard Go By Majority: 5, Hard Prober, Hard Tit For 2 Tats, Hard Tit For Tat, Hesitant QLearner, Hopeless, Inverse, Inverse Punisher, Joss: 0.9, Knowledgeable Worse and Worse, Level Punisher, Limited Retaliate (0.1/20), Limited Retaliate (0.08/15), Limited Retaliate (0.05/20), Math Constant Hunter, Naive Prober: 0.1, MEM2, Negation, Nice Average Copier, Nydegger, Omega TFT, Once Bitten, Opposite Grudger, $\pi$, Predator, Prober, Prober 2, Prober 3, Prober 4, Pun1, PSO Gambler 1_1_1, PSO Gambler 2_2_2, PSO Gambler 2_2_2 Noise 05, PSO Gambler Mem1, Punisher, Raider, Random: 0.5, Random Hunter, Remorseful Prober: 0.1, Resurrection, Retaliate (0.1), Retaliate (0.08), Retaliate (0.05), Revised Downing, Ripoff, Risky QLearner, SelfSteem, ShortMem, Shubik, Slow Tit For Two Tats, Sneaky Tit For Tat, Soft Grudger, Soft Joss: 0.9, SolutionB1, SolutionB5, Spiteful Tit For Tat, Stalker, Stochastic Cooperator, Stochastic WSLS, Suspicious Tit For Tat, Tester, ThueMorse, ThueMorseInverse, Thumper, Tit For Tat, Tit For 2 Tats, Tricky Cooperator, Tricky Defector, Tullock, Two Tits For Tat, VeryBad, Willing, Winner12, Winner21, Win-Shift Lose-Stay, Win-Stay Lose-Shift, Worse and Worse, Worse and Worse 2, Worse and Worse 3, ZD-Extort-2, ZD-Extort-2 v2, ZD-Extort-4, ZD-GTFT-2, ZD-GEN-2, ZD-SET-2, $e$]
Meta Winner Memory One
Meta Winner Finite Memory
Meta Winner Long Memory
Meta Winner Stochastic
NMWE Deterministic
NMWE Finite Memory
NMWE Long Memory
NMWE Memory One
NMWE Stochastic
Nice Meta Winner: [Adaptive, Adaptive Tit For Tat: 0.5, Aggravater, ALLCorALLD, Alternator, Alternator Hunter, AntiCycler, Anti Tit For Tat, Adaptive Pavlov 2006, Adaptive Pavlov 2011, Appeaser, Arrogant QLearner, Average Copier, Better and Better, BackStabber, Bully, Calculator, Cautious QLearner, Champion, CollectiveStrategy, Contrite Tit For Tat, Cooperator, Cooperator Hunter, Cycle Hunter, Cycler CCCCCD, Cycler CCCD, Cycler CCD, Cycler DC, Cycler DDC, Cycler CCCDCD, Davis, Defector, Defector Hunter, Desperate, DoubleCrosser, Doubler, EasyGo, Eatherley, Eventual Cycle Hunter, Evolved ANN, Evolved ANN 5, Evolved ANN 5 Noise 05, Evolved FSM 4, Evolved FSM 16, Evolved FSM 16 Noise 05, EvolvedLookerUp1_1_1, EvolvedLookerUp2_2_2, Evolved HMM 5, Feld, Firm But Fair, Fool Me Forever, Fool Me Once, Forgetful Fool Me Once, Forgetful Grudger, Forgiver, Forgiving Tit For Tat, Fortress3, Fortress4, GTFT: 0.33, Soft Go By Majority, Soft Go By Majority: 10, Soft Go By Majority: 20, Soft Go By Majority: 40, Soft Go By Majority: 5, $\phi$, Gradual, Gradual Killer, Grofman, Grudger, GrudgerAlternator, Grumpy, Handshake, Hard Go By Majority, Hard Go By Majority: 10, Hard Go By Majority: 20, Hard Go By Majority: 40, Hard Go By Majority: 5, Hard Prober, Hard Tit For 2 Tats, Hard Tit For Tat, Hesitant QLearner, Hopeless, Inverse, Inverse Punisher, Joss: 0.9, Knowledgeable Worse and Worse, Level Punisher, Limited Retaliate (0.1/20), Limited Retaliate (0.08/15), Limited Retaliate (0.05/20), Math Constant Hunter, Naive Prober: 0.1, MEM2, Negation, Nice Average Copier, Nydegger, Omega TFT, Once Bitten, Opposite Grudger, $\pi$, Predator, Prober, Prober 2, Prober 3, Prober 4, Pun1, PSO Gambler 1_1_1, PSO Gambler 2_2_2, PSO Gambler 2_2_2 Noise 05, PSO Gambler Mem1, Punisher, Raider, Random: 0.5, Random Hunter, Remorseful Prober: 0.1, Resurrection, Retaliate (0.1), Retaliate (0.08), Retaliate (0.05), Revised Downing, Ripoff, Risky QLearner, SelfSteem, ShortMem, Shubik, Slow Tit For Two Tats, Sneaky Tit For Tat, Soft Grudger, Soft Joss: 0.9, SolutionB1, SolutionB5, Spiteful Tit For Tat, Stalker, Stochastic Cooperator, Stochastic WSLS, Suspicious Tit For Tat, Tester, ThueMorse, ThueMorseInverse, Thumper, Tit For Tat, Tit For 2 Tats, Tricky Cooperator, Tricky Defector, Tullock, Two Tits For Tat, VeryBad, Willing, Winner12, Winner21, Win-Shift Lose-Stay, Win-Stay Lose-Shift, Worse and Worse, Worse and Worse 2, Worse and Worse 3, ZD-Extort-2, ZD-Extort-2 v2, ZD-Extort-4, ZD-GTFT-2, ZD-GEN-2, ZD-SET-2, $e$]
Nice Meta Winner Ensemble: [Adaptive, Adaptive Tit For Tat: 0.5, Aggravater, ALLCorALLD, Alternator, Alternator Hunter, AntiCycler, Anti Tit For Tat, Adaptive Pavlov 2006, Adaptive Pavlov 2011, Appeaser, Arrogant QLearner, Average Copier, Better and Better, BackStabber, Bully, Calculator, Cautious QLearner, Champion, CollectiveStrategy, Contrite Tit For Tat, Cooperator, Cooperator Hunter, Cycle Hunter, Cycler CCCCCD, Cycler CCCD, Cycler CCD, Cycler DC, Cycler DDC, Cycler CCCDCD, Davis, Defector, Defector Hunter, Desperate, DoubleCrosser, Doubler, EasyGo, Eatherley, Eventual Cycle Hunter, Evolved ANN, Evolved ANN 5, Evolved ANN 5 Noise 05, Evolved FSM 4, Evolved FSM 16, Evolved FSM 16 Noise 05, EvolvedLookerUp1_1_1, EvolvedLookerUp2_2_2, Evolved HMM 5, Feld, Firm But Fair, Fool Me Forever, Fool Me Once, Forgetful Fool Me Once, Forgetful Grudger, Forgiver, Forgiving Tit For Tat, Fortress3, Fortress4, GTFT: 0.33, Soft Go By Majority, Soft Go By Majority: 10, Soft Go By Majority: 20, Soft Go By Majority: 40, Soft Go By Majority: 5, $\phi$, Gradual, Gradual Killer, Grofman, Grudger, GrudgerAlternator, Grumpy, Handshake, Hard Go By Majority, Hard Go By Majority: 10, Hard Go By Majority: 20, Hard Go By Majority: 40, Hard Go By Majority: 5, Hard Prober, Hard Tit For 2 Tats, Hard Tit For Tat, Hesitant QLearner, Hopeless, Inverse, Inverse Punisher, Joss: 0.9, Knowledgeable Worse and Worse, Level Punisher, Limited Retaliate (0.1/20), Limited Retaliate (0.08/15), Limited Retaliate (0.05/20), Math Constant Hunter, Naive Prober: 0.1, MEM2, Negation, Nice Average Copier, Nydegger, Omega TFT, Once Bitten, Opposite Grudger, $\pi$, Predator, Prober, Prober 2, Prober 3, Prober 4, Pun1, PSO Gambler 1_1_1, PSO Gambler 2_2_2, PSO Gambler 2_2_2 Noise 05, PSO Gambler Mem1, Punisher, Raider, Random: 0.5, Random Hunter, Remorseful Prober: 0.1, Resurrection, Retaliate (0.1), Retaliate (0.08), Retaliate (0.05), Revised Downing, Ripoff, Risky QLearner, SelfSteem, ShortMem, Shubik, Slow Tit For Two Tats, Sneaky Tit For Tat, Soft Grudger, Soft Joss: 0.9, SolutionB1, SolutionB5, Spiteful Tit For Tat, Stalker, Stochastic Cooperator, Stochastic WSLS, Suspicious Tit For Tat, Tester, ThueMorse, ThueMorseInverse, Thumper, Tit For Tat, Tit For 2 Tats, Tricky Cooperator, Tricky Defector, Tullock, Two Tits For Tat, VeryBad, Willing, Winner12, Winner21, Win-Shift Lose-Stay, Win-Stay Lose-Shift, Worse and Worse, Worse and Worse 2, Worse and Worse 3, ZD-Extort-2, ZD-Extort-2 v2, ZD-Extort-4, ZD-GTFT-2, ZD-GEN-2, ZD-SET-2, $e$]
So the Meta strategies have a way too long name, and some strategies (like HardGoByMajority10, WinShiftLoseStay or Feld) don't print their args correctly (must be a problem with the str cast of the parameters, I'll look into it).
That looks great. Perhaps for the meta strategies we could override the __repr__
to include the number of strategies in the team only?
So:
Nice Meta Winner: 9 players
Yes seems like a good solution.
I found the reasons for the bad display of some players with inspect :
For The GoByMajority, the first arg isn't displayed because memory_depth isn't an attr of the player directly but is in self.classifier
.
We could make the new __repr__
search inside self.classifier
as well as in attr to resolve GoByMajority or make that strategy override __repr__
. Using init_args, would also resolve that problem.
For MemoryOnePlayer the problem is that the parameters are called four_vector
and initial
while the player's attribute are called _four_vector
and _initial
.
This show another weakness of using inspect : it assume the parameters and attributes names are the same.
For Feld the problem is exactly the same.
We could search in self.__dict__
for eventual slight difference between parameter and attribute name but it doesn't seems ideal. Or we could say that as another constraint when coding a strategy, __init__
parameters must have the same name as the attribute they'll be given to. But this assume that all parameters will be given to an attribute.
So in conclusion I don't think inspect is a good idea because of those. init_args
would be ideal except for the default args problem which I don't know how to solve.
Another option could be to use inspect and override/rewrite __repr__
for the specific strategies that it does not work great for perhaps?
Yes maybe, still seems a little dirty to me that the new __repr__
would assume __init__
args have corresponding attribute, but as long as it's documented I guess it's okay.
Should I try to implement all that (inspect solution, override __repr__
for problematic strategies and the solution I suggested for StrategyTransformers) ? I'll probably need some help to update the writing_the_new_strategy
section in the docs to reflect the changes though, I'm not very good with those kind of things (and english isn't my first language).
Parameter
objects that inspect.signature
returns for __init__
, which also solves the default value issue -- there is an attribute that contains the default value. See the docs hereLimited Retaliate (0.1/20): 0.1, 20
to not repeat parameters after the change, same for CyclerYes after some reflexion, I don't know why I was set on using getattr when inspect has all that we need. There are several implementations possible, I'll think about them. And yes a lot of strategies will need some tweaks after that I expect.
:+1:
I've assigned this issue to you @Chadys :) :+1:
There are two related, but slightly different requirements here:
The __repr__
method
This needs access to the arguments that were passed to the __init__
method of an instance so that it can include them in the name.
The API
This needs access to the parameters of the the __init__
method so that they can be presented in the strategies endpoint.
At the moment, we have the init_kwargs
attribute of a Player
instance, which can be used for 1, but we would need a similar class attribute for 2.
Suggestion:
We create a class method init_params
which uses inspect.signature(cls.__init__)
to return the parameters of the __init__
method
We keep the existing instance attribute init_kwargs
which gives the arguments used to initialise a given Player instance
The __repr__
method uses both the above to generate a name - using init_kwargs
for actual arguments and init_params
for any default values
The alternative is that we write the same code in both __repr__
and within the API to derive the init_params using inspect.signature
For now I did that :
def __repr__(self):
"""The string method for the strategy."""
name = self.name
prefix = ': '
sig = inspect.signature(self.__init__)
for arg in self.init_args:
name += prefix + str(arg)
sig.parameters.popitem(last=False)
prefix = ', '
for p_name, p_value in sig.parameters.items():
value = self.init_kwargs.get(p_name, p_value.default)
if value is not None:
name += prefix + str(value if not isinstance(value, float) else round(value, 2))
prefix = ', '
return name
Which works, but I think that it would be better if that inspect
handywork was only done once. So yes I think I will go with the init_params
solution, which I've already started, even more if it is needed in the API.
But, with init_params
containing all the parameters with their corresponding values (be it default ones or not given the case), do we really still need init_args
and init_kwargs
? Could we not use init_params
for clone
, __repr__
and the API ?
But, with init_params containing all the parameters with their corresponding values (be it default ones or not given the case), do we really still need init_args and init_kwargs ? Could we not use init_params for clone, repr and the API ?
init_params
would be a class method, so it would not have the values.
I'm getting rid of init_args
at the moment on #945
init_params
would only contains the default values then ?
Ah sorry I read to quick since I was thinking about attribute not method. So init_kwargs
would contain the values like it does now and, if there is none, the default values.
So I've nearly finished, I still need to change the tests and I'll be done. For now what I get by calling __repr__
on all strategies is this :
Adaptive
Adaptive Tit For Tat: 0.5
Aggravater
ALLCorALLD
Alternator
Alternator Hunter
AntiCycler
Anti Tit For Tat
Adaptive Pavlov 2006
Adaptive Pavlov 2011
Appeaser
Arrogant QLearner
Average Copier
Better and Better
BackStabber
Bully
Calculator
Cautious QLearner
Champion
CollectiveStrategy
Contrite Tit For Tat
Cooperator
Cooperator Hunter
Cycle Hunter
Cycler CCCCCD: CCCCCD
Cycler CCCD: CCCD
Cycler CCD: CCD
Cycler DC: DC
Cycler DDC: DDC
Cycler CCCDCD: CCCDCD
Darwin
Davis: 10
Defector
Defector Hunter
Desperate
DoubleCrosser
Doubler
EasyGo
Eatherley
Eventual Cycle Hunter
Evolved ANN
Evolved ANN 5
Evolved ANN 5 Noise 05
Evolved FSM 4
Evolved FSM 16
Evolved FSM 16 Noise 05
EvolvedLookerUp1_1_1
EvolvedLookerUp2_2_2
Evolved HMM 5
Feld: 1.0, 0.5, 200
Firm But Fair
Fool Me Forever
Fool Me Once
Forgetful Fool Me Once: 0.05
Forgetful Grudger
Forgiver
Forgiving Tit For Tat
Fortress3
Fortress4
GTFT
Geller
Geller Cooperator
Geller Defector
Soft Go By Majority
Soft Go By Majority: 10
Soft Go By Majority: 20
Soft Go By Majority: 40
Soft Go By Majority: 5
$\phi$
Gradual
Gradual Killer
Grofman
Grudger
GrudgerAlternator
Grumpy: Nice, 10, -10
Handshake
Hard Go By Majority
Hard Go By Majority: 10
Hard Go By Majority: 20
Hard Go By Majority: 40
Hard Go By Majority: 5
Hard Prober
Hard Tit For 2 Tats
Hard Tit For Tat
Hesitant QLearner
Hopeless
Inverse
Inverse Punisher
Joss: 0.9
Knowledgeable Worse and Worse
Level Punisher
Limited Retaliate: 0.1, 20
Limited Retaliate 2: 0.08, 15
Limited Retaliate 3: 0.05, 20
Math Constant Hunter
Naive Prober: 0.1
MEM2
Mind Bender
Mind Controller
Mind Reader
Mind Warper
Mirror Mind Reader
Negation
Nice Average Copier
Nydegger
Omega TFT: 3, 8
Once Bitten
Opposite Grudger
$\pi$
Predator
Prober
Prober 2
Prober 3
Prober 4
Protected Mind Reader
Pun1
PSO Gambler 1_1_1
PSO Gambler 2_2_2
PSO Gambler 2_2_2 Noise 05
PSO Gambler Mem1
Punisher
Raider
Random: 0.5
Random Hunter
Remorseful Prober: 0.1
Resurrection
Retaliate: 0.1
Retaliate 2: 0.08
Retaliate 3: 0.05
Revised Downing: True
Ripoff
Risky QLearner
SelfSteem
ShortMem
Shubik
Slow Tit For Two Tats
Slow Tit For Two Tats 2
Sneaky Tit For Tat
Soft Grudger
Soft Joss: 0.9
SolutionB1
SolutionB5
Spiteful Tit For Tat
Stalker
Stochastic Cooperator
Stochastic WSLS: 0.05
Suspicious Tit For Tat
Tester
ThueMorse
ThueMorseInverse
Thumper
Tit For Tat
Tit For 2 Tats
Tricky Cooperator
Tricky Defector
Tullock: 11
Two Tits For Tat
VeryBad
Willing
Winner12
Winner21
Win-Shift Lose-Stay: D
Win-Stay Lose-Shift: C
Worse and Worse
Worse and Worse 2
Worse and Worse 3
ZD-Extort-2: 0.11, 0.5
ZD-Extort-2 v2: 0.12, 0.5, 1
ZD-Extort-4: 0.24, 0.25, 1
ZD-GTFT-2: 0.25, 0.5
ZD-GEN-2: 0.12, 0.5, 3
ZD-SET-2: 0.25, 0.0, 2
$e$
Meta Hunter: 6 players
Meta Hunter Aggressive: 7 players
Meta Majority: 163 players
Meta Majority Memory One: 31 players
Meta Majority Finite Memory: 75 players
Meta Majority Long Memory: 88 players
Meta Minority: 163 players
Meta Mixer: 163 players
Meta Winner: 163 players
Meta Winner Deterministic: 117 players
Meta Winner Ensemble: 163 players
Meta Winner Memory One: 31 players
Meta Winner Finite Memory: 75 players
Meta Winner Long Memory: 88 players
Meta Winner Stochastic: 46 players
NMWE Deterministic: 117 players
NMWE Finite Memory: 75 players
NMWE Long Memory: 88 players
NMWE Memory One: 31 players
NMWE Stochastic: 46 players
Nice Meta Winner: 163 players
Nice Meta Winner Ensemble: 163 players
Is it ok ? I know about the parameters repetition in Cycler
but it'll get resolved when I'll make the PR for #947
Looking good :) If you want to handle the cycler parameters in this PR go ahead, or maybe wait until after #946 (may cause some merge conflicts).
Nice, I'll change Cycler too then. But yes, I planned to wait for #946, too many conflicts otherwise
This has been closed by #953.
@meatballs if I understand correctly the init_params
method (https://github.com/Axelrod-Python/Axelrod/blob/master/axelrod/player.py#L95) is now good to go for the API :)
Yes, just call it without parameters and you'll have all default values !
As an example:
Should:
which currently gives:
give:
?