comparison scripts/ABSapprox.py @ 27:1a88766113a9

A lot of things. Fixed problem in Gap Fixed multiprocessor versions of script (both PP and multiproc)
author nikcleju
date Wed, 09 Nov 2011 18:18:42 +0000
parents dd0e78b5bb13
children bc2a96a03b0a
comparison
equal deleted inserted replaced
26:f0f77d92e0c1 27:1a88766113a9
6 """ 6 """
7 7
8 import numpy as np 8 import numpy as np
9 import scipy.io 9 import scipy.io
10 import math 10 import math
11 #import matplotlib.pyplot as plt 11 doplot = True
12 #import matplotlib.cm as cm 12 try:
13 import matplotlib.pyplot as plt
14 except:
15 doplot = False
16 if doplot:
17 import matplotlib.cm as cm
13 import pyCSalgos 18 import pyCSalgos
14 import pyCSalgos.GAP.GAP 19 import pyCSalgos.GAP.GAP
15 import pyCSalgos.SL0.SL0_approx 20 import pyCSalgos.SL0.SL0_approx
16 21
17 # Define functions that prepare arguments for each algorithm call 22 # Define functions that prepare arguments for each algorithm call
37 sigma_decrease_factor = 0.5 42 sigma_decrease_factor = 0.5
38 mu_0 = 2 43 mu_0 = 2
39 L = 10 44 L = 10
40 return pyCSalgos.SL0.SL0_approx.SL0_approx(aggD,aggy,epsilon,sigmamin,sigma_decrease_factor,mu_0,L) 45 return pyCSalgos.SL0.SL0_approx.SL0_approx(aggD,aggy,epsilon,sigmamin,sigma_decrease_factor,mu_0,L)
41 46
47 def run_bp(y,M,Omega,D,U,S,Vt,epsilon,lbd):
48
49 N,n = Omega.shape
50 #D = np.linalg.pinv(Omega)
51 #U,S,Vt = np.linalg.svd(D)
52 aggDupper = np.dot(M,D)
53 aggDlower = Vt[-(N-n):,:]
54 aggD = np.concatenate((aggDupper, lbd * aggDlower))
55 aggy = np.concatenate((y, np.zeros(N-n)))
56
57 sigmamin = 0.001
58 sigma_decrease_factor = 0.5
59 mu_0 = 2
60 L = 10
61 return pyCSalgos.SL0.SL0_approx.SL0_approx(aggD,aggy,epsilon,sigmamin,sigma_decrease_factor,mu_0,L)
62
63
42 # Define tuples (algorithm setup function, algorithm function, name) 64 # Define tuples (algorithm setup function, algorithm function, name)
43 gap = (run_gap, 'GAP') 65 gap = (run_gap, 'GAP')
44 sl0 = (run_sl0, 'SL0_approx') 66 sl0 = (run_sl0, 'SL0_approx')
45 67
46 # Define which algorithms to run 68 # Define which algorithms to run
55 nalgosL = len(algosL) 77 nalgosL = len(algosL)
56 78
57 #Set up experiment parameters 79 #Set up experiment parameters
58 d = 50.0; 80 d = 50.0;
59 sigma = 2.0 81 sigma = 2.0
60 deltas = np.arange(0.05,0.95,0.05) 82 #deltas = np.arange(0.05,1.,0.05)
61 rhos = np.arange(0.05,0.95,0.05) 83 #rhos = np.arange(0.05,1.,0.05)
62 #deltas = np.array([0.15,0.95]) 84 deltas = np.array([0.05, 0.45, 0.95])
63 #rhos = np.array([0.15,0.95]) 85 rhos = np.array([0.05, 0.45, 0.95])
64 #deltas = np.array([0.05]) 86 #deltas = np.array([0.05])
65 #rhos = np.array([0.05]) 87 #rhos = np.array([0.05])
66 #delta = 0.8; 88 #delta = 0.8;
67 #rho = 0.15; 89 #rho = 0.15;
68 numvects = 20; # Number of vectors to generate 90 numvects = 100; # Number of vectors to generate
69 SNRdb = 20.; # This is norm(signal)/norm(noise), so power, not energy 91 SNRdb = 20.; # This is norm(signal)/norm(noise), so power, not energy
70 # Values for lambda 92 # Values for lambda
71 #lambdas = [0 10.^linspace(-5, 4, 10)]; 93 #lambdas = [0 10.^linspace(-5, 4, 10)];
72 #lambdas = np.concatenate((np.array([0]), 10**np.linspace(-5, 4, 10))) 94 #lambdas = np.concatenate((np.array([0]), 10**np.linspace(-5, 4, 10)))
73 lambdas = np.array([0., 0.0001, 0.01, 1, 100, 10000]) 95 lambdas = np.array([0., 0.0001, 0.01, 1, 100, 10000])
119 scipy.io.savemat('ABSapprox.mat',tosave) 141 scipy.io.savemat('ABSapprox.mat',tosave)
120 except TypeError: 142 except TypeError:
121 print "Oops, Type Error" 143 print "Oops, Type Error"
122 raise 144 raise
123 # Show 145 # Show
124 # for algotuple in algosN: 146 if doplot:
125 # plt.figure() 147 for algotuple in algosN:
126 # plt.imshow(meanmatrix[algotuple[1]], cmap=cm.gray, interpolation='nearest') 148 plt.figure()
127 # for algotuple in algosL: 149 plt.imshow(meanmatrix[algotuple[1]], cmap=cm.gray, interpolation='nearest',origin='lower')
128 # for ilbd in np.arange(lambdas.size): 150 for algotuple in algosL:
129 # plt.figure() 151 for ilbd in np.arange(lambdas.size):
130 # plt.imshow(meanmatrix[algotuple[1]][ilbd], cmap=cm.gray, interpolation='nearest') 152 plt.figure()
131 # plt.show() 153 plt.imshow(meanmatrix[algotuple[1]][ilbd], cmap=cm.gray, interpolation='nearest',origin='lower')
154 plt.show()
132 print "Finished." 155 print "Finished."
133 156
134 def genData(d,sigma,delta,rho,numvects,SNRdb): 157 def genData(d,sigma,delta,rho,numvects,SNRdb):
135 158
136 # Process parameters 159 # Process parameters
209 232
210 return mrelerrN,mrelerrL 233 return mrelerrN,mrelerrL
211 234
212 # Script main 235 # Script main
213 if __name__ == "__main__": 236 if __name__ == "__main__":
237
238 #import cProfile
239 #cProfile.run('mainrun()', 'profile')
214 mainrun() 240 mainrun()