-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_smoothing.py
More file actions
60 lines (46 loc) · 1.9 KB
/
plot_smoothing.py
File metadata and controls
60 lines (46 loc) · 1.9 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
56
57
58
59
60
"""
Figures 2 & 3 from the thesis:
- Smoothing of the indicator function for different r (Figure 2)
- Smoothing of the indicator function for different delta (Figure 3)
"""
import numpy as np
import matplotlib.pyplot as plt
from core import construct_smoothing_polynomial, smoothing_function
# --- Figure 2: Different r values, fixed delta = 0.5 ---
h = 0.001
T_vals = np.arange(3.5, 4.5 + h, h)
s0 = 4.0
delta = 0.5
fig1, ax1 = plt.subplots(figsize=(8, 5))
for r, color in [(20, 'red'), (10, 'blue'), (5, 'green')]:
coeffs = construct_smoothing_polynomial(r)
y = smoothing_function(T_vals, s0, delta, coeffs)
ax1.plot(T_vals, y, color=color, label=f'r = {r}')
# Indicator function
ax1.plot(T_vals[T_vals <= 4.0], np.ones(np.sum(T_vals <= 4.0)), 'k', linewidth=1.5)
ax1.plot(T_vals[T_vals >= 4.0], np.zeros(np.sum(T_vals >= 4.0)), 'k', linewidth=1.5,
label=r'$\mathbb{1}_{(-\infty, 4]}$')
ax1.set_ylim(-0.2, 1.2)
ax1.legend()
ax1.set_title(r'Smoothing of the indicator function for different $r$')
fig1.tight_layout()
fig1.savefig('plot_smoothing_r.png', dpi=150)
print("Saved: plot_smoothing_r.png")
# --- Figure 3: Different delta values, fixed r = 20 ---
r = 20
coeffs = construct_smoothing_polynomial(r)
fig2, ax2 = plt.subplots(figsize=(8, 5))
for delta_val, color in [(0.1, 'red'), (0.5, 'blue')]:
y = smoothing_function(T_vals, s0, delta_val, coeffs)
ax2.plot(T_vals, y, color=color, label=rf'$\delta = {delta_val}$')
# Indicator function
ax2.plot(T_vals[T_vals <= 4.0], np.ones(np.sum(T_vals <= 4.0)), 'k', linewidth=1.5)
ax2.plot(T_vals[T_vals >= 4.0], np.zeros(np.sum(T_vals >= 4.0)), 'k', linewidth=1.5,
label=r'$\mathbb{1}_{(-\infty, 4]}$')
ax2.set_ylim(-0.2, 1.2)
ax2.legend()
ax2.set_title(r'Smoothing of the indicator function for different $\delta$')
fig2.tight_layout()
fig2.savefig('plot_smoothing_delta.png', dpi=150)
print("Saved: plot_smoothing_delta.png")
plt.show()