-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_plot.py
78 lines (54 loc) · 1.92 KB
/
test_plot.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from __future__ import print_function
import os
if 'DISPLAY' not in os.environ:
import matplotlib
matplotlib.use("Agg")
import filecmp
import matplotlib.pyplot as plt
import psdr, psdr.demos
path = os.path.abspath(os.path.realpath(__file__))
path = os.path.dirname(path)
def test_shadow():
fun = psdr.demos.OTLCircuit()
X = fun.domain.sample_grid(4)
fX = fun(X)
Xg = fun.domain.sample_grid(6)
fXg = fun(Xg)
pra = psdr.PolynomialRidgeApproximation(degree = 5, subspace_dimension = 1)
pra.fit(X, fX)
# Generate shadow plot with response surface
ax = pra.shadow_plot(X, fX, pgfname = 'test_shadow.dat')
#assert filecmp.cmp(os.path.join(path,'data/test_shadow.dat'), 'test_shadow.dat')
#assert filecmp.cmp(os.path.join(path,'data/test_shadow_response.dat'), 'test_shadow_response.dat')
# Generate shadow envelope
pra.shadow_envelope(Xg, fXg, ax = ax, pgfname = 'test_shadow_envelope.dat')
#assert filecmp.cmp(os.path.join(path, 'data/test_shadow_envelope.dat'), 'test_shadow_envelope.dat')
fig, ax2 = plt.subplots()
pra2 = psdr.PolynomialRidgeApproximation(degree = 5, subspace_dimension = 2)
pra2.fit(X, fX)
pra2.shadow_plot(X, fX, ax = ax2)
def test_shadow_lipschitz():
fun = psdr.demos.OTLCircuit()
X = fun.domain.sample_grid(2)
fX = fun(X)
grads = fun.grad(X)
lip = psdr.LipschitzMatrix()
lip.fit(grads = grads)
ax = lip.shadow_plot(X, fX)
lip.shadow_uncertainty(fun.domain, X, fX, ax = ax, ngrid = 4, pgfname = 'test_shadow_uncertainty.dat')
#assert filecmp.cmp(os.path.join(path, 'data/test_shadow_uncertainty.dat'), 'test_shadow_uncertainty.dat')
def test_score():
fun = psdr.demos.OTLCircuit()
X = fun.domain.sample_grid(2)
fX = fun(X)
grads = fun.grad(X)
lip = psdr.DiagonalLipschitzMatrix()
lip.fit(grads = grads)
ax = lip.plot_score(domain = fun.domain)
ax.figure.tight_layout()
print(lip.U)
if __name__ == '__main__':
#test_shadow_lipschitz()
#test_shadow()
test_score()
plt.show()