-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_exp.py
72 lines (54 loc) · 2.08 KB
/
plot_exp.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
from os.path import basename, join
from phi.torch.flow import *
PATHS = [
"~/phi/exp_Sigmoid/Adjoint_000003",
# "~/phi/exp_Sigmoid/Ground Truth",
"~/phi/exp_Sigmoid/Adam",
# "~/phi/exp_Sigmoid/Newton",
# "~/phi/exp_Sigmoid/Newton Damped 0.01",
"~/phi/exp_Sigmoid/Sign",
# "~/phi/exp_Sigmoid/SGD 1e-2",
# "~/phi/exp_Sigmoid/SGD 1e-4",
]
# for x_axis in ['time', 'steps']:
# vis.plot_scalars(PATHS, names=['x_l1', 'y_l1'],
# log_scale='y', x=x_axis, reduce='scenes', smooth=64)
# # vis.savefig()
# vis.show()
import pylab
pylab.rc('font', family='Arial', weight='normal', size=8)
# pylab.style.use('dark_background')
cycle = pylab.rcParams['axes.prop_cycle'].by_key()['color']
def plot_error_by_x(path: str, label: str):
net = dense_net(1, 1, [16, 64, 16], activation='Sigmoid')
net.load_state_dict(torch.load(path))
x = math.linspace(-12, 0, 1000, batch('batch'))
y = math.exp(x)
x_prediction = math.native_call(net, y)
x_error = math.l1_loss(x - x_prediction)
pylab.plot(x.numpy(), x_error.numpy(), label=label)
for path in PATHS:
plot_error_by_x(join(path, "net_10000.pth"), basename(path))
# pylab.yscale('log')
pylab.legend()
pylab.show()
def plot_result_by_x(path: str, label: str, color: int):
net = dense_net(1, 1, [16, 64, 16], activation='Sigmoid')
net.load_state_dict(torch.load(path))
x = math.linspace(-12, 0, 1000, batch('batch'))
y = math.exp(x)
x_prediction = math.native_call(net, y)
pylab.plot(x.numpy(), x_prediction.numpy(), label=label, color=cycle[color])
pylab.figure(figsize=(2.5, 2.2))
x = math.linspace(-11, 0, 1000, batch('batch'))
pylab.plot(x.numpy(), x.numpy(), '--', color='grey')
plot_result_by_x("~/phi/exp_Sigmoid/SGD 1e-2/net_10000.pth", "SGD", 3)
plot_result_by_x("~/phi/exp_Sigmoid/Adam/net_10000.pth", "Adam", 1)
plot_result_by_x("~/phi/exp_Sigmoid/Sign/net_10000.pth", "Rescaled", 0)
# pylab.yscale('log')
pylab.legend()
pylab.xlabel("$x^*$")
pylab.ylabel("Predicted $x$")
pylab.tight_layout()
pylab.savefig('plots/exp/exp_pred_vs_sol.pdf', transparent=True)
pylab.show()