SciPy

prob140.MarkovChain.log_prob_of_path

MarkovChain.log_prob_of_path(starting_condition, path)[source]

Finds the log-probability of a path given a starting condition.

May have better precision than prob_of_path.

Parameters:
starting_condition : state or Distribution

If a state, finds the log-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

log of probability

Examples

>>> states = make_array('A', 'B')
>>> transition_matrix = np.array([[0.1, 0.9],
...                               [0.8, 0.2]])
>>> mc = MarkovChain.from_matrix(states, transition_matrix)
>>> mc.log_prob_of_path('A', ['A', 'B', 'A'])
-2.6310891599660815
>>> start = Table().states(['A', 'B']).probability([0.8, 0.2])
>>> mc.log_prob_of_path(start, ['A', 'B', 'A'])
-0.55164761828624576