-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Added Markov Chain #2146
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
Added Markov Chain #2146
Conversation
other/markov_chain.py
Outdated
self.connections[node1][node2] = probability | ||
|
||
def get_nodes(self) -> List[str]: | ||
return list(self.connections.keys()) |
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 list(self.connections.keys()) | |
return list(self.connections) |
.keys() is almost never needed in modern Python.
other/markov_chain.py
Outdated
|
||
>>> result = get_transitions('a', transitions, 5000) | ||
|
||
>>> assert result['a'] > result['b'] > result['c'] |
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.
>>> assert result['a'] > result['b'] > result['c'] | |
>>> result['a'] > result['b'] > result['c'] | |
True |
other/markov_chain.py
Outdated
for node1, node2, probability in transitions: | ||
graph.add_transition_probability(node1, node2, probability) | ||
|
||
visited = {node: 0 for node in graph.get_nodes()} |
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.
visited = {node: 0 for node in graph.get_nodes()} | |
visited = collections.Counter() |
(import collections at top of file)
https://docs.python.org/3/library/collections.html#collections.Counter
* Added Markov Chain * Implemented suggestions
Describe your change:
Checklist: