-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_brownian_paths.py
More file actions
55 lines (44 loc) · 1.4 KB
/
plot_brownian_paths.py
File metadata and controls
55 lines (44 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Figure 6 & 7 from the thesis:
- Independent Brownian motion paths (Figure 6)
- Fine and coarse approximation of a Brownian path (Figure 7)
"""
import numpy as np
import matplotlib.pyplot as plt
from core import sim_brownian_motion
np.random.seed(42)
# --- Figure 6: Independent Brownian motions ---
T = 1.0
l = 10
M = 4
bm = sim_brownian_motion(T, l, M)
t = np.linspace(0, T, 2**l + 1)
fig1, ax1 = plt.subplots(figsize=(8, 5))
for m in range(M):
ax1.plot(t, bm[:, m])
ax1.set_xlabel('t')
ax1.set_ylabel(r'$W(t)$')
ax1.set_title('Independent Brownian motions')
fig1.tight_layout()
fig1.savefig('plot_independent_bm.png', dpi=150)
print("Saved: plot_independent_bm.png")
# --- Figure 7: Fine and coarse approximation ---
bm_single = sim_brownian_motion(T, l, 1)
t_fine = np.linspace(0, T, 2**l + 1)
fig2, ax2 = plt.subplots(figsize=(8, 5))
# Fine path (l=10)
ax2.plot(t_fine, bm_single[:, 0], label=f'l = {l}', linewidth=0.5)
# Coarse paths
for lc, color in [(4, 'tab:orange'), (3, 'tab:olive')]:
step = 2**(l - lc)
t_coarse = t_fine[::step]
bm_coarse = bm_single[::step, 0]
ax2.plot(t_coarse, bm_coarse, label=f'l = {lc}', linewidth=1.5)
ax2.set_xlabel('t')
ax2.set_ylabel(r'$\hat{W}^{(2^l)}(t)$')
ax2.legend()
ax2.set_title('Fine and coarse approximation of a Brownian path')
fig2.tight_layout()
fig2.savefig('plot_fine_coarse_bm.png', dpi=150)
print("Saved: plot_fine_coarse_bm.png")
plt.show()