Skip to content

Commit 89084e8

Browse files
committed
update based on feedback on num_distributions
1 parent 5dd46be commit 89084e8

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lectures/markov_chains.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,22 +1126,25 @@ The following figure shows the dynamics of $(\psi P^t)(i)$ as $t$ gets large, f
11261126
First, 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
11441145
ts_length = 50
1146+
num_distributions = 25
1147+
11451148
n = len(P)
11461149
mc = qe.MarkovChain(P)
11471150
ψ_star = mc.stationary_distributions[0]
@@ -1150,8 +1153,7 @@ mc = qe.MarkovChain(P)
11501153
fig, axes = plt.subplots(nrows=1, ncols=n)
11511154
plt.subplots_adjust(wspace=0.35)
11521155
1153-
ψ_0s = generate_initial_values(ts_length, n)
1154-
1156+
ψ_0s = generate_initial_values(num_distributions, n)
11551157
for ψ_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
11821184
P = np.array([[0, 1],
11831185
[1, 0]])
1186+
11841187
ts_length = 50
1188+
num_distributions = 25
11851189
n = len(P)
11861190
mc = qe.MarkovChain(P)
11871191
ψ_star = mc.stationary_distributions[0]
11881192
fig, 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)
11921195
for ψ_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-
15561557
Suppose that $P$ is stochastic and, moreover, that $P^k$ is
15571558
stochastic for some integer $k$.
15581559

0 commit comments

Comments
 (0)