def test_13(self): Nr = 32 Nc = 31 Nd = 5 M = 4 D = np.random.randn(Nd, Nd, M).astype(np.float32) s = np.random.randn(Nr, Nc).astype(np.float32) frc = 0.5 msk = su.rndmask(s.shape, frc, dtype=np.float32) s *= msk lmbda = 1e-1 mu = 1e-2 Wl1 = np.random.randn(1, 1, M).astype(np.float32) Wl1i = np.concatenate((Wl1, np.ones(Wl1.shape[0:-1] + (1,))), axis=-1) Wgrdi = np.hstack((np.ones(M,), np.zeros((1,)))) opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': False, 'MaxMainIter': 50, 'AutoRho': {'Enabled': False}}) opt['L1Weight'] = Wl1i opt['GradWeight'] = Wgrdi b = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, D, s, msk, lmbda, mu, opt) X1 = b.solve() opt['L1Weight'] = Wl1 opt['GradWeight'] = 1.0 X2 = cucbpdn.cbpdngrdmsk(D, s, msk, lmbda, mu, opt) assert(sm.mse(X1, X2) < 1e-10)
def test_12(self): Nr = 32 Nc = 31 Nd = 5 M = 4 D = np.random.randn(Nd, Nd, M).astype(np.float32) s = np.random.randn(Nr, Nc).astype(np.float32) frc = 0.5 msk = su.rndmask(s.shape, frc, dtype=np.float32) s *= msk lmbda = 1e-1 mu = 1e-2 # Since cucbpdn.cbpdngrdmsk automatically ensures that the ℓ2 of # gradient term is not applied to the AMS impulse filter, while # cbpdn.AddMaskSim does not, we have to pass a GradWeight array # with a zero entry corresponding to the AMS impulse filter to # cbpdn.AddMaskSim Wgrdi = np.hstack((np.ones(M,), np.zeros((1,)))) opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': False, 'MaxMainIter': 50, 'AutoRho': {'Enabled': False}}) opt['GradWeight'] = Wgrdi b = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, D, s, msk, lmbda, mu, opt) X1 = b.solve() opt['GradWeight'] = 1.0 X2 = cucbpdn.cbpdngrdmsk(D, s, msk, lmbda, mu, opt) assert(sm.mse(X1, X2) < 1e-10)
def test_14(self): Nr = 32 Nc = 31 Nd = 5 M = 4 D = np.random.randn(Nd, Nd, M).astype(np.float32) s = np.random.randn(Nr, Nc).astype(np.float32) frc = 0.5 msk = su.rndmask(s.shape, frc, dtype=np.float32) s *= msk lmbda = 1e-1 mu = 1e-2 # Create a random ℓ2 of gradient term weighting array. There is no # need to extend this array to account for the AMS impulse filter # since this is taken care of automatically by cucbpdn.cbpdngrdmsk Wgrd = np.random.randn(M).astype(np.float32) # Append a zero entry to the GradWeight array, corresponding to # the impulse filter appended to the dictionary by cbpdn.AddMaskSim, # since this is not done automatically by cbpdn.AddMaskSim Wgrdi = np.hstack((Wgrd, np.zeros((1,)))) opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': False, 'MaxMainIter': 50, 'AutoRho': {'Enabled': False}}) opt['GradWeight'] = Wgrdi b = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, D, s, msk, lmbda, mu, opt) X1 = b.solve() opt['GradWeight'] = Wgrd X2 = cucbpdn.cbpdngrdmsk(D, s, msk, lmbda, mu, opt) assert(sm.mse(X1, X2) < 1e-10)
def test_13(self): Nr = 32 Nc = 31 Nd = 5 M = 4 D = np.random.randn(Nd, Nd, M).astype(np.float32) s = np.random.randn(Nr, Nc).astype(np.float32) frc = 0.5 msk = su.rndmask(s.shape, frc, dtype=np.float32) s *= msk lmbda = 1e-1 mu = 1e-2 # Create a random ℓ1 term weighting array. There is no need to # extend this array to account for the AMS impulse filter since # this is taken care of automatically by cucbpdn.cbpdngrdmsk Wl1 = np.random.randn(1, 1, M).astype(np.float32) # Append a zero entry to the L1Weight array, corresponding to # the impulse filter appended to the dictionary by cbpdn.AddMaskSim, # since this is not done automatically by cbpdn.AddMaskSim Wl1i = np.concatenate((Wl1, np.zeros(Wl1.shape[0:-1] + (1, ))), axis=-1) # Since cucbpdn.cbpdngrdmsk automatically ensures that the ℓ2 of # gradient term is not applied to the AMS impulse filter, while # cbpdn.AddMaskSim does not, we have to pass a GradWeight array # with a zero entry corresponding to the AMS impulse filter to # cbpdn.AddMaskSim Wgrdi = np.hstack((np.ones(M, ), np.zeros((1, )))) opt = cbpdn.ConvBPDNGradReg.Options({ 'Verbose': False, 'MaxMainIter': 50, 'AutoRho': { 'Enabled': False } }) opt['L1Weight'] = Wl1i opt['GradWeight'] = Wgrdi b = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, D, s, msk, lmbda, mu, opt) X1 = b.solve() opt['L1Weight'] = Wl1 opt['GradWeight'] = 1.0 X2 = cucbpdn.cbpdngrdmsk(D, s, msk, lmbda, mu, opt) assert (sm.mse(X1, X2) < 1e-10)
opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': True, 'MaxMainIter': 20, 'HighMemSolve': True, 'LinSolveCheck': False, 'RelStopTol': 2e-3, 'AuxVarObj': False, 'AutoRho': {'Enabled': False}}) # Initialise and run AddMaskSim/ConvBPDNGradReg object opt['GradWeight'] = wgrd b = cbpdn.AddMaskSim(cbpdn.ConvBPDNGradReg, D, shw, msk, lmbda, mu, opt) X1 = b.solve() print("AddMaskSim/ConvBPDNGradReg solve time: %.2fs" % b.timer.elapsed('solve')) # Time CUDA AddMaskSim/ConvBPDNGradReg solve opt['GradWeight'] = 1.0 t = util.Timer() with util.ContextTimer(t): X2 = cucbpdn.cbpdngrdmsk(D, shw, msk, lmbda, mu, opt) print("GPU AddMaskSim/ConvBPDNGradReg solve time: %.2fs" % t.elapsed()) print("GPU time improvement factor: %.1f" % (b.timer.elapsed('solve') / t.elapsed())) # Compare CPU and GPU solutions print("CPU solution: min: %.4e max: %.4e l1: %.4e" % (X1.min(), X1.max(), np.sum(np.abs(X1)))) print("GPU solution: min: %.4e max: %.4e l1: %.4e" % (X2.min(), X2.max(), np.sum(np.abs(X2)))) print("CPU/GPU MSE: %.2e SNR: %.2f dB" % (sm.mse(X1, X2), sm.snr(X1, X2)))