diff 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
line wrap: on
line diff
--- a/utils.py	Thu Apr 05 14:00:13 2012 +0300
+++ b/utils.py	Mon Apr 23 10:54:57 2012 +0300
@@ -30,7 +30,9 @@
         print "Exiting."
         return
  
-    loadshowmatrices_multipixels(filename, algonames, [], [], algonames, [], doshow, dosave, saveplotbase, saveplotexts)
+    withticks = ['GAP']
+    withnoaxes = [algoname[0][0] for algoname in algonames if algoname not in withticks]
+    loadshowmatrices_multipixels(filename, algonames, [], [], withticks, withnoaxes, doshow, dosave, saveplotbase, saveplotexts)
       
 def replot_approx(filename, algonames = None, doshow=True, dosave=False, saveplotbase=None, saveplotexts=None):
     """
@@ -42,7 +44,13 @@
 
     if algonames == None:
       if 'algosNnames' in mdict and 'algosLnames' in mdict:
-        algonames = numpy.vstack((mdict['algosNnames'], mdict['algosLnames']))
+        
+        if mdict['algosLnames'].size is 0:
+          algonames = mdict['algosNnames']
+        elif mdict['algosNnames'].size is 0:
+          algonames = mdict['algosLnames']
+        else:
+          algonames = numpy.vstack((mdict['algosNnames'], mdict['algosLnames']))
       else:
         print "No algonames given, and couldn't find them in mat file."
         print "Exiting."
@@ -167,6 +175,65 @@
     if doshow:
       plt.show()
     print "Finished."    
+
+def replot_ProveEll1(filename, algonames=None, doshow=True, dosave=False, saveplotbase=None, saveplotexts=None):
+
+  """
+  Plot ...
+  The files are saved in the current folder.
+  """
+
+  mdict = scipy.io.loadmat(filename)
+
+  if algonames == None:
+    if 'algosNnames' in mdict and 'algosLnames' in mdict:
+      algonames = numpy.vstack((mdict['algosNnames'], mdict['algosLnames']))
+    else:
+      print "No algonames given, and couldn't find them in mat file."
+      print "Exiting."
+      return
+
+  lambdas = mdict['lambdas']
+
+  toplot = numpy.zeros((len(lambdas),len(algonames)))
+  
+  idxcol = 0
+  for algonameobj in algonames:
+    algoname = algonameobj[0][0]
+    if mdict['meanmatrix'][algoname][0,0].ndim == 2:
+      toplot[:,idxcol] = (1 - mdict['meanmatrix'][algoname][0,0]) * numpy.ones(len(lambdas))
+    elif mdict['meanmatrix'][algoname][0,0].ndim == 3:
+      for ilbd in numpy.arange(len(lambdas)):
+        toplot[ilbd,idxcol] = 1 - mdict['meanmatrix'][algoname][0,0][ilbd][0,0]
+    idxcol = idxcol + 1
+
+  plt.figure()
+  plt.plot(toplot)
+  #plt.legend([algonameobj[0][0] for algonameobj in algonames])
+  plt.legend(['NESTA', r'ABS-$\lambda$: BP'])
+
+  ax = plt.gca()
+
+  fewerticks = [0,3,6,9]
+  xticklabels = []
+  for i in range(lambdas.size):
+    if i in fewerticks:
+      xticklabels.append('{:g}'.format(lambdas[i,0]))
+    else:
+      xticklabels.append('')
+  ax.set_xticklabels(xticklabels)
+  #ax.set_xlabel(r'Value of $\lambda$', size=60)
+  ax.set_xlabel(r'$\lambda$', size=40)
+  for label in ax.get_xticklabels():
+    label.set_fontsize(20) 
+  for label in ax.get_yticklabels():
+    label.set_fontsize(20)
+  for ext in saveplotexts:
+    plt.savefig(saveplotbase + '.' + ext, bbox_inches='tight')
+
+  if doshow:
+    plt.show()
+  print "Finished."   
     
 def appendtomatfile(filename, toappend, toappendname):
   mdict = scipy.io.loadmat(filename)