Mercurial > hg > pycsalgos
diff 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 |
line wrap: on
line diff
--- a/scripts/ABSapprox.py Wed Nov 09 11:11:39 2011 +0000 +++ b/scripts/ABSapprox.py Wed Nov 09 18:18:42 2011 +0000 @@ -8,8 +8,13 @@ import numpy as np import scipy.io import math -#import matplotlib.pyplot as plt -#import matplotlib.cm as cm +doplot = True +try: + import matplotlib.pyplot as plt +except: + doplot = False +if doplot: + import matplotlib.cm as cm import pyCSalgos import pyCSalgos.GAP.GAP import pyCSalgos.SL0.SL0_approx @@ -39,6 +44,23 @@ L = 10 return pyCSalgos.SL0.SL0_approx.SL0_approx(aggD,aggy,epsilon,sigmamin,sigma_decrease_factor,mu_0,L) +def run_bp(y,M,Omega,D,U,S,Vt,epsilon,lbd): + + N,n = Omega.shape + #D = np.linalg.pinv(Omega) + #U,S,Vt = np.linalg.svd(D) + aggDupper = np.dot(M,D) + aggDlower = Vt[-(N-n):,:] + aggD = np.concatenate((aggDupper, lbd * aggDlower)) + aggy = np.concatenate((y, np.zeros(N-n))) + + sigmamin = 0.001 + sigma_decrease_factor = 0.5 + mu_0 = 2 + L = 10 + return pyCSalgos.SL0.SL0_approx.SL0_approx(aggD,aggy,epsilon,sigmamin,sigma_decrease_factor,mu_0,L) + + # Define tuples (algorithm setup function, algorithm function, name) gap = (run_gap, 'GAP') sl0 = (run_sl0, 'SL0_approx') @@ -57,15 +79,15 @@ #Set up experiment parameters d = 50.0; sigma = 2.0 - deltas = np.arange(0.05,0.95,0.05) - rhos = np.arange(0.05,0.95,0.05) - #deltas = np.array([0.15,0.95]) - #rhos = np.array([0.15,0.95]) + #deltas = np.arange(0.05,1.,0.05) + #rhos = np.arange(0.05,1.,0.05) + deltas = np.array([0.05, 0.45, 0.95]) + rhos = np.array([0.05, 0.45, 0.95]) #deltas = np.array([0.05]) #rhos = np.array([0.05]) #delta = 0.8; #rho = 0.15; - numvects = 20; # Number of vectors to generate + numvects = 100; # Number of vectors to generate SNRdb = 20.; # This is norm(signal)/norm(noise), so power, not energy # Values for lambda #lambdas = [0 10.^linspace(-5, 4, 10)]; @@ -121,14 +143,15 @@ print "Oops, Type Error" raise # Show - # for algotuple in algosN: - # plt.figure() - # plt.imshow(meanmatrix[algotuple[1]], cmap=cm.gray, interpolation='nearest') - # for algotuple in algosL: - # for ilbd in np.arange(lambdas.size): - # plt.figure() - # plt.imshow(meanmatrix[algotuple[1]][ilbd], cmap=cm.gray, interpolation='nearest') - # plt.show() + if doplot: + for algotuple in algosN: + plt.figure() + plt.imshow(meanmatrix[algotuple[1]], cmap=cm.gray, interpolation='nearest',origin='lower') + for algotuple in algosL: + for ilbd in np.arange(lambdas.size): + plt.figure() + plt.imshow(meanmatrix[algotuple[1]][ilbd], cmap=cm.gray, interpolation='nearest',origin='lower') + plt.show() print "Finished." def genData(d,sigma,delta,rho,numvects,SNRdb): @@ -211,4 +234,7 @@ # Script main if __name__ == "__main__": + + #import cProfile + #cProfile.run('mainrun()', 'profile') mainrun() \ No newline at end of file