prob140.MarkovChain.from_transition_function¶
-
classmethod
MarkovChain.
from_transition_function
(states, transition_function)[source]¶ Constructs a MarkovChain from a transition function.
Parameters: - states : iterable
List of states.
- transition_function : function
Bivariate transition function that maps two states to a probability.
Returns: - MarkovChain
Examples
>>> states = make_array(1, 2) >>> def transition(s1, s2): ... if s1 == s2: ... return 0.7 ... else: ... return 0.3 >>> MarkovChain.from_transition_function(states, transition) 1 2 1 0.7 0.3 2 0.3 0.7