Skip to content

Commit

Permalink
Working on an experimental design example in moderate dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffrey-hokanson committed Aug 30, 2020
1 parent 24b6e77 commit f2ac52d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
50 changes: 50 additions & 0 deletions Reproducibility/Lipschitz/fig_design.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import numpy as np
import psdr, psdr.demos
from psdr.pgf import PGF
import seaborn as sns

funs = [psdr.demos.OTLCircuit()]
names = ['OTLCircuit']

algs = [lambda dom, M, L: psdr.random_sample(dom, M),
lambda dom, M, L: psdr.latin_hypercube_maximin(dom, M, maxiter = 1),
lambda dom, M, L: psdr.minimax_lloyd(dom, M, L = L)
]
alg_names = ['random', 'LHS', 'minimax']
# Number of repetitions
Ms = [100, 100, 10]

Nsamp = 20

for fun, name in zip(funs, names):
# Estimate the Lipschitz matrix
np.random.seed(0)
X = fun.domain.sample(1000)
grads = fun.grad(X)

lip = psdr.LipschitzMatrix(verbose = True, reltol = 1e-7, abstol = 1e-7, feastol = 1e-7)
lip.fit(grads = grads)

L = lip.L

# Samples to use when estimating dispersion
X0 = psdr.maximin_coffeehouse(fun.domain, 200, L = L, N0 = 10)

# Now perform designs
for alg, alg_name, M in zip(algs, alg_names, Ms):
dispersion = []
# We can get a very sloppy fit with more points
for i in range(M):
np.random.seed(i)
X = alg(fun.domain, Nsamp, L)
dist = psdr.fill_distance_estimate(fun.domain, X, L = L, X0 = X0)
dispersion.append(dist)
print(f'{alg_name:20s} : {i:4d} dispersion {dist:10.5e}')

ax = sns.swarmplot(dispersion)
x, y = np.array(ax.collections[0].get_offsets()).T
pgf = PGF()
pgf.add('x', x)
pgf.add('y', y)
pgf.write(f'data/fig_design_{name}_{alg_name}.dat')

2 changes: 0 additions & 2 deletions Reproducibility/Lipschitz/fig_epsilon_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
fun = psdr.demos.Borehole()




if False:
fun = psdr.demos.HartmannMHD()
X = fun.domain.sample_grid(4)
Expand Down

0 comments on commit f2ac52d

Please sign in to comment.