Mercurial > hg > absrec
comparison utils.py @ 21:d395461b92ae tip
Lots and lots of modifications. Approximate recovery script working.
author | Nic Cleju <nikcleju@gmail.com> |
---|---|
date | Mon, 23 Apr 2012 10:54:57 +0300 |
parents | 2837cfeaf353 |
children |
comparison
equal
deleted
inserted
replaced
20:eccc7a5b9ee3 | 21:d395461b92ae |
---|---|
28 else: | 28 else: |
29 print "No algonames given, and couldn't find them in mat file." | 29 print "No algonames given, and couldn't find them in mat file." |
30 print "Exiting." | 30 print "Exiting." |
31 return | 31 return |
32 | 32 |
33 loadshowmatrices_multipixels(filename, algonames, [], [], algonames, [], doshow, dosave, saveplotbase, saveplotexts) | 33 withticks = ['GAP'] |
34 withnoaxes = [algoname[0][0] for algoname in algonames if algoname not in withticks] | |
35 loadshowmatrices_multipixels(filename, algonames, [], [], withticks, withnoaxes, doshow, dosave, saveplotbase, saveplotexts) | |
34 | 36 |
35 def replot_approx(filename, algonames = None, doshow=True, dosave=False, saveplotbase=None, saveplotexts=None): | 37 def replot_approx(filename, algonames = None, doshow=True, dosave=False, saveplotbase=None, saveplotexts=None): |
36 """ | 38 """ |
37 Replot exact recovery results from mat file, with better axis ticks and | 39 Replot exact recovery results from mat file, with better axis ticks and |
38 other custom tweaked options. | 40 other custom tweaked options. |
40 | 42 |
41 mdict = scipy.io.loadmat(filename) | 43 mdict = scipy.io.loadmat(filename) |
42 | 44 |
43 if algonames == None: | 45 if algonames == None: |
44 if 'algosNnames' in mdict and 'algosLnames' in mdict: | 46 if 'algosNnames' in mdict and 'algosLnames' in mdict: |
45 algonames = numpy.vstack((mdict['algosNnames'], mdict['algosLnames'])) | 47 |
48 if mdict['algosLnames'].size is 0: | |
49 algonames = mdict['algosNnames'] | |
50 elif mdict['algosNnames'].size is 0: | |
51 algonames = mdict['algosLnames'] | |
52 else: | |
53 algonames = numpy.vstack((mdict['algosNnames'], mdict['algosLnames'])) | |
46 else: | 54 else: |
47 print "No algonames given, and couldn't find them in mat file." | 55 print "No algonames given, and couldn't find them in mat file." |
48 print "Exiting." | 56 print "Exiting." |
49 return | 57 return |
50 | 58 |
165 | 173 |
166 ilbd = ilbd + 1 | 174 ilbd = ilbd + 1 |
167 if doshow: | 175 if doshow: |
168 plt.show() | 176 plt.show() |
169 print "Finished." | 177 print "Finished." |
178 | |
179 def replot_ProveEll1(filename, algonames=None, doshow=True, dosave=False, saveplotbase=None, saveplotexts=None): | |
180 | |
181 """ | |
182 Plot ... | |
183 The files are saved in the current folder. | |
184 """ | |
185 | |
186 mdict = scipy.io.loadmat(filename) | |
187 | |
188 if algonames == None: | |
189 if 'algosNnames' in mdict and 'algosLnames' in mdict: | |
190 algonames = numpy.vstack((mdict['algosNnames'], mdict['algosLnames'])) | |
191 else: | |
192 print "No algonames given, and couldn't find them in mat file." | |
193 print "Exiting." | |
194 return | |
195 | |
196 lambdas = mdict['lambdas'] | |
197 | |
198 toplot = numpy.zeros((len(lambdas),len(algonames))) | |
199 | |
200 idxcol = 0 | |
201 for algonameobj in algonames: | |
202 algoname = algonameobj[0][0] | |
203 if mdict['meanmatrix'][algoname][0,0].ndim == 2: | |
204 toplot[:,idxcol] = (1 - mdict['meanmatrix'][algoname][0,0]) * numpy.ones(len(lambdas)) | |
205 elif mdict['meanmatrix'][algoname][0,0].ndim == 3: | |
206 for ilbd in numpy.arange(len(lambdas)): | |
207 toplot[ilbd,idxcol] = 1 - mdict['meanmatrix'][algoname][0,0][ilbd][0,0] | |
208 idxcol = idxcol + 1 | |
209 | |
210 plt.figure() | |
211 plt.plot(toplot) | |
212 #plt.legend([algonameobj[0][0] for algonameobj in algonames]) | |
213 plt.legend(['NESTA', r'ABS-$\lambda$: BP']) | |
214 | |
215 ax = plt.gca() | |
216 | |
217 fewerticks = [0,3,6,9] | |
218 xticklabels = [] | |
219 for i in range(lambdas.size): | |
220 if i in fewerticks: | |
221 xticklabels.append('{:g}'.format(lambdas[i,0])) | |
222 else: | |
223 xticklabels.append('') | |
224 ax.set_xticklabels(xticklabels) | |
225 #ax.set_xlabel(r'Value of $\lambda$', size=60) | |
226 ax.set_xlabel(r'$\lambda$', size=40) | |
227 for label in ax.get_xticklabels(): | |
228 label.set_fontsize(20) | |
229 for label in ax.get_yticklabels(): | |
230 label.set_fontsize(20) | |
231 for ext in saveplotexts: | |
232 plt.savefig(saveplotbase + '.' + ext, bbox_inches='tight') | |
233 | |
234 if doshow: | |
235 plt.show() | |
236 print "Finished." | |
170 | 237 |
171 def appendtomatfile(filename, toappend, toappendname): | 238 def appendtomatfile(filename, toappend, toappendname): |
172 mdict = scipy.io.loadmat(filename) | 239 mdict = scipy.io.loadmat(filename) |
173 mdict[toappendname] = toappend | 240 mdict[toappendname] = toappend |
174 try: | 241 try: |