Differences between this lecture and the previous lecture.
- Previously, the sampling focused on the approximation of a probabilistic distribution.
- This time, the sampling is about the infilling of a space.
What we want:
It generates quasirandom numbers
Nonrandom (e.g. Full Factorial Design)
np.random.seed(1) # Pseudorandom
np.random.rand() # Always 0.417022004702574
0.417022004702574
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.01, 0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81, 0.91, 0.02, 0.12, 0.22, 0.32, ...
Over a unit square:
s = runDisc(Grid, 2500, 21, 1) # Deterministic, so running only once
pltDisc(s, 21)
Mean: 1.890e-02, Std: 0.000e+00
s = runDisc(URand, 2500, 21, 10)
pltDisc(s, 21)
Mean: 1.894e-02, Std: 5.344e-03
s = runDisc(LHS, 2500, 21, 10)
pltDisc(s, 21)
Mean: 9.690e-03, Std: 1.947e-03
s = runDisc(Halton, 2500, 21, 1) # Deterministic, so running only once
pltDisc(s, 21)
Mean: 2.000e-03, Std: 0.000e+00
s = runDisc(Hmsl, 2500, 21, 1) # Deterministic, so running only once
pltDisc(s, 21)
Mean: 1.200e-03, Std: 0.000e+00
s = runDisc(lambda N: Sobol(N,sk=10), 2500, 21, 1) # Deterministic, so running only once
pltDisc(s, 21)
Mean: 1.200e-03, Std: 0.000e+00
Leads to quasi Monte Carlo:
lbls = ['URand', 'LHS', 'Halton', 'Sobol']
stys = ['r-', 'b-', 'g-', 'm-']
Ns = np.arange(11.0,N+1.0)
f = plt.figure(figsize=(6,4))
for _i in range(4):
plt.loglog(Ns, R[_i], stys[_i], label=lbls[_i])
plt.loglog(Ns, 1/np.sqrt(Ns), 'k--', linewidth=2, label='N^1/2/N')
plt.loglog(Ns, 0.01*np.log(Ns)**2/Ns, 'r--', linewidth=2, label='logN^2/N')
plt.ylabel('Error')
plt.xlabel('No. of samples')
_=plt.legend()