@@ -1126,22 +1126,25 @@ The following figure shows the dynamics of $(\psi P^t)(i)$ as $t$ gets large, f
11261126First, we write a function to draw ` n ` initial values
11271127
11281128``` {code-cell} ipython3
1129- def generate_initial_values(ts_length , n):
1129+ def generate_initial_values(num_distributions , n):
11301130 n = len(P)
1131- ψ_0s = np.empty((ts_length , n))
1131+ ψ_0s = np.empty((num_distributions , n))
11321132
1133- for t in range(ts_length ):
1133+ for i in range(num_distributions ):
11341134 draws = np.random.randint(1, 10_000_000, size=n)
11351135
11361136 # Scale them so that they add up into 1
1137- ψ_0s[t ,:] = np.array(draws/sum(draws))
1137+ ψ_0s[i ,:] = np.array(draws/sum(draws))
11381138
11391139 return ψ_0s
11401140```
11411141
11421142``` {code-cell} ipython3
1143- # Define the number of iterations
1143+ # Define the number of iterations
1144+ # and number of initial distributions
11441145ts_length = 50
1146+ num_distributions = 25
1147+
11451148n = len(P)
11461149mc = qe.MarkovChain(P)
11471150ψ_star = mc.stationary_distributions[0]
@@ -1150,8 +1153,7 @@ mc = qe.MarkovChain(P)
11501153fig, axes = plt.subplots(nrows=1, ncols=n)
11511154plt.subplots_adjust(wspace=0.35)
11521155
1153- ψ_0s = generate_initial_values(ts_length, n)
1154-
1156+ ψ_0s = generate_initial_values(num_distributions, n)
11551157for ψ_0 in ψ_0s:
11561158 ψs = iterate_ψ(ψ_0, P, ts_length)
11571159
@@ -1181,14 +1183,15 @@ In the case of our periodic chain, we find the distribution is oscillating
11811183``` {code-cell} ipython3
11821184P = np.array([[0, 1],
11831185 [1, 0]])
1186+
11841187ts_length = 50
1188+ num_distributions = 25
11851189n = len(P)
11861190mc = qe.MarkovChain(P)
11871191ψ_star = mc.stationary_distributions[0]
11881192fig, axes = plt.subplots(nrows=1, ncols=n)
11891193
1190- ψ_0s = generate_initial_values(ts_length, n)
1191-
1194+ ψ_0s = generate_initial_values(num_distributions, n)
11921195for ψ_0 in ψ_0s:
11931196 ψs = iterate_ψ(ψ_0, P, ts_length)
11941197
@@ -1550,9 +1553,7 @@ power $P^k$ for all $k \in \mathbb N$.
15501553
15511554
15521555``` {solution-start} mc_ex_pk
1553- :class: dropdown
15541556```
1555-
15561557Suppose that $P$ is stochastic and, moreover, that $P^k$ is
15571558stochastic for some integer $k$.
15581559
0 commit comments