-
Notifications
You must be signed in to change notification settings - Fork 273
Add state to action analysis. #870
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Can we use |
||
Counter({(('C', 'D'), 'C'): 1})], | ||
[Counter({(('D', 'C'), 'D'): 1}), | ||
Counter({(('D', 'C'), 'C'): 1})], | ||
[Counter({(('C', 'C'), 'C'): 1}), | ||
Counter({(('C', 'C'), 'D'): 1})], | ||
None] | ||
|
||
normalised_state_distribution = [ | ||
Counter({('C', 'D'): 0.5, ('D', 'C'): 0.5}), | ||
Counter({('D', 'C'): 1.0}), | ||
Counter({('C', 'C'): 0.5, ('C', 'D'): 0.5}), | ||
None] | ||
normalised_state_to_action_distribution = [[Counter({(('C', 'D'), 'D'): 1}), | ||
Counter({(('C', 'D'), 'C'): 1})], | ||
[Counter({(('D', 'C'), 'D'): 1}), | ||
Counter({(('D', 'C'), 'C'): 1})], | ||
[Counter({(('C', 'C'), 'C'): 1}), | ||
Counter({(('C', 'C'), 'D'): 1})], | ||
None] | ||
|
||
sparklines = [ '█ \n █', ' \n██', '██\n█ ', None ] | ||
|
||
def test_compute_scores(self): | ||
|
@@ -63,6 +79,37 @@ def test_compute_normalised_state_distribution(self): | |
for inter, dist in zip(self.interactions, self.normalised_state_distribution): | ||
self.assertEqual(dist, iu.compute_normalised_state_distribution(inter)) | ||
|
||
def test_compute_state_to_action_distribution(self): | ||
for inter, dist in zip(self.interactions, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. mixing |
||
expected_dist =[Counter({(('C', 'C'), 'C'): 1, (('D', 'C'), 'C'): 1, | ||
(('C', 'D'), 'D'): 2, (('D', 'C'), 'D'): 1, | ||
(('D', 'D'), 'C'): 1}), | ||
Counter({(('C', 'C'), 'D'): 1, | ||
(('C', 'D'), 'C'): 2, (('D', 'C'), 'D'): 2, | ||
(('D', 'D'), 'C'): 1})] | ||
|
||
self.assertEqual(expected_dist, | ||
iu.compute_state_to_action_distribution(inter)) | ||
|
||
def test_compute_normalised_state_to_action_distribution(self): | ||
for inter, dist in zip(self.interactions, | ||
self.normalised_state_to_action_distribution): | ||
self.assertEqual(dist, | ||
iu.compute_normalised_state_to_action_distribution(inter)) | ||
inter = [(C, D), (D, C), (C, D), (D, C), (D, D), (C, C), (C, D)] | ||
expected_dist =[Counter({(('C', 'C'), 'C'): 1, (('D', 'C'), 'C'): 1 / 2, | ||
(('C', 'D'), 'D'): 1, (('D', 'C'), 'D'): 1 / 2, | ||
(('D', 'D'), 'C'): 1}), | ||
Counter({(('C', 'C'), 'D'): 1, | ||
(('C', 'D'), 'C'): 1, (('D', 'C'), 'D'): 1, | ||
(('D', 'D'), 'C'): 1})] | ||
self.assertEqual(expected_dist, | ||
iu.compute_normalised_state_to_action_distribution(inter)) | ||
|
||
def test_compute_sparklines(self): | ||
for inter, spark in zip(self.interactions, self.sparklines): | ||
self.assertEqual(spark, iu.compute_sparklines(inter)) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 emptynorm_counter
so the behaviour is consistant :)The test cases catch this occurrence :)