Skip to content

Commit 1b916e8

Browse files
committed
Add code for the plot in double q learning problem.
1 parent 5be96fe commit 1b916e8

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

.DS_Store

6 KB
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
Nmax = 1_000_000
5+
R = 100 # number of Monte Carlo trials (tune)
6+
7+
sum_running_max = np.zeros(Nmax, dtype=np.float64)
8+
9+
rng = np.random.default_rng(0)
10+
for r in range(R):
11+
eps = rng.standard_normal(Nmax) # N(0,1)
12+
runmax = np.maximum.accumulate(eps) # runmax[n-1] = max_{i<=n} eps[i]
13+
sum_running_max += runmax
14+
15+
fhat = 1.0 + (sum_running_max / R)
16+
ghat = np.ones(Nmax) # exactly g(n)=1, but included for plotting
17+
18+
n = np.arange(1, Nmax + 1)
19+
20+
plt.figure()
21+
plt.semilogx(n, fhat, label="Monte Carlo f(n)=E[max X]")
22+
plt.semilogx(n, ghat, label="g(n)=max E[X]=1")
23+
plt.xlabel("n (log scale)")
24+
plt.ylabel("value")
25+
plt.legend()
26+
plt.grid(True, which="both", linestyle="--", linewidth=0.5)
27+
plt.show()

0 commit comments

Comments
 (0)