Skip to content

Commit

Permalink
Changes in ES computation and plotting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreday committed Sep 18, 2017
1 parent d22aa9c commit af78c71
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions SA_v2/analysis/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
from matplotlib import pyplot as plt
import sys,os
from sklearn.neighbors import KernelDensity
from sklearn import preprocessing as prep

def density_map(X,kde,savefile='test.png',show=True,xlabel=None,ylabel=None):
def density_map(X, kde, savefile='test.png', show=True, xlabel=None, ylabel=None, n_mesh = 400):

plt.rc('text', usetex=True)
font = {'family' : 'serif', 'size' : 40}
font = {'family' : 'serif', 'size': 18}
plt.rc('font', **font)

fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111)
n_mesh=400
xmin,xmax = np.percentile(X[:,0],q=10.),np.max(X[:,0])
#n_mesh=400
xmin, xmax = np.percentile(X[:,0],q=10.),np.max(X[:,0])
#xmin, xmax = np.min(X[:,0]),np.max(X[:,0])
dx = xmax - xmin
ymin, ymax = np.min(X[:,1]),np.max(X[:,1])
Expand All @@ -22,30 +23,27 @@ def density_map(X,kde,savefile='test.png',show=True,xlabel=None,ylabel=None):
y = np.linspace(ymin-0.1*dy,ymax+0.1*dy, n_mesh)
extent = (xmin-0.1*dx,xmax+0.1*dx,ymin-0.1*dy,ymax+0.1*dy)

from sklearn import preprocessing as prep
mms=prep.MinMaxScaler()

my_map=plt.get_cmap(name='BuGn')

xy=np.array([[xi,yi] for yi in y for xi in x])
xy=np.array([[xi, yi] for yi in y for xi in x])
#print("kk")
z = np.exp(kde.evaluate_density(xy))
z = np.exp(kde.evaluate_density(xy)) # this should be the computationally expensive part
#z = np.exp(rho)
#print("ksdjfk")
z=mms.fit_transform(z.reshape(-1,1))
Z=z.reshape(n_mesh, n_mesh)
z=my_map(z)
Zrgb = z.reshape(n_mesh, n_mesh, 4)


Zrgb[Z < 0.005] = (1.0,1.0,1.0,1.0)

plt.imshow(Zrgb, interpolation='bilinear',cmap='BuGn', extent=extent,origin='lower',aspect='auto',zorder=1)
cb=plt.colorbar()
cb.set_label(label='Density',labelpad=10)

X1, Y1 = np.meshgrid(x,y)
plt.contour(X1, Y1, Z, levels=np.linspace(0.05,0.8,5), linewidths=0.3, colors='k', extent=extent,zorder=2)
plt.contour(X1, Y1, Z, levels=np.linspace(0.03,0.8,6), linewidths=0.3, colors='k', extent=extent,zorder=2)
ax.grid(False)

if xlabel is not None:
Expand Down
2 changes: 1 addition & 1 deletion SA_v2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def run_ES(parameters, model:MODEL, utils):
outfile = utils.make_file_name(parameters, root=parameters['root'])
with open(outfile,'wb') as f:
pickle.dump(exact_data, f, protocol=4)

print("Saved results in %s"%outfile)
print("Total run time : \t %.3f s"%(time.time()-st))
print("\n Thank you and goodbye !")
Expand Down
2 changes: 1 addition & 1 deletion SA_v2/para.dat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
task ES
L 8
L 6
J 1.0
hz 1.0
hx_i -2.
Expand Down

0 comments on commit af78c71

Please sign in to comment.