-
Notifications
You must be signed in to change notification settings - Fork 263
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
Meta Winner Ensemble #757
Meta Winner Ensemble #757
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from axelrod import Actions, Player, obey_axelrod | ||
from axelrod import Actions, Player, obey_axelrod, random_choice | ||
from ._strategies import all_strategies | ||
from .hunter import ( | ||
DefectorHunter, AlternatorHunter, RandomHunter, MathConstantHunter, | ||
|
@@ -165,6 +165,32 @@ def meta_strategy(self, results, opponent): | |
|
||
return bestresult | ||
|
||
class MetaWinnerEnsemble(MetaWinner): | ||
"""A variant of MetaWinner that chooses one of the top scoring strategies at random against each opponent.""" | ||
|
||
name = "Meta Winner Ensemble" | ||
|
||
def meta_strategy(self, results, opponent): | ||
# Sort by score | ||
scores = [(pl.score, i) for (i, pl) in enumerate(self.team)] | ||
# Choose one of the best scorers at random | ||
scores.sort(reverse=True) | ||
prop = max(1, int(len(scores) * 0.08)) | ||
index = choice([i for (s, i) in scores[:prop]]) | ||
|
||
# Update each player's proposed history with his proposed result, but | ||
# always after the new result has been settled based on scores | ||
# accumulated until now. | ||
for r, t in zip(results, self.team): | ||
t.proposed_history.append(r) | ||
|
||
if opponent.defections == 0: | ||
# Don't poke the bear | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😄 |
||
return C | ||
|
||
# return result | ||
return results[index] | ||
|
||
|
||
class MetaHunter(MetaPlayer): | ||
"""A player who uses a selection of hunters.""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,6 +185,27 @@ def test_strategy(self): | |
self.assertEqual(player.history[-1], D) | ||
|
||
|
||
class TestMetaWinnerEnsemble(TestMetaPlayer): | ||
name = "Meta Winner Ensemble" | ||
player = axelrod.MetaWinnerEnsemble | ||
expected_classifier = { | ||
'memory_depth': float('inf'), # Long memory | ||
'stochastic': True, | ||
'makes_use_of': set(['game']), | ||
'long_run_time': True, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
expected_class_classifier = copy.copy(expected_classifier) | ||
expected_class_classifier['stochastic'] = False | ||
expected_class_classifier['makes_use_of'] = set([]) | ||
|
||
def test_strategy(self): | ||
self.first_play_test(C) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test (for a given random seed) just for a few plays please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added two deterministic test cases. |
||
|
||
class TestMetaHunter(TestMetaPlayer): | ||
|
||
name = "Meta Hunter" | ||
|
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.
Could you add something like:
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.
done