annotate scripts/ABSapprox.py @ 32:e1da5140c9a5

Count and display finished jobs in run_once_tuple() Disabled "dictionary not normalized" message in OMP Fixed bug that displayed same values for all algorithms Made TST default iterations nsweep = 300
author nikcleju
date Fri, 11 Nov 2011 15:35:55 +0000
parents 829bf04c92af
children 116dcfacd1cc
rev   line source
nikcleju@10 1 # -*- coding: utf-8 -*-
nikcleju@10 2 """
nikcleju@10 3 Created on Sat Nov 05 18:08:40 2011
nikcleju@10 4
nikcleju@10 5 @author: Nic
nikcleju@10 6 """
nikcleju@10 7
nikcleju@19 8 import numpy as np
nikcleju@22 9 import scipy.io
nikcleju@22 10 import math
nikcleju@29 11
nikcleju@10 12 import pyCSalgos
nikcleju@19 13 import pyCSalgos.GAP.GAP
nikcleju@19 14 import pyCSalgos.SL0.SL0_approx
nikcleju@30 15 import pyCSalgos.OMP.omp_QR
nikcleju@30 16 import pyCSalgos.RecomTST.RecommendedTST
nikcleju@10 17
nikcleju@29 18 #==========================
nikcleju@29 19 # Algorithm functions
nikcleju@29 20 #==========================
nikcleju@22 21 def run_gap(y,M,Omega,epsilon):
nikcleju@19 22 gapparams = {"num_iteration" : 1000,\
nikcleju@19 23 "greedy_level" : 0.9,\
nikcleju@19 24 "stopping_coefficient_size" : 1e-4,\
nikcleju@19 25 "l2solver" : 'pseudoinverse',\
nikcleju@19 26 "noise_level": epsilon}
nikcleju@22 27 return pyCSalgos.GAP.GAP.GAP(y,M,M.T,Omega,Omega.T,gapparams,np.zeros(Omega.shape[1]))[0]
nikcleju@29 28
nikcleju@22 29 def run_sl0(y,M,Omega,D,U,S,Vt,epsilon,lbd):
nikcleju@19 30
nikcleju@19 31 N,n = Omega.shape
nikcleju@22 32 #D = np.linalg.pinv(Omega)
nikcleju@22 33 #U,S,Vt = np.linalg.svd(D)
nikcleju@19 34 aggDupper = np.dot(M,D)
nikcleju@19 35 aggDlower = Vt[-(N-n):,:]
nikcleju@19 36 aggD = np.concatenate((aggDupper, lbd * aggDlower))
nikcleju@19 37 aggy = np.concatenate((y, np.zeros(N-n)))
nikcleju@19 38
nikcleju@22 39 sigmamin = 0.001
nikcleju@22 40 sigma_decrease_factor = 0.5
nikcleju@20 41 mu_0 = 2
nikcleju@20 42 L = 10
nikcleju@22 43 return pyCSalgos.SL0.SL0_approx.SL0_approx(aggD,aggy,epsilon,sigmamin,sigma_decrease_factor,mu_0,L)
nikcleju@10 44
nikcleju@27 45 def run_bp(y,M,Omega,D,U,S,Vt,epsilon,lbd):
nikcleju@27 46
nikcleju@27 47 N,n = Omega.shape
nikcleju@27 48 #D = np.linalg.pinv(Omega)
nikcleju@27 49 #U,S,Vt = np.linalg.svd(D)
nikcleju@27 50 aggDupper = np.dot(M,D)
nikcleju@27 51 aggDlower = Vt[-(N-n):,:]
nikcleju@27 52 aggD = np.concatenate((aggDupper, lbd * aggDlower))
nikcleju@27 53 aggy = np.concatenate((y, np.zeros(N-n)))
nikcleju@27 54
nikcleju@27 55 sigmamin = 0.001
nikcleju@27 56 sigma_decrease_factor = 0.5
nikcleju@27 57 mu_0 = 2
nikcleju@27 58 L = 10
nikcleju@27 59 return pyCSalgos.SL0.SL0_approx.SL0_approx(aggD,aggy,epsilon,sigmamin,sigma_decrease_factor,mu_0,L)
nikcleju@27 60
nikcleju@30 61 def run_ompeps(y,M,Omega,D,U,S,Vt,epsilon,lbd):
nikcleju@30 62
nikcleju@30 63 N,n = Omega.shape
nikcleju@30 64 #D = np.linalg.pinv(Omega)
nikcleju@30 65 #U,S,Vt = np.linalg.svd(D)
nikcleju@30 66 aggDupper = np.dot(M,D)
nikcleju@30 67 aggDlower = Vt[-(N-n):,:]
nikcleju@30 68 aggD = np.concatenate((aggDupper, lbd * aggDlower))
nikcleju@30 69 aggy = np.concatenate((y, np.zeros(N-n)))
nikcleju@30 70
nikcleju@30 71 opts = dict()
nikcleju@30 72 opts['stopCrit'] = 'mse'
nikcleju@30 73 opts['stopTol'] = epsilon**2 / aggy.size
nikcleju@30 74 return pyCSalgos.OMP.omp_QR.greed_omp_qr(aggy,aggD,aggD.shape[1],opts)[0]
nikcleju@30 75
nikcleju@30 76 def run_tst(y,M,Omega,D,U,S,Vt,epsilon,lbd):
nikcleju@30 77
nikcleju@30 78 N,n = Omega.shape
nikcleju@30 79 #D = np.linalg.pinv(Omega)
nikcleju@30 80 #U,S,Vt = np.linalg.svd(D)
nikcleju@30 81 aggDupper = np.dot(M,D)
nikcleju@30 82 aggDlower = Vt[-(N-n):,:]
nikcleju@30 83 aggD = np.concatenate((aggDupper, lbd * aggDlower))
nikcleju@30 84 aggy = np.concatenate((y, np.zeros(N-n)))
nikcleju@30 85
nikcleju@32 86 nsweep = 300
nikcleju@32 87 tol = epsilon / np.linalg.norm(aggy)
nikcleju@32 88 return pyCSalgos.RecomTST.RecommendedTST.RecommendedTST(aggD, aggy, nsweep=nsweep, tol=tol)
nikcleju@30 89
nikcleju@29 90 #==========================
nikcleju@29 91 # Define tuples (algorithm function, name)
nikcleju@29 92 #==========================
nikcleju@22 93 gap = (run_gap, 'GAP')
nikcleju@30 94 sl0 = (run_sl0, 'SL0a')
nikcleju@29 95 bp = (run_bp, 'BP')
nikcleju@30 96 ompeps = (run_ompeps, 'OMPeps')
nikcleju@30 97 tst = (run_tst, 'TST')
nikcleju@10 98
nikcleju@22 99 # Define which algorithms to run
nikcleju@22 100 # 1. Algorithms not depending on lambda
nikcleju@22 101 algosN = gap, # tuple
nikcleju@22 102 # 2. Algorithms depending on lambda (our ABS approach)
nikcleju@32 103 #algosL = sl0,bp,ompeps,tst # tuple
nikcleju@32 104 algosL = sl0,tst
nikcleju@32 105
nikcleju@32 106 #==========================
nikcleju@32 107 # Pool initializer function (multiprocessing)
nikcleju@32 108 # Needed to pass the shared variable to the worker processes
nikcleju@32 109 # The variables must be global in the module in order to be seen later in run_once_tuple()
nikcleju@32 110 # see http://stackoverflow.com/questions/1675766/how-to-combine-pool-map-with-array-shared-memory-in-python-multiprocessing
nikcleju@32 111 #==========================
nikcleju@32 112 def initProcess(share, njobs):
nikcleju@32 113 import sys
nikcleju@32 114 currmodule = sys.modules[__name__]
nikcleju@32 115 currmodule.proccount = share
nikcleju@32 116 currmodule.njobs = njobs
nikcleju@29 117
nikcleju@29 118 #==========================
nikcleju@29 119 # Interface functions
nikcleju@29 120 #==========================
nikcleju@29 121 def run_multiproc(ncpus=None):
nikcleju@30 122 d,sigma,deltas,rhos,lambdas,numvects,SNRdb,dosavedata,savedataname,doshowplot,dosaveplot,saveplotbase,saveplotexts = standard_params()
nikcleju@29 123 run_multi(algosN, algosL, d,sigma,deltas,rhos,lambdas,numvects,SNRdb,dosavedata=dosavedata,savedataname=savedataname,\
nikcleju@30 124 doparallel=True, ncpus=ncpus,\
nikcleju@30 125 doshowplot=doshowplot,dosaveplot=dosaveplot,saveplotbase=saveplotbase,saveplotexts=saveplotexts)
nikcleju@22 126
nikcleju@29 127 def run():
nikcleju@30 128 d,sigma,deltas,rhos,lambdas,numvects,SNRdb,dosavedata,savedataname,doshowplot,dosaveplot,saveplotbase,saveplotexts = standard_params()
nikcleju@29 129 run_multi(algosN, algosL, d,sigma,deltas,rhos,lambdas,numvects,SNRdb,dosavedata=dosavedata,savedataname=savedataname,\
nikcleju@30 130 doparallel=False,\
nikcleju@30 131 doshowplot=doshowplot,dosaveplot=dosaveplot,saveplotbase=saveplotbase,saveplotexts=saveplotexts)
nikcleju@19 132
nikcleju@29 133 def standard_params():
nikcleju@29 134 #Set up standard experiment parameters
nikcleju@25 135 d = 50.0;
nikcleju@22 136 sigma = 2.0
nikcleju@32 137 #deltas = np.arange(0.05,1.,0.05)
nikcleju@32 138 #rhos = np.arange(0.05,1.,0.05)
nikcleju@32 139 deltas = np.array([0.05, 0.45, 0.95])
nikcleju@32 140 rhos = np.array([0.05, 0.45, 0.95])
nikcleju@31 141 #deltas = np.array([0.05])
nikcleju@31 142 #rhos = np.array([0.05])
nikcleju@22 143 #delta = 0.8;
nikcleju@22 144 #rho = 0.15;
nikcleju@27 145 numvects = 100; # Number of vectors to generate
nikcleju@20 146 SNRdb = 20.; # This is norm(signal)/norm(noise), so power, not energy
nikcleju@22 147 # Values for lambda
nikcleju@22 148 #lambdas = [0 10.^linspace(-5, 4, 10)];
nikcleju@25 149 #lambdas = np.concatenate((np.array([0]), 10**np.linspace(-5, 4, 10)))
nikcleju@25 150 lambdas = np.array([0., 0.0001, 0.01, 1, 100, 10000])
nikcleju@29 151
nikcleju@29 152 dosavedata = True
nikcleju@30 153 savedataname = 'approx_pt_std1.mat'
nikcleju@30 154
nikcleju@30 155 doshowplot = False
nikcleju@30 156 dosaveplot = True
nikcleju@30 157 saveplotbase = 'approx_pt_std1_'
nikcleju@30 158 saveplotexts = ('png','pdf','eps')
nikcleju@29 159
nikcleju@29 160
nikcleju@30 161 return d,sigma,deltas,rhos,lambdas,numvects,SNRdb,dosavedata,savedataname,\
nikcleju@30 162 doshowplot,dosaveplot,saveplotbase,saveplotexts
nikcleju@29 163
nikcleju@29 164 #==========================
nikcleju@29 165 # Main functions
nikcleju@29 166 #==========================
nikcleju@29 167 def run_multi(algosN, algosL, d, sigma, deltas, rhos, lambdas, numvects, SNRdb,
nikcleju@29 168 doparallel=False, ncpus=None,\
nikcleju@29 169 doshowplot=False, dosaveplot=False, saveplotbase=None, saveplotexts=None,\
nikcleju@29 170 dosavedata=False, savedataname=None):
nikcleju@30 171
nikcleju@30 172 print "This is analysis recovery ABS approximation script by Nic"
nikcleju@30 173 print "Running phase transition ( run_multi() )"
nikcleju@29 174
nikcleju@29 175 if doparallel:
nikcleju@32 176 import multiprocessing
nikcleju@32 177 # Shared value holding the number of finished processes
nikcleju@32 178 # Add it as global of the module
nikcleju@32 179 import sys
nikcleju@32 180 currmodule = sys.modules[__name__]
nikcleju@32 181 currmodule.proccount = multiprocessing.Value('I', 0) # 'I' = unsigned int, see docs (multiprocessing, array)
nikcleju@29 182
nikcleju@30 183 if dosaveplot or doshowplot:
nikcleju@30 184 try:
nikcleju@30 185 import matplotlib
nikcleju@30 186 if doshowplot:
nikcleju@30 187 print "Importing matplotlib with default (GUI) backend... ",
nikcleju@30 188 else:
nikcleju@30 189 print "Importing matplotlib with \"Cairo\" backend... ",
nikcleju@30 190 matplotlib.use('Cairo')
nikcleju@30 191 import matplotlib.pyplot as plt
nikcleju@30 192 import matplotlib.cm as cm
nikcleju@30 193 print "OK"
nikcleju@30 194 except:
nikcleju@30 195 print "FAIL"
nikcleju@30 196 print "Importing matplotlib.pyplot failed. No figures at all"
nikcleju@30 197 print "Try selecting a different backend"
nikcleju@30 198 doshowplot = False
nikcleju@30 199 dosaveplot = False
nikcleju@30 200
nikcleju@30 201 # Print summary of parameters
nikcleju@30 202 print "Parameters:"
nikcleju@30 203 if doparallel:
nikcleju@30 204 if ncpus is None:
nikcleju@30 205 print " Running in parallel with default threads using \"multiprocessing\" package"
nikcleju@30 206 else:
nikcleju@30 207 print " Running in parallel with",ncpus,"threads using \"multiprocessing\" package"
nikcleju@30 208 else:
nikcleju@30 209 print "Running single thread"
nikcleju@30 210 if doshowplot:
nikcleju@30 211 print " Showing figures"
nikcleju@30 212 else:
nikcleju@30 213 print " Not showing figures"
nikcleju@30 214 if dosaveplot:
nikcleju@30 215 print " Saving figures as "+saveplotbase+"* with extensions ",saveplotexts
nikcleju@30 216 else:
nikcleju@30 217 print " Not saving figures"
nikcleju@30 218 print " Running algorithms",[algotuple[1] for algotuple in algosN],[algotuple[1] for algotuple in algosL]
nikcleju@29 219
nikcleju@29 220 nalgosN = len(algosN)
nikcleju@29 221 nalgosL = len(algosL)
nikcleju@29 222
nikcleju@22 223 meanmatrix = dict()
nikcleju@22 224 for i,algo in zip(np.arange(nalgosN),algosN):
nikcleju@22 225 meanmatrix[algo[1]] = np.zeros((rhos.size, deltas.size))
nikcleju@22 226 for i,algo in zip(np.arange(nalgosL),algosL):
nikcleju@22 227 meanmatrix[algo[1]] = np.zeros((lambdas.size, rhos.size, deltas.size))
nikcleju@22 228
nikcleju@29 229 # Prepare parameters
nikcleju@29 230 jobparams = []
nikcleju@30 231 print " (delta, rho) pairs to be run:"
nikcleju@22 232 for idelta,delta in zip(np.arange(deltas.size),deltas):
nikcleju@22 233 for irho,rho in zip(np.arange(rhos.size),rhos):
nikcleju@22 234
nikcleju@22 235 # Generate data and operator
nikcleju@29 236 Omega,x0,y,M,realnoise = generateData(d,sigma,delta,rho,numvects,SNRdb)
nikcleju@22 237
nikcleju@29 238 #Save the parameters, and run after
nikcleju@30 239 print " delta = ",delta," rho = ",rho
nikcleju@29 240 jobparams.append((algosN,algosL, Omega,y,lambdas,realnoise,M,x0))
nikcleju@32 241
nikcleju@32 242 if doparallel:
nikcleju@32 243 currmodule.njobs = deltas.size * rhos.size
nikcleju@30 244 print "End of parameters"
nikcleju@30 245
nikcleju@29 246 # Run
nikcleju@29 247 jobresults = []
nikcleju@32 248
nikcleju@29 249 if doparallel:
nikcleju@32 250 pool = multiprocessing.Pool(4,initializer=initProcess,initargs=(currmodule.proccount,currmodule.njobs))
nikcleju@32 251 jobresults = pool.map(run_once_tuple, jobparams)
nikcleju@29 252 else:
nikcleju@29 253 for jobparam in jobparams:
nikcleju@29 254 jobresults.append(run_once(algosN,algosL,Omega,y,lambdas,realnoise,M,x0))
nikcleju@29 255
nikcleju@29 256 # Read results
nikcleju@29 257 idx = 0
nikcleju@29 258 for idelta,delta in zip(np.arange(deltas.size),deltas):
nikcleju@29 259 for irho,rho in zip(np.arange(rhos.size),rhos):
nikcleju@29 260 mrelerrN,mrelerrL = jobresults[idx]
nikcleju@29 261 idx = idx+1
nikcleju@22 262 for algotuple in algosN:
nikcleju@22 263 meanmatrix[algotuple[1]][irho,idelta] = 1 - mrelerrN[algotuple[1]]
nikcleju@22 264 if meanmatrix[algotuple[1]][irho,idelta] < 0 or math.isnan(meanmatrix[algotuple[1]][irho,idelta]):
nikcleju@22 265 meanmatrix[algotuple[1]][irho,idelta] = 0
nikcleju@22 266 for algotuple in algosL:
nikcleju@22 267 for ilbd in np.arange(lambdas.size):
nikcleju@22 268 meanmatrix[algotuple[1]][ilbd,irho,idelta] = 1 - mrelerrL[algotuple[1]][ilbd]
nikcleju@22 269 if meanmatrix[algotuple[1]][ilbd,irho,idelta] < 0 or math.isnan(meanmatrix[algotuple[1]][ilbd,irho,idelta]):
nikcleju@22 270 meanmatrix[algotuple[1]][ilbd,irho,idelta] = 0
nikcleju@22 271
nikcleju@32 272 # Save
nikcleju@32 273 if dosavedata:
nikcleju@32 274 tosave = dict()
nikcleju@32 275 tosave['meanmatrix'] = meanmatrix
nikcleju@32 276 tosave['d'] = d
nikcleju@32 277 tosave['sigma'] = sigma
nikcleju@32 278 tosave['deltas'] = deltas
nikcleju@32 279 tosave['rhos'] = rhos
nikcleju@32 280 tosave['numvects'] = numvects
nikcleju@32 281 tosave['SNRdb'] = SNRdb
nikcleju@32 282 tosave['lambdas'] = lambdas
nikcleju@32 283 try:
nikcleju@32 284 scipy.io.savemat(savedataname, tosave)
nikcleju@32 285 except:
nikcleju@32 286 print "Save error"
nikcleju@22 287 # Show
nikcleju@29 288 if doshowplot or dosaveplot:
nikcleju@27 289 for algotuple in algosN:
nikcleju@29 290 algoname = algotuple[1]
nikcleju@27 291 plt.figure()
nikcleju@29 292 plt.imshow(meanmatrix[algoname], cmap=cm.gray, interpolation='nearest',origin='lower')
nikcleju@29 293 if dosaveplot:
nikcleju@29 294 for ext in saveplotexts:
nikcleju@29 295 plt.savefig(saveplotbase + algoname + '.' + ext)
nikcleju@27 296 for algotuple in algosL:
nikcleju@29 297 algoname = algotuple[1]
nikcleju@27 298 for ilbd in np.arange(lambdas.size):
nikcleju@27 299 plt.figure()
nikcleju@29 300 plt.imshow(meanmatrix[algoname][ilbd], cmap=cm.gray, interpolation='nearest',origin='lower')
nikcleju@29 301 if dosaveplot:
nikcleju@29 302 for ext in saveplotexts:
nikcleju@30 303 plt.savefig(saveplotbase + algoname + ('_lbd%.0e' % lambdas[ilbd]) + '.' + ext)
nikcleju@29 304 if doshowplot:
nikcleju@29 305 plt.show()
nikcleju@29 306
nikcleju@22 307 print "Finished."
nikcleju@22 308
nikcleju@29 309 def run_once_tuple(t):
nikcleju@32 310 results = run_once(*t)
nikcleju@32 311 import sys
nikcleju@32 312 currmodule = sys.modules[__name__]
nikcleju@32 313 currmodule.proccount.value = currmodule.proccount.value + 1
nikcleju@32 314 print "================================"
nikcleju@32 315 print "Finished job",currmodule.proccount.value,"of",currmodule.njobs
nikcleju@32 316 print "================================"
nikcleju@32 317 return results
nikcleju@10 318
nikcleju@29 319 def run_once(algosN,algosL,Omega,y,lambdas,realnoise,M,x0):
nikcleju@22 320
nikcleju@22 321 d = Omega.shape[1]
nikcleju@22 322
nikcleju@22 323 nalgosN = len(algosN)
nikcleju@22 324 nalgosL = len(algosL)
nikcleju@10 325
nikcleju@19 326 xrec = dict()
nikcleju@19 327 err = dict()
nikcleju@19 328 relerr = dict()
nikcleju@22 329
nikcleju@22 330 # Prepare storage variables for algorithms non-Lambda
nikcleju@22 331 for i,algo in zip(np.arange(nalgosN),algosN):
nikcleju@22 332 xrec[algo[1]] = np.zeros((d, y.shape[1]))
nikcleju@22 333 err[algo[1]] = np.zeros(y.shape[1])
nikcleju@22 334 relerr[algo[1]] = np.zeros(y.shape[1])
nikcleju@22 335 # Prepare storage variables for algorithms with Lambda
nikcleju@22 336 for i,algo in zip(np.arange(nalgosL),algosL):
nikcleju@22 337 xrec[algo[1]] = np.zeros((lambdas.size, d, y.shape[1]))
nikcleju@22 338 err[algo[1]] = np.zeros((lambdas.size, y.shape[1]))
nikcleju@22 339 relerr[algo[1]] = np.zeros((lambdas.size, y.shape[1]))
nikcleju@19 340
nikcleju@22 341 # Run algorithms non-Lambda
nikcleju@22 342 for iy in np.arange(y.shape[1]):
nikcleju@22 343 for algofunc,strname in algosN:
nikcleju@22 344 epsilon = 1.1 * np.linalg.norm(realnoise[:,iy])
nikcleju@22 345 xrec[strname][:,iy] = algofunc(y[:,iy],M,Omega,epsilon)
nikcleju@22 346 err[strname][iy] = np.linalg.norm(x0[:,iy] - xrec[strname][:,iy])
nikcleju@22 347 relerr[strname][iy] = err[strname][iy] / np.linalg.norm(x0[:,iy])
nikcleju@32 348 for algofunc,strname in algosN:
nikcleju@32 349 print strname,' : avg relative error = ',np.mean(relerr[strname])
nikcleju@22 350
nikcleju@22 351 # Run algorithms with Lambda
nikcleju@19 352 for ilbd,lbd in zip(np.arange(lambdas.size),lambdas):
nikcleju@19 353 for iy in np.arange(y.shape[1]):
nikcleju@22 354 D = np.linalg.pinv(Omega)
nikcleju@22 355 U,S,Vt = np.linalg.svd(D)
nikcleju@22 356 for algofunc,strname in algosL:
nikcleju@19 357 epsilon = 1.1 * np.linalg.norm(realnoise[:,iy])
nikcleju@22 358 gamma = algofunc(y[:,iy],M,Omega,D,U,S,Vt,epsilon,lbd)
nikcleju@22 359 xrec[strname][ilbd,:,iy] = np.dot(D,gamma)
nikcleju@19 360 err[strname][ilbd,iy] = np.linalg.norm(x0[:,iy] - xrec[strname][ilbd,:,iy])
nikcleju@19 361 relerr[strname][ilbd,iy] = err[strname][ilbd,iy] / np.linalg.norm(x0[:,iy])
nikcleju@19 362 print 'Lambda = ',lbd,' :'
nikcleju@32 363 for algofunc,strname in algosL:
nikcleju@32 364 print ' ',strname,' : avg relative error = ',np.mean(relerr[strname][ilbd,:])
nikcleju@10 365
nikcleju@22 366 # Prepare results
nikcleju@22 367 mrelerrN = dict()
nikcleju@22 368 for algotuple in algosN:
nikcleju@22 369 mrelerrN[algotuple[1]] = np.mean(relerr[algotuple[1]])
nikcleju@22 370 mrelerrL = dict()
nikcleju@22 371 for algotuple in algosL:
nikcleju@22 372 mrelerrL[algotuple[1]] = np.mean(relerr[algotuple[1]],1)
nikcleju@22 373
nikcleju@22 374 return mrelerrN,mrelerrL
nikcleju@29 375
nikcleju@29 376 def generateData(d,sigma,delta,rho,numvects,SNRdb):
nikcleju@29 377
nikcleju@29 378 # Process parameters
nikcleju@29 379 noiselevel = 1.0 / (10.0**(SNRdb/10.0));
nikcleju@29 380 p = round(sigma*d);
nikcleju@29 381 m = round(delta*d);
nikcleju@29 382 l = round(d - rho*m);
nikcleju@29 383
nikcleju@29 384 # Generate Omega and data based on parameters
nikcleju@29 385 Omega = pyCSalgos.GAP.GAP.Generate_Analysis_Operator(d, p);
nikcleju@29 386 # Optionally make Omega more coherent
nikcleju@29 387 U,S,Vt = np.linalg.svd(Omega);
nikcleju@29 388 Sdnew = S * (1+np.arange(S.size)) # Make D coherent, not Omega!
nikcleju@29 389 Snew = np.vstack((np.diag(Sdnew), np.zeros((Omega.shape[0] - Omega.shape[1], Omega.shape[1]))))
nikcleju@29 390 Omega = np.dot(U , np.dot(Snew,Vt))
nikcleju@29 391
nikcleju@29 392 # Generate data
nikcleju@29 393 x0,y,M,Lambda,realnoise = pyCSalgos.GAP.GAP.Generate_Data_Known_Omega(Omega, d,p,m,l,noiselevel, numvects,'l0');
nikcleju@29 394
nikcleju@29 395 return Omega,x0,y,M,realnoise
nikcleju@22 396
nikcleju@19 397 # Script main
nikcleju@19 398 if __name__ == "__main__":
nikcleju@27 399 #import cProfile
nikcleju@27 400 #cProfile.run('mainrun()', 'profile')
nikcleju@29 401 run()