prob140.MarkovChain.simulate_path¶
-
MarkovChain.
simulate_path
(starting_condition, steps, plot_path=False)[source]¶ Simulates a path of n steps with a specific starting condition.
Parameters: - starting_condition : state or Distribution
If a state, simulates n steps starting at that state. If a Distribution, samples from that distribution to find the starting state.
- steps : int
Number of steps to take.
- plot_path : bool
If True, plots the simulated path.
Returns: - ndarray
Array of sampled states.
Examples
>>> states = ['A', 'B'] >>> transition_matrix = np.array([[0.1, 0.9], ... [0.8, 0.2]]) >>> mc = MarkovChain.from_matrix(states, transition_matrix) >>> mc.simulate_path('A', 10) array(['A', 'A', 'B', 'A', 'B', 'A', 'B', 'B', 'A', 'B', 'B'])