-
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
Add state to action analysis. #870
Conversation
Add two functions to interaction_utils: - `interaction_utils.compute_state_to_action_distribution`: computes list of counter objects of mapping a `(state, action)` to a count. - `interaction_utils.compute_normalised_state_to_action_distribution`: computes list of counter objects of mapping a `(state, action)` to a normalised count (for a given state). There have then been incorporated in `axelrod.result_set` and in particular in the `result_set.summarise()` output. Which now includes the average rates for each strategy in a tournament. So for memory 1 strategies this means we can measure their parameters and for non memory 1 strategies we can infer what the parameters correspond to the data.
axelrod/interaction_utils.py
Outdated
def compute_state_to_action_distribution(interactions): | ||
""" | ||
Returns the count of each state to action | ||
for a set of interactions. |
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 needs a little more explanation as to what the function does. It wasn't clear to me until I looked at how it's being used in the result set. Perhaps an example would be useful?
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.
Yeah good shout. I'll clear that up and find the others. I think I got lazy :)
axelrod/interaction_utils.py
Outdated
""" | ||
Returns the normalised count of each state to action | ||
for a set of interactions. | ||
|
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.
Same here. A little more explanation of what this is doing might be in order.
Let me know if you think it needs more than those last two commits :) Just jumping in the plane, will pick this up later :D |
axelrod/interaction_utils.py
Outdated
Implying that from a state of (C, D) (the first player having played C and | ||
the second playing D) the player in question then played C. | ||
|
||
The following counter object, implies that the player in question was in |
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.
Pedantic: "The following Counter object implies that"
axelrod/interaction_utils.py
Outdated
return None | ||
|
||
distributions = [Counter([(state, outcome[j]) for state, outcome in zip(interactions, | ||
interactions[1:])]) |
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.
Can we make the spacing here more aesthetically pleasing?
axelrod/interaction_utils.py
Outdated
|
||
((C, D), C) | ||
|
||
Implying that from a state of (C, D) (the first player having played C and |
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.
Pedantic: lowercase "impying"
axelrod/interaction_utils.py
Outdated
Implying that from a state of (C, D) (the first player having played C and | ||
the second playing D) the player in question then played C. | ||
|
||
The following counter object, implies that the player in question was only |
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.
formatting
axelrod/interaction_utils.py
Outdated
---------- | ||
normalised_state_to_C_distributions : List of Counter Object | ||
List of Counter objects where the keys are the states and actions and | ||
the values the normalized counts.. The |
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.
double period
axelrod/interaction_utils.py
Outdated
normalized_distribution = [] | ||
for player in range(2): | ||
counter = {} | ||
for state in [('C', 'C'), ('C', 'D'), ('D', 'C'), ('D', 'D')]: |
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.
C
, D
as in Actions.C
, Actions.D
rather than 'C'
and 'D'
axelrod/result_set.py
Outdated
""" | ||
Returns | ||
---------- | ||
|
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.
return var name / spacing
norm_counter = Counter() | ||
for state in [(C, C), (C, D), (D, C), (D, D)]: | ||
total = counter[(state, C)] + counter[(state, D)] | ||
if total > 0: |
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.
if total == 0
then we add nothing to the list? just checking that is the intention rather than None or an empty dict.
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.
If total == 0
we still add the empty norm_counter
so the behaviour is consistant :)
The test cases catch this occurrence :)
@@ -22,11 +22,27 @@ class TestMatch(unittest.TestCase): | |||
Counter({('D', 'C'): 2}), | |||
Counter({('C', 'C'): 1, ('C', 'D'): 1}), | |||
None] | |||
state_to_action_distribution = [[Counter({(('C', 'D'), 'D'): 1}), |
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.
Can we use C
and D
instead of 'C'
and 'D'
?
self.state_to_action_distribution): | ||
self.assertEqual(dist, | ||
iu.compute_state_to_action_distribution(inter)) | ||
inter = [(C, D), (D, C), (C, D), (D, C), (D, D), (C, C), (C, D)] |
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.
mixing C
and 'C'
Looks fine overall, I added some minor comments about docstrings and |
- 'C'/'D' -> C/D - Adding type docstrings.
I think I've caught all of them and answered your question above, happy to further improve it though if you think of anything else :) 👍 |
Add two functions to interaction_utils:
interaction_utils.compute_state_to_action_distribution
: computeslist of counter objects of mapping a
(state, action)
to a count.interaction_utils.compute_normalised_state_to_action_distribution
: computeslist of counter objects of mapping a
(state, action)
to a normalisedcount (for a given state).
There have then been incorporated in
axelrod.result_set
and in particular inthe
result_set.summarise()
output. Which now includes the averagerates for each strategy in a tournament. So for memory 1 strategies this
means we can measure their parameters and for non memory 1 strategies we
can infer what the parameters correspond to the data.