-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_plots.py
More file actions
183 lines (107 loc) · 4.76 KB
/
Copy patherror_plots.py
File metadata and controls
183 lines (107 loc) · 4.76 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# -*- coding: utf-8 -*-
"""
Created on May 15 2016
@author: Inom Mirzaev
Plots the generated data from parallel minimize.
"""
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import cPickle, os
import model_rates as mr
fnames = []
#read all the files in the folder
for file in os.listdir("data_files"):
if file.endswith("cobyla.pkl"):
fnames.append(file)
#Open the specific file
myfile = fnames[ -1]
ext = '_alpha_' + str( myfile[-12] )
pkl_file = open(os.path.join( 'data_files' , myfile ) , 'rb')
data = cPickle.load( pkl_file )
pkl_file.close()
a = []
# Total variance norm. See Gibbs and Su (2009) for the definition.
tv_norm = np.zeros( len(data) )
N = len(data[0][-1])
dx = ( mr.x1 - mr.x0 ) / N
for cnum in range(len(data)):
a.append( data[cnum][0] )
#Compute total variation norm
tv_norm[cnum] = np.sum( np.max ( np.abs ( data[cnum][-2]-data[cnum][-1] ) , axis=1 ) ) *dx
a = np.asarray( a )
min_ind = 10
f_fit = data[ min_ind ][-1]
f_true = data[ min_ind ][-2]
f_init = data[ min_ind ][-3]
plt.close('all')
#Colormap for the imshow plots
my_cmap = plt.get_cmap('Set2')
#==============================================================================
# plot of approximate conditional measure (cdf)
#==============================================================================
fig1 = plt.figure(1)
plt.title('$F_{30} (x,\ y)$', fontsize=20, y=1.04)
plt.xlabel('$x$', fontsize=20)
plt.ylabel('$y$', fontsize=20)
plt.imshow(np.flipud(f_fit), interpolation='nearest', cmap=my_cmap , \
vmin=0.001, vmax = np.max( ( np.max(f_fit) , np.max(f_true) ) ) , extent=(0,1,0,1))
cbar_ax = fig1.add_axes([0.85, 0.13, 0.03, 0.75])
plt.colorbar(cax=cbar_ax)
fig_name = 'f_fit'+ext+'.png'
plt.savefig( os.path.join( 'images' , fig_name ) , dpi=400 , bbox_inches='tight' )
#==============================================================================
# plot of true conditional measure (cdf)
#==============================================================================
fig2 = plt.figure(2)
plt.title('$F_{0} (x,\ y)$', fontsize=20, y=1.04)
plt.xlabel('$x$', fontsize=20)
plt.ylabel('$y$', fontsize=20)
plt.imshow(np.flipud(f_true), interpolation='nearest', cmap=my_cmap , \
vmin=0.001, vmax = np.max( ( np.max(f_fit) , np.max(f_true) ) ) , extent=(0,1,0,1))
cbar_ax = fig2.add_axes([0.85, 0.13, 0.03, 0.75])
plt.colorbar(cax=cbar_ax)
fig_name = 'f_true'+ext+'.png'
plt.savefig( os.path.join( 'images' , fig_name ) , dpi=400 , bbox_inches='tight' )
#==============================================================================
# Error between true and fit
#==============================================================================
fig3 = plt.figure(3)
plt.title('Absolute error for $F_{0}$ and $F_{30}$', fontsize=16, y=1.04)
aa = np.abs( f_fit - f_true )
imgplot = plt.imshow(np.flipud( aa ) , interpolation='nearest', cmap='Reds' , \
vmin = 0, vmax = np.max( aa ) , extent=(0,1,0,1))
cbar_ax = fig3.add_axes([0.85, 0.13, 0.03, 0.75])
plt.colorbar(cax=cbar_ax)
plt.xlabel('$x$', fontsize=20)
plt.ylabel('$y$', fontsize=20)
fig_name = 'relative_error'+ext+'.png'
plt.savefig( os.path.join( 'images' , fig_name ) , dpi=400 , bbox_inches='tight' )
#==============================================================================
# Error with respect to t_f
#==============================================================================
plt.figure(4)
plt.plot(a, tv_norm , color='blue', linewidth=1 , marker='o' , markersize=5 )
plt.ylabel( r'$\rho_{TV} \left ( F_{0} , \ F_{30} \right )$', fontsize=20 )
plt.xlabel( '$t_f$', fontsize=20 )
fig_name = 'tv_error'+ext+'.png'
plt.savefig( os.path.join( 'images' , fig_name ) , dpi=400 , bbox_inches='tight' )
#==============================================================================
# plot of cdf for fixed y
#==============================================================================
grid = np.linspace( mr.x0 , mr.x1 , len(f_true) )
f, ax = plt.subplots(2, sharex=True)
mm = int( len(f_true)/2 )
ax[0].plot( grid, f_true[ mm ] , color='b' , linewidth=2 , label='True' )
ax[0].plot( grid, f_fit[ mm ] , color='r' , linewidth=2 , linestyle = '--' , label='Fit')
ax[0].set_ylim([0,1.1])
ax[0].legend(loc='best')
ax[0].set_ylabel('$F(x,\ 0.5)$', fontsize=20)
mm = -1
ax[1].plot( grid, f_true[ mm ] , color='b' , linewidth=2 , label='True' )
ax[1].plot( grid, f_fit[ mm ] , color='r' , linewidth=2 , linestyle = '--' , label='Fit')
ax[1].set_ylim([0,1.1])
ax[1].set_xlabel('$x$', fontsize=20)
ax[1].set_ylabel('$F(x,\ 1.0)$', fontsize=20)
fig_name = 'approximate_F'+ext+'.png'
plt.savefig( os.path.join( 'images' , fig_name ) , dpi=400 , bbox_inches='tight' )