-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SteinAndRapoport Strategy #1012
Conversation
This is looking ready to take a look at, let's get the tests running first of all :) This file: https://github.com/Axelrod-Python/Axelrod/blob/master/requirements.txt contains the list of all libraries needed by the library, with your contribution we need to add
At present the tests are not even running on the continuous integration server because it cannot import the library as we haven't told it to install |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking solid to me @MariosZoulias, once the test and coverage reports run there might be a few other things that come up.
Can you also modify https://github.com/Axelrod-Python/Axelrod/blob/master/docs/reference/overview_of_strategies.rst, that's the file that generates: http://axelrod.readthedocs.io/en/stable/reference/overview_of_strategies.html?highlight=Stein and we will need to modify the table to say the SteinAndRapoport is now implemented.
axelrod/strategies/_strategies.py
Outdated
@@ -72,6 +72,7 @@ | |||
from .selfsteem import SelfSteem | |||
from .shortmem import ShortMem | |||
from .stalker import Stalker | |||
from .axelrod_first import SteinAndRapoport |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 7,8,9 of this file look like:
7 from .axelrod_first import (
8 Davis, RevisedDowning, Feld, Grofman, Nydegger, Joss, Shubik, Tullock,
9 UnnamedStrategy)
So you can remove this line and just add SteinAndRapoport
to the list imported there.
axelrod/strategies/axelrod_first.py
Outdated
self.alpha = 0.05 | ||
|
||
def strategy(self , opponent: Player , chi_tests = [0]) -> Action: | ||
# chi-tests == 0 then we play TitForTat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remove this inline comment.
axelrod/strategies/axelrod_first.py
Outdated
if round_number < 16 : | ||
if opponent.history[-1] == 'D' : | ||
return D | ||
else : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else :
should be else:
axelrod/strategies/axelrod_first.py
Outdated
return C | ||
|
||
# For first 15 rounds tit for tat as we dont know opponents strategy | ||
if round_number < 16 : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
round_number < 16 :
should be round_number < 16:
axelrod/strategies/axelrod_first.py
Outdated
round_number = len(self.history) + 1 | ||
|
||
# First 4 moves | ||
if round_number < 5 : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
round_number < 5 :
should be round_number < 5:
(no space between 5
and :
)
|
||
@FinalTransformer((D, D), name_prefix=None) | ||
class SteinAndRapoport(Player): | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite formatted correctly (see: http://axelrod.readthedocs.io/en/stable/tutorials/contributing/strategy/docstrings.html).
Can you remove one indentation level for the description (it should be at the same level as the """
).
Then can you add:
Names:
- SteinAndRapoport [Axelrod1980]_
Hello i made the changes ;) Forget it i think i just did it ;) |
I've closed #1014 as it would be better if that came as part of this PR. The file you need to modify is part of the repository so it is on your computer: open |
axelrod/strategies/axelrod_first.py
Outdated
|
||
@FinalTransformer((D, D), name_prefix=None) | ||
class SteinAndRapoport(Player): | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not indented on the correct level. It should look like:
class SteinAndRapoport(Player):
```
A player who plays...
...
```
Ok great, there are some failing tests but nothing we can't work through. To get us started, in
I'm not around today but I'll look through everything else properly tomorrow. |
@MariosZoulias I've looked through this carefully and you've done a great job! It isn't completely correct though, instead of making multiple comments on the way I have made the changes and opened a Pull Request to your branch: MariosZoulias#1 If you merge that (on github by clicking on "Merge pull request") then that will automatically add my changes to here. Let me know if you have any questions. |
A small side note: your last two commit messages were "More changes" and "More and More changes" on http://axelrod.readthedocs.io/en/stable/tutorials/contributing/guidelines.html we briefly mention some guidelines about commit messages. It is good practice to write informative messages: this blog post https://chris.beams.io/posts/git-commit/ is quite a good description of what is meant by that :) I'm not asking you to change anything about your previous commit messages just letting you know what's considered good practice :) |
This is due to an error that was occurring with scipy. The solution is to use a conda environment as described in http://tjelvarolsson.com/blog/how-to-continuously-test-your-python-code-on-windows-using-appveyor/
The strategy wasn't quite correct: it would in fact not remember the result of the chisquared test from one call to another. I've fixed that here. I've also included a few more tests including a test that the chi squared test gets run again and that it can change it's mind.
Correct strategy and add relevant tests.
Hello . |
Cool, it was a good attempt but that wasn't working as you'd hoped. As you had implemented it, that list was an internal variable for your method, and everytime the function was being called it was called with a new default version of that list: def strategy(self , opponent: Player , chi_tests = [0]) -> Action: So that list was never actually growing. Similarly we only ever cared about the last element of the list so that might as well be a simple boolean attribute and calling that variable You were only testing the exact play on the 15th round, and not the rounds thereafter which is why this slipped through. I added that last test which checks that the player defects for 15 rounds following the first test and then also that it tests again at round 30. Let me know if you have any other questions. I think we're really close to this being ready but as I PR'd (9c03615) a few changes I'll leave the merging decisions up to @marcharper and @meatballs (when they have time). They might have further requests. Marc and Owen: one of the commits in this PR is 5a6cc56 which is due to appveyor having issues with the |
@@ -241,7 +241,8 @@ def clone(self): | |||
return new_player | |||
|
|||
def reset(self): | |||
"""Resets history. | |||
""" | |||
Resets history. | |||
When creating strategies that create new attributes then this method | |||
should be re-written (in the inherited class) and should not only reset | |||
history but also rest all other attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a little clumsy and not as clear as it could be. How about:
"""Resets a player to its initial state
This method is called at the beginning of each match (between a pair of players) to reset a player's state to its initial starting point. It ensures that no 'memory' of previous matches is carried forward.
The default method resets a player's history, cooperations, defections and state_distribution. Players which have further attributes need to override this method and ensure those additional attributes are also reset.
"""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @MariosZoulias, this has turned up in this PR because I put a line break on line 244 (I shouldn't have done that), the text wasn't changed by either of us but if you could make the improvements suggested by @meatballs that would be helpful. This file is in Axelrod/axelrod/player.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's sort this out separately. I'll merge this PR and put another one in for the docstring
Thanks for the merge @meatballs and thanks for the work on this @MariosZoulias 👍 I'll create a new release when I get a moment, this is a nice strategy to finally have added to the library. |
#379
New Strategy to be implemented
Please tell e also how to fix the test problem ;)
Thank you