We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7972926 commit b5d37efCopy full SHA for b5d37ef
graph/markov_chain.py
@@ -0,0 +1,21 @@
1
+import random
2
+
3
+my_chain = {
4
+ 'A': {'A': 0.6,
5
+ 'E': 0.4},
6
+ 'E': {'A': 0.7,
7
+ 'E': 0.3}
8
+}
9
10
+def __choose_state(state_map):
11
+ choice = random.random()
12
+ probability_reached = 0
13
+ for state, probability in state_map.items():
14
+ probability_reached += probability
15
+ if probability_reached > choice:
16
+ return state
17
18
+def next_state(chain, current_state):
19
+ next_state_map = chain.get(current_state)
20
+ next_state = __choose_state(next_state_map)
21
+ return next_state
0 commit comments