Compare GPs + Plot¶
In [65]:
Copied!
import fastgps
import qmcpy as qp
import numpy as np
import torch
import pandas as pd
import itertools
from matplotlib import pyplot
import tueplots.figsizes
import fastgps
import qmcpy as qp
import numpy as np
import torch
import pandas as pd
import itertools
from matplotlib import pyplot
import tueplots.figsizes
In [66]:
Copied!
device = "cpu"
if device!="mps":
torch.set_default_dtype(torch.float64)
device = "cpu"
if device!="mps":
torch.set_default_dtype(torch.float64)
In [67]:
Copied!
colors = ["xkcd:"+color[:-1] for color in pd.read_csv("../../../xkcd_colors.txt",comment="#").iloc[:,0].tolist()][::-1]
colors = ["xkcd:"+color[:-1] for color in pd.read_csv("../../../xkcd_colors.txt",comment="#").iloc[:,0].tolist()][::-1]
True Function¶
In [68]:
Copied!
d = 1
def f_ackley(x, a=20, b=0.2, c=2*np.pi, scaling=32.768):
return x[:,0]*torch.exp(-x[:,0])
# https://www.sfu.ca/~ssurjano/ackley.html
assert x.ndim==2
x = 2*scaling*x-scaling
t1 = a*torch.exp(-b*torch.sqrt(torch.mean(x**2,1)))
t2 = torch.exp(torch.mean(torch.cos(c*x),1))
t3 = a+np.exp(1)
y = -t1-t2+t3
return y
d = 1
def f_ackley(x, a=20, b=0.2, c=2*np.pi, scaling=32.768):
return x[:,0]*torch.exp(-x[:,0])
# https://www.sfu.ca/~ssurjano/ackley.html
assert x.ndim==2
x = 2*scaling*x-scaling
t1 = a*torch.exp(-b*torch.sqrt(torch.mean(x**2,1)))
t2 = torch.exp(torch.mean(torch.cos(c*x),1))
t3 = a+np.exp(1)
y = -t1-t2+t3
return y
Parameters¶
In [69]:
Copied!
n = 2**2
xticks = torch.linspace(0,1,501,device=device)
yticks = f_ackley(xticks[:,None])
n = 2**2
xticks = torch.linspace(0,1,501,device=device)
yticks = f_ackley(xticks[:,None])
Standard GP¶
In [70]:
Copied!
print(" n = %d"%n)
sgp = fastgps.StandardGP(
qp.KernelSquaredExponential(d,torchify=True,device=device),
qp.DigitalNetB2(d,seed=11),
)
x_next = sgp.get_x_next(n)
y_next = f_ackley(x_next)
sgp.add_y_next(y_next)
sgp.fit()
pmean_std_n,pstd_std_n,q,ci_low_std_n,ci_high_std_n = sgp.post_ci(xticks[:,None])
x_std_n,y_std_n = sgp.x.clone(),sgp.y.clone()
nprojs = [n,2*n,4*n,8*n,16*n]
vprojs = [sgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
fig,ax = pyplot.subplots(nrows=1,ncols=1,figsize=(6,4))
ax.set_xscale("log",base=10)
ax.set_yscale("log",base=10)
ax.plot(nprojs,vprojs,'-o');
print(" n = %d"%n)
sgp = fastgps.StandardGP(
qp.KernelSquaredExponential(d,torchify=True,device=device),
qp.DigitalNetB2(d,seed=11),
)
x_next = sgp.get_x_next(n)
y_next = f_ackley(x_next)
sgp.add_y_next(y_next)
sgp.fit()
pmean_std_n,pstd_std_n,q,ci_low_std_n,ci_high_std_n = sgp.post_ci(xticks[:,None])
x_std_n,y_std_n = sgp.x.clone(),sgp.y.clone()
nprojs = [n,2*n,4*n,8*n,16*n]
vprojs = [sgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
fig,ax = pyplot.subplots(nrows=1,ncols=1,figsize=(6,4))
ax.set_xscale("log",base=10)
ax.set_yscale("log",base=10)
ax.plot(nprojs,vprojs,'-o');
n = 4
iter of 5.0e+03 | best loss | loss
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.00e+00 | -3.04e+00 | -3.04e+00
5.00e+00 | -3.98e+00 | -3.98e+00
1.00e+01 | -4.92e+00 | -4.92e+00
1.50e+01 | -5.00e+00 | -5.00e+00
2.00e+01 | -5.02e+00 | -5.00e+00
2.20e+01 | -5.02e+00 | -5.01e+00
posterior cubature var: n = 4 2.92e-05 n = 8 1.27e-05 n = 16 6.27e-06 n = 32 3.12e-06 n = 64 1.56e-06
In [71]:
Copied!
print(" n = %d"%(2*n))
x_next = sgp.get_x_next(2*n)
y_next = f_ackley(x_next)
sgp.add_y_next(y_next)
sgp.fit()
pmean_std_2n,pstd_std_2n,q,ci_low_std_2n,ci_high_std_2n = sgp.post_ci(xticks[:,None])
x_std_2n,y_std_2n = sgp.x.clone(),sgp.y.clone()
nprojs = [2*n,4*n,8*n,16*n,32*n]
vprojs = [sgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o')
fig
print(" n = %d"%(2*n))
x_next = sgp.get_x_next(2*n)
y_next = f_ackley(x_next)
sgp.add_y_next(y_next)
sgp.fit()
pmean_std_2n,pstd_std_2n,q,ci_low_std_2n,ci_high_std_2n = sgp.post_ci(xticks[:,None])
x_std_2n,y_std_2n = sgp.x.clone(),sgp.y.clone()
nprojs = [2*n,4*n,8*n,16*n,32*n]
vprojs = [sgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o')
fig
n = 8
iter of 5.0e+03 | best loss | loss
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.00e+00 | -1.76e+01 | -1.76e+01
5.00e+00 | -1.76e+01 | -1.76e+01
1.00e+01 | -1.76e+01 | -1.76e+01
posterior cubature var: n = 8 1.28e-05 n = 16 6.27e-06 n = 32 3.12e-06 n = 64 1.56e-06 n = 128 7.81e-07
Out[71]:
In [72]:
Copied!
print(" n = %d"%(4*n))
x_next = sgp.get_x_next(4*n)
assert x_next.shape==(2*n,1)
y_next = f_ackley(x_next)
sgp.add_y_next(y_next)
sgp.fit()
pmean_std_4n,pstd_std_4n,q,ci_low_std_4n,ci_high_std_4n = sgp.post_ci(xticks[:,None])
x_std_4n,y_std_4n = sgp.x.clone(),sgp.y.clone()
nprojs = [4*n,8*n,16*n,32*n,64*n]
vprojs = [sgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o')
fig
print(" n = %d"%(4*n))
x_next = sgp.get_x_next(4*n)
assert x_next.shape==(2*n,1)
y_next = f_ackley(x_next)
sgp.add_y_next(y_next)
sgp.fit()
pmean_std_4n,pstd_std_4n,q,ci_low_std_4n,ci_high_std_4n = sgp.post_ci(xticks[:,None])
x_std_4n,y_std_4n = sgp.x.clone(),sgp.y.clone()
nprojs = [4*n,8*n,16*n,32*n,64*n]
vprojs = [sgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o')
fig
n = 16
iter of 5.0e+03 | best loss | loss
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.00e+00 | -4.46e+01 | -4.46e+01
5.00e+00 | -4.47e+01 | -4.47e+01
1.00e+01 | -4.48e+01 | -4.48e+01
1.50e+01 | -4.48e+01 | -4.48e+01
1.60e+01 | -4.48e+01 | -4.48e+01
posterior cubature var: n = 16 6.27e-06 n = 32 3.12e-06 n = 64 1.56e-06 n = 128 7.81e-07 n = 256 3.91e-07
Out[72]:
Lattice¶
In [73]:
Copied!
print(" n = %d"%n)
fgp = fastgps.FastGPLattice(
qp.KernelShiftInvar(d,torchify=True,device=device),
qp.Lattice(d,seed=7),
)
x_next = fgp.get_x_next(n)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_lattice_n,pstd_lattice_n,q,ci_low_lattice_n,ci_high_lattice_n = fgp.post_ci(xticks[:,None])
x_lattice_n,y_lattice_n = fgp.x.clone(),fgp.y.clone()
nprojs = [n,2*n,4*n,8*n,16*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
fig,ax = pyplot.subplots(nrows=1,ncols=1,figsize=(6,4))
ax.set_xscale("log",base=10)
ax.set_yscale("log",base=10)
ax.plot(nprojs,vprojs,'-o');
print(" n = %d"%n)
fgp = fastgps.FastGPLattice(
qp.KernelShiftInvar(d,torchify=True,device=device),
qp.Lattice(d,seed=7),
)
x_next = fgp.get_x_next(n)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_lattice_n,pstd_lattice_n,q,ci_low_lattice_n,ci_high_lattice_n = fgp.post_ci(xticks[:,None])
x_lattice_n,y_lattice_n = fgp.x.clone(),fgp.y.clone()
nprojs = [n,2*n,4*n,8*n,16*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
fig,ax = pyplot.subplots(nrows=1,ncols=1,figsize=(6,4))
ax.set_xscale("log",base=10)
ax.set_yscale("log",base=10)
ax.plot(nprojs,vprojs,'-o');
n = 4
iter of 5.0e+03 | best loss | loss
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.00e+00 | 5.45e+00 | 5.45e+00
5.00e+00 | 2.88e+00 | 2.88e+00
1.00e+01 | -1.68e+00 | -1.68e+00
1.50e+01 | -1.95e+00 | -1.95e+00
2.00e+01 | -2.12e+00 | -2.12e+00
2.50e+01 | -2.23e+00 | -2.23e+00
3.00e+01 | -2.33e+00 | -2.33e+00
3.50e+01 | -2.49e+00 | -2.49e+00
4.00e+01 | -2.87e+00 | -2.87e+00
4.50e+01 | -3.81e+00 | -3.81e+00
5.00e+01 | -4.56e+00 | -4.49e+00
5.50e+01 | -4.82e+00 | -4.82e+00
6.00e+01 | -5.14e+00 | -5.14e+00
6.50e+01 | -5.35e+00 | -5.35e+00
7.00e+01 | -5.36e+00 | -5.36e+00
7.40e+01 | -5.36e+00 | -5.36e+00
posterior cubature var: n = 4 6.01e-07 n = 8 5.08e-07 n = 16 1.45e-07 n = 32 1.17e-08 n = 64 7.44e-10
In [74]:
Copied!
print(" n = %d"%(2*n))
x_next = fgp.get_x_next(2*n)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_lattice_2n,pstd_lattice_2n,q,ci_low_lattice_2n,ci_high_lattice_2n = fgp.post_ci(xticks[:,None])
x_lattice_2n,y_lattice_2n = fgp.x.clone(),fgp.y.clone()
nprojs = [2*n,4*n,8*n,16*n,32*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o');
fig
print(" n = %d"%(2*n))
x_next = fgp.get_x_next(2*n)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_lattice_2n,pstd_lattice_2n,q,ci_low_lattice_2n,ci_high_lattice_2n = fgp.post_ci(xticks[:,None])
x_lattice_2n,y_lattice_2n = fgp.x.clone(),fgp.y.clone()
nprojs = [2*n,4*n,8*n,16*n,32*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o');
fig
n = 8
iter of 5.0e+03 | best loss | loss
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.00e+00 | -1.50e+01 | -1.50e+01
5.00e+00 | -1.51e+01 | -1.51e+01
1.00e+01 | -1.51e+01 | -1.51e+01
1.10e+01 | -1.51e+01 | -1.51e+01
posterior cubature var: n = 8 4.32e-07 n = 16 1.18e-07 n = 32 9.30e-09 n = 64 5.91e-10 n = 128 3.70e-11
Out[74]:
In [75]:
Copied!
print(" n = %d"%(4*n))
x_next = fgp.get_x_next(4*n)
assert x_next.shape==(2*n,1)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_lattice_4n,pstd_lattice_4n,q,ci_low_lattice_4n,ci_high_lattice_4n = fgp.post_ci(xticks[:,None])
x_lattice_4n,y_lattice_4n = fgp.x.clone(),fgp.y.clone()
print(" posterior cubature var: %-10.2e n=%d: %-10.2e n=%d: %-10.2e"%\
(fgp.post_cubature_var(),8*n,fgp.post_cubature_var(n=8*n),16*n,fgp.post_cubature_var(n=16*n)))
nprojs = [4*n,8*n,16*n,32*n,64*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o')
fig
print(" n = %d"%(4*n))
x_next = fgp.get_x_next(4*n)
assert x_next.shape==(2*n,1)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_lattice_4n,pstd_lattice_4n,q,ci_low_lattice_4n,ci_high_lattice_4n = fgp.post_ci(xticks[:,None])
x_lattice_4n,y_lattice_4n = fgp.x.clone(),fgp.y.clone()
print(" posterior cubature var: %-10.2e n=%d: %-10.2e n=%d: %-10.2e"%\
(fgp.post_cubature_var(),8*n,fgp.post_cubature_var(n=8*n),16*n,fgp.post_cubature_var(n=16*n)))
nprojs = [4*n,8*n,16*n,32*n,64*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o')
fig
n = 16
iter of 5.0e+03 | best loss | loss
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.00e+00 | -3.63e+01 | -3.63e+01
5.00e+00 | -3.70e+01 | -3.70e+01
1.00e+01 | -3.71e+01 | -3.71e+01
1.20e+01 | -3.71e+01 | -3.71e+01
posterior cubature var: 1.59e-07 n=32: 1.34e-08 n=64: 8.54e-10
posterior cubature var: n = 16 1.59e-07 n = 32 1.34e-08 n = 64 8.54e-10 n = 128 5.34e-11 n = 256 3.34e-12
Out[75]:
Digital Net¶
In [76]:
Copied!
print(" n = %d"%n)
fgp = fastgps.FastGPDigitalNetB2(
qp.KernelDigShiftInvarCombined(d,torchify=True,device=device),
qp.DigitalNetB2(d,seed=7),
)
x_next = fgp.get_x_next(n)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_dnb2_n,pstd_dnb2_n,q,ci_low_dnb2_n,ci_high_dnb2_n = fgp.post_ci(xticks[:,None])
x_dnb2_n,y_dnb2_n = fgp.x.clone(),fgp.y.clone()
print(" posterior cubature var: %-10.2e n=%d: %-10.2e n=%d: %-10.2e"%\
(fgp.post_cubature_var(),2*n,fgp.post_cubature_var(n=2*n),4*n,fgp.post_cubature_var(n=4*n)))
nprojs = [n,2*n,4*n,8*n,16*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
fig,ax = pyplot.subplots(nrows=1,ncols=1,figsize=(6,4))
ax.set_xscale("log",base=10)
ax.set_yscale("log",base=10)
ax.plot(nprojs,vprojs,'-o');
print(" n = %d"%n)
fgp = fastgps.FastGPDigitalNetB2(
qp.KernelDigShiftInvarCombined(d,torchify=True,device=device),
qp.DigitalNetB2(d,seed=7),
)
x_next = fgp.get_x_next(n)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_dnb2_n,pstd_dnb2_n,q,ci_low_dnb2_n,ci_high_dnb2_n = fgp.post_ci(xticks[:,None])
x_dnb2_n,y_dnb2_n = fgp.x.clone(),fgp.y.clone()
print(" posterior cubature var: %-10.2e n=%d: %-10.2e n=%d: %-10.2e"%\
(fgp.post_cubature_var(),2*n,fgp.post_cubature_var(n=2*n),4*n,fgp.post_cubature_var(n=4*n)))
nprojs = [n,2*n,4*n,8*n,16*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
fig,ax = pyplot.subplots(nrows=1,ncols=1,figsize=(6,4))
ax.set_xscale("log",base=10)
ax.set_yscale("log",base=10)
ax.plot(nprojs,vprojs,'-o');
n = 4
iter of 5.0e+03 | best loss | loss
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.00e+00 | 7.15e+00 | 7.15e+00
5.00e+00 | 3.26e+00 | 3.26e+00
1.00e+01 | -1.97e+00 | -1.87e+00
1.50e+01 | -2.68e+00 | -2.68e+00
2.00e+01 | -3.14e+00 | -3.14e+00
2.50e+01 | -3.43e+00 | -3.43e+00
3.00e+01 | -3.70e+00 | -3.70e+00
3.50e+01 | -3.91e+00 | -3.91e+00
4.00e+01 | -4.03e+00 | -4.03e+00
4.50e+01 | -4.13e+00 | -4.13e+00
5.00e+01 | -4.15e+00 | -4.15e+00
5.50e+01 | -4.18e+00 | -4.18e+00
posterior cubature var: 2.85e-04 n=8: 1.37e-04 n=16: 3.97e-05
posterior cubature var: n = 4 2.85e-04 n = 8 1.37e-04 n = 16 3.97e-05 n = 32 2.59e-05 n = 64 1.39e-06
In [77]:
Copied!
print(" n = %d"%(2*n))
x_next = fgp.get_x_next(2*n)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_dnb2_2n,pstd_dnb2_2n,q,ci_low_dnb2_2n,ci_high_dnb2_2n = fgp.post_ci(xticks[:,None])
x_dnb2_2n,y_dnb2_2n = fgp.x.clone(),fgp.y.clone()
nprojs = [2*n,4*n,8*n,16*n,32*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o');
fig
print(" n = %d"%(2*n))
x_next = fgp.get_x_next(2*n)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_dnb2_2n,pstd_dnb2_2n,q,ci_low_dnb2_2n,ci_high_dnb2_2n = fgp.post_ci(xticks[:,None])
x_dnb2_2n,y_dnb2_2n = fgp.x.clone(),fgp.y.clone()
nprojs = [2*n,4*n,8*n,16*n,32*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o');
fig
n = 8
iter of 5.0e+03 | best loss | loss
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.00e+00 | -1.09e+01 | -1.09e+01
5.00e+00 | -1.13e+01 | -1.13e+01
1.00e+01 | -1.14e+01 | -1.14e+01
1.50e+01 | -1.16e+01 | -1.16e+01
2.00e+01 | -1.17e+01 | -1.17e+01
2.50e+01 | -1.20e+01 | -1.20e+01
3.00e+01 | -1.20e+01 | -1.20e+01
3.50e+01 | -1.20e+01 | -1.20e+01
posterior cubature var: n = 8 2.49e-05 n = 16 1.40e-05 n = 32 1.30e-05 n = 64 2.00e-07 n = 128 5.94e-08
Out[77]:
In [78]:
Copied!
print(" n = %d"%(4*n))
x_next = fgp.get_x_next(4*n)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_dnb2_4n,pstd_dnb2_4n,q,ci_low_dnb2_4n,ci_high_dnb2_4n = fgp.post_ci(xticks[:,None])
x_dnb2_4n,y_dnb2_4n = fgp.x.clone(),fgp.y.clone()
nprojs = [4*n,8*n,16*n,32*n,64*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o')
fig
print(" n = %d"%(4*n))
x_next = fgp.get_x_next(4*n)
y_next = f_ackley(x_next)
fgp.add_y_next(y_next)
fgp.fit()
pmean_dnb2_4n,pstd_dnb2_4n,q,ci_low_dnb2_4n,ci_high_dnb2_4n = fgp.post_ci(xticks[:,None])
x_dnb2_4n,y_dnb2_4n = fgp.x.clone(),fgp.y.clone()
nprojs = [4*n,8*n,16*n,32*n,64*n]
vprojs = [fgp.post_cubature_var(n=nproj) for nproj in nprojs]
print(" posterior cubature var: "+(("n = %d %-10.2e")*len(nprojs))%tuple(itertools.chain(*zip(nprojs,vprojs))))
ax.plot(nprojs,vprojs,'-o')
fig
n = 16
iter of 5.0e+03 | best loss | loss
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.00e+00 | -2.71e+01 | -2.71e+01
5.00e+00 | -2.71e+01 | -2.71e+01
1.00e+01 | -2.71e+01 | -2.71e+01
1.50e+01 | -2.72e+01 | -2.72e+01
1.60e+01 | -2.72e+01 | -2.72e+01
posterior cubature var: n = 16 1.27e-05 n = 32 1.18e-05 n = 64 1.67e-07 n = 128 5.02e-08 n = 256 1.00e-08
Out[78]:
Collect Data + Plot¶
In [79]:
Copied!
data = [
[
(x_std_n,y_std_n,pmean_std_n,ci_low_std_n,ci_high_std_n),
(x_lattice_n,y_lattice_n,pmean_lattice_n,ci_low_lattice_n,ci_high_lattice_n),
(x_dnb2_n,y_dnb2_n,pmean_dnb2_n,ci_low_dnb2_n,ci_high_dnb2_n)
],
[
(x_std_2n,y_std_2n,pmean_std_2n,ci_low_std_2n,ci_high_std_2n),
(x_lattice_2n,y_lattice_2n,pmean_lattice_2n,ci_low_lattice_2n,ci_high_lattice_2n),
(x_dnb2_2n,y_dnb2_2n,pmean_dnb2_2n,ci_low_dnb2_2n,ci_high_dnb2_2n)
],
[
(x_std_4n,y_std_4n,pmean_std_4n,ci_low_std_4n,ci_high_std_4n),
(x_lattice_4n,y_lattice_4n,pmean_lattice_4n,ci_low_lattice_4n,ci_high_lattice_4n),
(x_dnb2_4n,y_dnb2_4n,pmean_dnb2_4n,ci_low_dnb2_4n,ci_high_dnb2_4n)
],
]
data = [
[
(x_std_n,y_std_n,pmean_std_n,ci_low_std_n,ci_high_std_n),
(x_lattice_n,y_lattice_n,pmean_lattice_n,ci_low_lattice_n,ci_high_lattice_n),
(x_dnb2_n,y_dnb2_n,pmean_dnb2_n,ci_low_dnb2_n,ci_high_dnb2_n)
],
[
(x_std_2n,y_std_2n,pmean_std_2n,ci_low_std_2n,ci_high_std_2n),
(x_lattice_2n,y_lattice_2n,pmean_lattice_2n,ci_low_lattice_2n,ci_high_lattice_2n),
(x_dnb2_2n,y_dnb2_2n,pmean_dnb2_2n,ci_low_dnb2_2n,ci_high_dnb2_2n)
],
[
(x_std_4n,y_std_4n,pmean_std_4n,ci_low_std_4n,ci_high_std_4n),
(x_lattice_4n,y_lattice_4n,pmean_lattice_4n,ci_low_lattice_4n,ci_high_lattice_4n),
(x_dnb2_4n,y_dnb2_4n,pmean_dnb2_4n,ci_low_dnb2_4n,ci_high_dnb2_4n)
],
]
In [80]:
Copied!
nrows = 3
ncols = len(data[0])
_alpha = 0.25
pyplot.rcParams.update(tueplots.figsizes.icml2024_full(nrows=nrows,ncols=ncols))
fig,ax = pyplot.subplots(nrows=nrows,ncols=ncols)
ax = ax.reshape((nrows,ncols))
for i in range(3):
for j in range(ncols):
x,y,pmean,ci_low,ci_high = data[i][j]
ax[i,j].plot(xticks.cpu(),yticks.cpu(),color="k")
ax[i,j].scatter(x[:,0].cpu(),y.cpu(),color="k")
ax[i,j].plot(xticks.cpu(),pmean.cpu(),color=colors[j])
ax[i,j].fill_between(xticks.cpu(),ci_low.cpu(),ci_high.cpu(),color=colors[j],alpha=_alpha)
ax[0,0].set_title("StandardGP")
ax[0,1].set_title("FastGPDigitalNetB2")
ax[0,2].set_title("FastGPLattice")
ax[0,0].set_ylabel(r"n = %d"%n)
ax[1,0].set_ylabel(r"n = %d"%(2*n))
ax[2,0].set_ylabel(r"n = %d"%(4*n))
fig.savefig("./gps.pdf")
nrows = 3
ncols = len(data[0])
_alpha = 0.25
pyplot.rcParams.update(tueplots.figsizes.icml2024_full(nrows=nrows,ncols=ncols))
fig,ax = pyplot.subplots(nrows=nrows,ncols=ncols)
ax = ax.reshape((nrows,ncols))
for i in range(3):
for j in range(ncols):
x,y,pmean,ci_low,ci_high = data[i][j]
ax[i,j].plot(xticks.cpu(),yticks.cpu(),color="k")
ax[i,j].scatter(x[:,0].cpu(),y.cpu(),color="k")
ax[i,j].plot(xticks.cpu(),pmean.cpu(),color=colors[j])
ax[i,j].fill_between(xticks.cpu(),ci_low.cpu(),ci_high.cpu(),color=colors[j],alpha=_alpha)
ax[0,0].set_title("StandardGP")
ax[0,1].set_title("FastGPDigitalNetB2")
ax[0,2].set_title("FastGPLattice")
ax[0,0].set_ylabel(r"n = %d"%n)
ax[1,0].set_ylabel(r"n = %d"%(2*n))
ax[2,0].set_ylabel(r"n = %d"%(4*n))
fig.savefig("./gps.pdf")
In [ ]:
Copied!