def test_15(self): x = np.linspace(-1, 1, 21) sprm, sfvl, fvmx, sidx = util.grid_search(fnv, (x, )) assert np.abs(sprm[0][0] - 0.1) < 1e-14 assert np.abs(sprm[0][1] - 0.5) < 1e-14 assert sidx[0][0] == 11 assert sidx[0][1] == 15
def test_15(self): x = np.linspace(-1, 1, 21) sprm, sfvl, fvmx, sidx = util.grid_search(fnv, (x,)) assert np.abs(sprm[0][0] - 0.1) < 1e-14 assert np.abs(sprm[0][1] - 0.5) < 1e-14 assert sidx[0][0] == 11 assert sidx[0][1] == 15
""" Select regularization parameter $\lambda$ by evaluating the error in recovering the sparse representation over a logarithmicaly spaced grid. (The reference representation is assumed to be known, which is not realistic in a real application.) A function is defined that evalues the BPDN recovery error for a specified $\lambda$, and this function is evaluated in parallel by :func:`sporco.util.grid_search`. """ # Function computing reconstruction error at lmbda def evalerr(prm): lmbda = prm[0] b = bpdn.BPDN(D, s, lmbda, opt) x = b.solve() return np.sum(np.abs(x-x0)) # Parallel evalution of error function on lmbda grid lrng = np.logspace(1, 2, 20) sprm, sfvl, fvmx, sidx = util.grid_search(evalerr, (lrng,)) lmbda = sprm[0] print('Minimum ℓ1 error: %5.2f at 𝜆 = %.2e' % (sfvl, lmbda)) """ Once the best $\lambda$ has been determined, run BPDN with verbose display of ADMM iteration statistics. """ # Initialise and run BPDN object for best lmbda opt['Verbose'] = True b = bpdn.BPDN(D, s, lmbda, opt) x = b.solve() print("BPDN solve time: %.2fs" % b.timer.elapsed('solve'))
def test_08(self): x = np.linspace(-1, 1, 21) sprm, sfvl, fvmx, sidx = util.grid_search(fn, (x, )) assert (np.abs(sprm[0] - 0.1) < 1e-14) assert (sidx[0] == 11)
'AutoRho' : {'RsdlTarget' : 1.0}}) # Function computing reconstruction error for (lmbda, mu) pair def evalerr(prm): lmbda = prm[0] mu = prm[1] b = bpdn.BPDNJoint(D, s, lmbda, mu, opt) x = b.solve() return np.sum(np.abs(x-x0)) # Parallel evalution of error function on lmbda,mu grid lrng = np.logspace(-4, 0.5, 10) mrng = np.logspace(0.5, 1.6, 10) sprm, sfvl, fvmx, sidx = util.grid_search(evalerr, (lrng, mrng)) lmbda = sprm[0] mu = sprm[1] print('Minimum ℓ1 error: %5.2f at (𝜆,μ) = (%.2e, %.2e)' % (sfvl, lmbda, mu)) # Initialise and run BPDNJoint object for best lmbda and mu opt['Verbose'] = True b = bpdn.BPDNJoint(D, s, lmbda, mu, opt) b.solve() print("BPDNJoint solve time: %.2fs" % b.runtime) # Display recovery results fig1 = plot.figure(1, figsize=(6,8)) plot.subplot(1,2,1)
# Select Lanczos kernel order depending on PSF shape if shape == 'complex' or shape == 'narrow': K = 5 else: K = 10 # Load reference PSF psffile = os.path.join(psfpath, '%s.npz' % shape) npz = np.load(psffile, allow_pickle=True) psfref = npz['refpsf'].item()[M] # Evaluate performance over selected parameter ranges perf = partial(psf_est_performance, K=K, img=img, psfref=psfref) sprm, sfvl, fvmx, sidx = grid_search( perf, (paramranges['sigma0'], paramranges['lmbdaX'], paramranges['lmbdaG'], paramranges['rhoX'], paramranges['LG']), fmin=False, nproc=nproc) # Add results for this image to results dict results[basename] = { 'shape': shape, 'pps': pps, 'noise': noise, 'K': K, 'sprm': sprm, 'sfvl': sfvl, 'fvmx': fvmx, 'sidx': sidx }
# Skip input images for different noise levels if noise != slct_noise: continue basename = '%s_d%03d_n%7.1e.npz' % (shape, pps, noise) print('Computing parameters for %s' % starfile) stars = np.load(starfile) pos = np.load(posfile) # Load reference PSF psffile = os.path.join(psfpath, '%s.npz' % shape) npz = np.load(psffile, allow_pickle=True) psfref = npz['refpsf'].item()[M] # Evaluate performance over selected parameter ranges perf = partial(psf_est_performance, stars=stars, pos=pos, psfref=psfref) sprm, sfvl, fvmx, sidx = grid_search( perf, (paramranges['n_comp'], paramranges['ksig'], paramranges['n_scales'], paramranges['ksig_init'], paramranges['psf_size'], paramranges['n_eigenvects']), fmin=False, nproc=nproc) # Add results for this image to results dict results[basename] = {'shape': shape, 'pps': pps, 'noise': noise, 'sprm': sprm, 'sfvl': sfvl, 'fvmx': fvmx, 'sidx': sidx} # Save data to NPZ file np.savez(rsltfile, paramranges=paramranges, results=results)