Example 5.4#

Simulation of a continuous-space Markov chain.

import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(15)

# Note our system x_n = a x_{n-1} + noise
T = 1000
x = np.zeros(T)

x[0] = 100
a = 0.9

for t in range(1,T):
    x[t] = a * x[t-1] + rng.normal(0,1)

plt.plot(x)
plt.show()
../_images/30f62f499f6cc96d3479f664dd566472cc5c9f5553278a5310bf5a2c14d8c2bf.png

We can see that the chain starts from \(x_0 = 100\) but converges to its stationary measure. For some values \(a\), this may not hold. See the example below with \(a = 1\).

import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(15)

# Note our system x_n = a x_{n-1} + noise
T = 100000
x = np.zeros(T)

x[0] = 100
a = 1

for t in range(1,T):
    x[t] = a * x[t-1] + rng.normal(0,1)

plt.plot(x)
plt.show()
../_images/393925c157fef112ec88cb3b3fb41d3b3111ebca605b5cb680e03bbc91fba91b.png

This chain will not converge anywhere.