-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest_plots.py
executable file
·60 lines (49 loc) · 1.52 KB
/
test_plots.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
#!/usr/bin/env python -tt
from __future__ import division
import sys
import inspect
import numpy as np
import matplotlib.pyplot as plt
import kde
import dgp_class as dgp
def main(Nsamp=None, Nmesh=None):
"""
Generates plots for the 16 test cases for both the analytical pdf and the
kernel density estimate.
Parameters
----------
Nsamp: int
Number of samples used for the kde
Nmesh: int
Number of points used for the mesh
"""
if Nsamp is None:
Nsamp = 10000
classes = [(cls, name) for name, cls in inspect.getmembers(dgp)
if inspect.isclass(cls) and not cls in (dgp.dgp, dgp.LogNormal)]
for cls, name in classes:
print 'Generating graph for', name
model = cls()
x = model.sample(size=Nsamp)
t, mesh, kdense = kde.kde(x, N=Nmesh)
f = model.pdf(mesh)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title(name, size=36)
plt.plot(mesh, kdense)
plt.plot(mesh, f)
for label in ax.get_xticklabels() + ax.get_yticklabels():
label.set_fontsize(24)
fig.set_figheight(10)
fig.set_figwidth(12)
fig.savefig(name+'.pdf')
plt.close()
return None
if __name__ == "__main__":
answer = raw_input('Warning: This script generates 16 pdfs\n' +
'Do you wish to continue? (Y/N)')
if answer in ('Y', 'y', 'yes', 'Yes', 'YES'):
main()
sys.exit(0)
else:
sys.exit(1)