prob140.MarkovChain.prob_of_path¶
-
MarkovChain.
prob_of_path
(starting_condition, path)[source]¶ Finds the probability of a path given a starting condition.
Parameters: - starting_condition : state or Distribution
If a state, finds the probability of the path starting at that state. If a Distribution, finds the probability of the path with the first element sampled from the Distribution.
- path : ndarray
Array of states
Returns: - float
probability
Examples
>>> states = ['A', 'B'] >>> transition_matrix = np.array([[0.1, 0.9], ... [0.8, 0.2]]) >>> mc = MarkovChain.from_matrix(states, transition_matrix) >>> mc.prob_of_path('A', ['A', 'B', 'A']) 0.072 >>> 0.1 * 0.9 * 0.8 0.072 >>> start = Table().states(['A', 'B']).probability([0.8, 0.2]) >>> mc.prob_of_path(start, ['A', 'B', 'A']) 0.576 >>> 0.8 * 0.9 * 0.8 0.576