Skip to content

Commit 34b0d72

Browse files
committed
Update markov_chains_I.md
1 parent 120f41e commit 34b0d72

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

lectures/markov_chains_I.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ P = np.array([[0.971, 0.029, 0.000],
812812
P @ P
813813
```
814814

815-
Let's pick an initial distribution $\psi_0$ and trace out the sequence of distributions $\psi_0 P^t$ for $t = 0, 1, 2, \ldots$
815+
Let's pick an initial distribution $\psi_1, \psi_2, \psi_3$ and trace out the sequence of distributions $\psi_i P^t$ for $t = 0, 1, 2, \ldots$, for $i=1, 2, 3$.
816816

817817
First, we write a function to iterate the sequence of distributions for `ts_length` period
818818

@@ -829,26 +829,44 @@ def iterate_ψ(ψ_0, P, ts_length):
829829
Now we plot the sequence
830830

831831
```{code-cell} ipython3
832-
ψ_0 = (0.0, 0.2, 0.8) # Initial condition
832+
ψ_1 = (0.0, 0.0, 1.0)
833+
ψ_2 = (1.0, 0.0, 0.0)
834+
ψ_3 = (0.0, 1.0, 0.0) # Three initial conditions
835+
colors = ['blue','red', 'green'] # Different colors for each initial point
836+
837+
# Define the vertices of the unit simplex
838+
v = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 0]])
839+
840+
# Define the faces of the unit simplex
841+
faces = [
842+
[v[0], v[1], v[2]],
843+
[v[0], v[1], v[3]],
844+
[v[0], v[2], v[3]],
845+
[v[1], v[2], v[3]]
846+
]
833847
834848
fig = plt.figure()
835849
ax = fig.add_subplot(projection='3d')
836850
837-
def update(n):
838-
ψ_t = iterate_ψ(ψ_0, P, n+1)
839-
851+
def update(n):
840852
ax.clear()
841853
ax.set_xlim([0, 1])
842854
ax.set_ylim([0, 1])
843855
ax.set_zlim([0, 1])
844-
ax.view_init(30, 210)
856+
ax.view_init(45, 45)
845857
846-
for i, point in enumerate(ψ_t):
847-
ax.scatter(point[0], point[1], point[2], color='r', s=60, alpha=(i+1)/len(ψ_t))
858+
simplex = Poly3DCollection(faces, alpha=0.03)
859+
ax.add_collection3d(simplex)
848860
861+
for idx, ψ_0 in enumerate([ψ_1, ψ_2, ψ_3]):
862+
ψ_t = iterate_ψ(ψ_0, P, n+1)
863+
864+
for i, point in enumerate(ψ_t):
865+
ax.scatter(point[0], point[1], point[2], color=colors[idx], s=60, alpha=(i+1)/len(ψ_t))
866+
849867
mc = qe.MarkovChain(P)
850868
ψ_star = mc.stationary_distributions[0]
851-
ax.scatter(ψ_star[0], ψ_star[1], ψ_star[2], c='k', s=60)
869+
ax.scatter(ψ_star[0], ψ_star[1], ψ_star[2], c='yellow', s=60)
852870
853871
return fig,
854872
@@ -860,9 +878,9 @@ HTML(anim.to_jshtml())
860878
Here
861879

862880
* $P$ is the stochastic matrix for recession and growth {ref}`considered above <mc_eg2>`.
863-
* The highest red dot is an arbitrarily chosen initial marginal probability distribution $\psi_0$, represented as a vector in $\mathbb R^3$.
864-
* The other red dots are the marginal distributions $\psi_0 P^t$ for $t = 1, 2, \ldots$.
865-
* The black dot is $\psi^*$.
881+
* The red, blue and green dots are initial marginal probability distribution $\psi_1, \psi_2, \psi_3$, represented as a vector in $\mathbb R^3$.
882+
* The transparent dots are the marginal distributions $\psi_i P^t$ for $t = 1, 2, \ldots$, for $i=1,2,3.$.
883+
* The yellow dot is $\psi^*$.
866884

867885
You might like to try experimenting with different initial conditions.
868886

0 commit comments

Comments
 (0)