예제 #1
0
"""
Define an `x` array and three 1-d functions of it.
"""

x = np.linspace(-1, 1, 101)
y1 = np.abs(x)
y2 = np.abs(x)**1.5
y3 = x**2


"""
Plot the three functions on the same axes.
"""

plot.plot(np.stack((y1, y2, y3)).T, x, xlbl='x', ylbl='y',
        title='Plot Example', lgnd=('$|x|$', '$|x|^{(3/2)}$', '$x^2$'),
        lglc='upper center')


"""
We can also create a plot and then add to it. In this case we need to create the figure object separately and pass it as argument to the :func:`.plot.plot` function so that it doesn't automatically call `fig.show` after the first plot call.
"""

fig = plot.figure()
plot.plot(np.stack((y1, y2, y3)).T, x, xlbl='x', ylbl='y',
        title='Plot Example', lgnd=('$|x|$', '$|x|^{(3/2)}$', '$x^2$'),
        lglc='upper center', fig=fig)
plot.plot(y1[::5], x[::5], lw=0, ms=8.0, marker='o', fig=fig)
fig.show()

예제 #2
0
파일: bpdndl.py 프로젝트: bwohlberg/sporco
fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), title='D0', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1), title='D1', fig=fig)
fig.show()


"""
Get iterations statistics from solver object and plot functional value, ADMM primary and dual residuals, and automatically adjusted ADMM penalty parameter against the iteration number.
"""

its = d.getitstat()
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 3, 1)
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 3, 2)
plot.plot(np.vstack((its.XPrRsdl, its.XDlRsdl, its.DPrRsdl,
          its.DDlRsdl)).T, ptyp='semilogy', xlbl='Iterations',
          ylbl='Residual', lgnd=['X Primal', 'X Dual', 'D Primal', 'D Dual'],
          fig=fig)
plot.subplot(1, 3, 3)
plot.plot(np.vstack((its.XRho, its.DRho)).T, xlbl='Iterations',
          ylbl='Penalty Parameter', ptyp='semilogy',
          lgnd=['$\\rho_X$', '$\\rho_D$'], fig=fig)
fig.show()


# Wait for enter on keyboard
input()
예제 #3
0
print("Denoised median image PSNR: %5.2f dB" % sm.psnr(img, imgd_median))


"""
Display the reference, noisy, and denoised images.
"""

fig = plot.figure(figsize=(14, 14))
plot.subplot(2, 2, 1)
plot.imview(img, title='Reference', fig=fig)
plot.subplot(2, 2, 2)
plot.imview(imgn, title='Noisy', fig=fig)
plot.subplot(2, 2, 3)
plot.imview(imgd_mean, title='SC mean Result', fig=fig)
plot.subplot(2, 2, 4)
plot.imview(imgd_median, title='SC median Result', fig=fig)
fig.show()


"""
Plot functional evolution during ADMM iterations.
"""

its = b.getitstat()
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional')



# Wait for enter on keyboard
input()
예제 #4
0
fig1 = plot.figure(1, figsize=(14,14))
plot.subplot(2,2,1)
plot.imview(sl, fgrf=fig1, title='Lowpass component')
plot.subplot(2,2,2)
plot.imview(np.sum(abs(X), axis=b.cri.axisM).squeeze(), fgrf=fig1,
            fltscl=True, title='Main representation')
plot.subplot(2,2,3)
plot.imview(imgr, fgrf=fig1, title='Reconstructed image')
plot.subplot(2,2,4)
plot.imview(imgr - img, fgrf=fig1, fltscl=True,
            title='Reconstruction difference')
fig1.show()


# Plot functional value, residuals, and rho
its = b.getitstat()
fig2 = plot.figure(2, figsize=(21,7))
plot.subplot(1,3,1)
plot.plot(its.ObjFun, fgrf=fig2, xlbl='Iterations', ylbl='Functional')
plot.subplot(1,3,2)
plot.plot(np.vstack((its.PrimalRsdl, its.DualRsdl)).T, fgrf=fig2,
          ptyp='semilogy', xlbl='Iterations', ylbl='Residual',
          lgnd=['Primal', 'Dual'])
plot.subplot(1,3,3)
plot.plot(its.Rho, fgrf=fig2, xlbl='Iterations', ylbl='Penalty Parameter')
fig2.show()


# Wait for enter on keyboard
input()
예제 #5
0
def plot(*args, **kwargs):
    warnings.warn("sporco.util.plot is deprecated: use sporco.plot.plot",
                  PendingDeprecationWarning)
    return spl.plot(*args, **kwargs)
예제 #6
0
print("ConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve'), "\n")

# Display dictionaries
D1 = D1.squeeze()
fig1 = plot.figure(1, figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), fgrf=fig1, title='D0')
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1, dsz), fgrf=fig1, title='D1')
fig1.show()

# Plot functional value and residuals
its = d.getitstat()
fig2 = plot.figure(2, figsize=(21, 7))
plot.subplot(1, 3, 1)
plot.plot(its.ObjFun, fgrf=fig2, xlbl='Iterations', ylbl='Functional')
plot.subplot(1, 3, 2)
plot.plot(np.vstack((its.XPrRsdl, its.XDlRsdl, its.DPrRsdl, its.DDlRsdl)).T,
          fgrf=fig2,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
          lgnd=['X Primal', 'X Dual', 'D Primal', 'D Dual'])
plot.subplot(1, 3, 3)
plot.plot(np.vstack((its.XRho, its.DRho)).T,
          fgrf=fig2,
          xlbl='Iterations',
          ylbl='Penalty Parameter',
          ptyp='semilogy',
          lgnd=['$\\rho_X$', '$\\rho_D$'])
fig2.show()
예제 #7
0
Initialise and run BPDN object
"""

b2 = bpdn.BPDN(D, s, lmbda, opt)
x2 = b2.solve()

print("BPDN robust PGM backtracking solve time: %.2fs" %
      b2.timer.elapsed('solve'))
"""
Plot comparison of reference and recovered representations.
"""

plot.plot(np.hstack((x0, x1, x2)),
          alpha=0.5,
          title='Sparse representation',
          lgnd=[
              'Reference', 'Reconstructed (Std Backtrack)',
              'Reconstructed (Robust Backtrack)'
          ])
"""
Plot functional value, residual, and L
"""

its1 = b1.getitstat()
its2 = b2.getitstat()
fig = plot.figure(figsize=(21, 7))
plot.subplot(1, 3, 1)
plot.plot(its1.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.plot(its2.ObjFun,
          xlbl='Iterations',
          ylbl='Functional',
예제 #8
0
# Display dictionaries
D1 = D1.squeeze()
fig1 = plot.figure(1, figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), fgrf=fig1, title='D0')
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1), fgrf=fig1, title='D1')
fig1.show()

# Plot functional value and residuals
itsx = xstep.getitstat()
itsd = dstep.getitstat()
fig2 = plot.figure(2, figsize=(21, 7))
plot.subplot(1, 3, 1)
plot.plot(itsx.ObjFun, fgrf=fig2, xlbl='Iterations', ylbl='Functional')
plot.subplot(1, 3, 2)
plot.plot(np.vstack(
    (itsx.PrimalRsdl, itsx.DualRsdl, itsd.PrimalRsdl, itsd.DualRsdl)).T,
          fgrf=fig2,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
          lgnd=['X Primal', 'X Dual', 'D Primal', 'D Dual'])
plot.subplot(1, 3, 3)
plot.plot(np.vstack((itsx.Rho, itsd.Rho)).T,
          fgrf=fig2,
          xlbl='Iterations',
          ylbl='Penalty Parameter',
          ptyp='semilogy',
          lgnd=['Rho', 'Sigma'])
예제 #9
0
plot.imview(util.tiledict(D11), title='D1 Nesterov', fig=fig)
plot.subplot(2, 2, 3)
plot.imview(util.tiledict(D12), title='D1 Linear', fig=fig)
plot.subplot(2, 2, 4)
plot.imview(util.tiledict(D13), title='D1 GenLinear', fig=fig)
fig.show()
"""
Get iterations statistics from CCMOD solver object and plot functional value, and residuals.
"""

its1 = c1.getitstat()
its2 = c2.getitstat()
its3 = c3.getitstat()
fig = plot.figure(figsize=(15, 5))
plot.subplot(1, 2, 1)
plot.plot(its1.DFid, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.plot(its2.DFid, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.plot(its3.DFid,
          xlbl='Iterations',
          ylbl='Functional',
          lgnd=['Nesterov', 'Linear', 'GenLinear'],
          fig=fig)
plot.subplot(1, 2, 2)
plot.plot(its1.Rsdl,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
          fig=fig)
plot.plot(its2.Rsdl,
          ptyp='semilogy',
          xlbl='Iterations',
예제 #10
0
lmbda = 2.98e1

print("")
b = bpdn.BPDN(D, s, lmbda, opt)
x = b.solve()

print("BPDN standard FISTA backtracking solve time: %.2fs" %
      b.timer.elapsed('solve'))
print("")


"""
Plot comparison of reference and recovered representations.
"""

plot.plot(np.hstack((x0, x)), title='Sparse representation (standard FISTA)',
          lgnd=['Reference', 'Reconstructed'])


"""
Plot lmbda error curve, functional value, residuals, and rho
"""

its = b.getitstat()
fig = plot.figure(figsize=(21, 7))
plot.subplot(1, 3, 1)
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 3, 2)
plot.plot(its.Rsdl, ptyp='semilogy', xlbl='Iterations', ylbl='Residual',
          fig=fig)
plot.subplot(1, 3, 3)
plot.plot(its.L, xlbl='Iterations',
예제 #11
0
"""
Load dictionary and display it. Grouped elements are displayed on the same axis.
"""

M = 4
D = np.load(os.path.join('data', 'pianodict.npz'))['elems']
fig = plot.figure(figsize=(10, 16))
for i in range(24):
    plot.subplot(8, 3, i + 1, title=f'{librosa.midi_to_note(i+60)}',
                 ylim=[-6, 6])
    plot.gca().get_xaxis().set_visible(False)
    plot.gca().get_yaxis().set_visible(False)
    plot.gca().set_frame_on(False)
    for k in range(M):
        plot.plot(D[M*(i+1)-k-1], fig=fig)
fig.show()


"""
Set :class:`.admm.cbpdn.ConvBPDNInhib` solver options.
"""

lmbda = 1e-1
mu = 1e1
gamma = 1e0
opt = cbpdnin.ConvBPDNInhib.Options({'Verbose': True, 'MaxMainIter': 500,
                                     'RelStopTol': 5e-2, 'AuxVarObj': False,
                                     'rho': 100, 'AutoRho': {'Enabled': False}})

예제 #12
0
    'Backtrack': BacktrackRobust()
})
"""
Initialise and run PGM solver.
"""

bp = pbpdn.BPDN(D, s, lmbda, opt_pgm)
xp = bp.solve()

print("PGM BPDN solve time: %.2fs" % bp.timer.elapsed('solve'))
"""
Plot comparison of reference and recovered representations.
"""

plot.plot(np.hstack((x0, xa, xp)),
          alpha=0.5,
          title='Sparse representation',
          lgnd=['Reference', 'Reconstructed (ADMM)', 'Reconstructed (PGM)'])
"""
Plot functional value, residual, and L
"""

itsa = ba.getitstat()
itsp = bp.getitstat()
fig = plot.figure(figsize=(21, 7))
plot.subplot(1, 3, 1)
plot.plot(itsa.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.plot(itsp.ObjFun,
          xlbl='Iterations',
          ylbl='Functional',
          lgnd=['ADMM', 'PGM'],
          fig=fig)
예제 #13
0
s_clean = s_clean[:, np.newaxis]
s_noise = s_noise[:, np.newaxis]

Maxiter = 200
opt_par = cbpdn.ConvBPDN.Options({'Verbose': True, 'MaxMainIter': Maxiter,
                                  'RelStopTol': 1e-4, 'AuxVarObj': False,
                                  'AutoRho': {'Enabled': True}})

# solve with real valued signal with real valued dictionary
b_r = cbpdn.ConvBPDN(D0.real, s_noise.real, lmbda_0, opt=opt_par, dimK=None, dimN=dimN)
x_r = b_r.solve()
fig, ax = plot.subplots(nrows=2, ncols=3, sharex=True, sharey=True, figsize=(18, 8))

rec_r = b_r.reconstruct().squeeze()
fig.suptitle('real value solver ' + str(np.count_nonzero(x_r) * 100 / x_r.size) + '% non zero elements', fontsize=14)
plot.plot(s_clean.real, title='clean(real)', fig=fig, ax=ax[0, 0])
plot.plot(s_clean.imag, title='clean(imag)', fig=fig, ax=ax[1, 0])

plot.plot(s_noise.real, title='corrupted(real)', fig=fig, ax=ax[0, 1])
plot.plot(s_noise.imag, title='corrupted(imag)', fig=fig, ax=ax[1, 1])

plot.plot(rec_r.real, title='reconstructed(real)', fig=fig, ax=ax[0, 2])
plot.plot(rec_r.imag, title='reconstructed(imag)', fig=fig, ax=ax[1, 2])

fig.show()
# solve with a complex valued signal with complex valued dictionary
b_c = comcbpdn.ComplexConvBPDN(D0, s_noise, lmbda_0, opt_par, None, dimN)
x_c = b_c.solve()
rec_c = b_c.reconstruct().squeeze()

fig, ax = plot.subplots(nrows=2, ncols=3, sharex=True, sharey=True, figsize=(18, 8))
예제 #14
0
D1 = d.getdict()
print("OnlineConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve'))


"""
Display initial and final dictionaries.
"""

D1 = D1.squeeze()
fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), title='D0', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1), title='D1', fig=fig)
fig.show()


"""
Get iterations statistics from solver object and plot functional value.
"""

its = d.getitstat()
fig = plot.figure(figsize=(7, 7))
plot.plot(np.vstack((its.DeltaD, its.Eta)).T, xlbl='Iterations',
          lgnd=('Delta D', 'Eta'), fig=fig)
fig.show()


# Wait for enter on keyboard
input()
예제 #15
0
Display initial and final dictionaries.
"""

D1 = d.getdict().reshape((8, 8, D0.shape[1]))
D0 = D0.reshape(8, 8, D0.shape[-1])
fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), title='D0', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1), title='D1', fig=fig)
fig.show()
"""
Get iterations statistics from solver object and plot functional value and PGM residuals.
"""

its = d.getitstat()
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 2, 1)
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 2, 2)
plot.plot(np.vstack((its.XRsdl, its.DRsdl)).T,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
          lgnd=['X', 'D'],
          fig=fig)
fig.show()

# Wait for enter on keyboard
input()
예제 #16
0
def plot(*args, **kwargs):
    warnings.warn(
        "sporco.util.plot is deprecated: please use sporco.plot.plot")
    return spl.plot(*args, **kwargs)
예제 #17
0
fig.suptitle('ConvProdDictL1L1GrdJoint Results (false colour, '
             'bands 10, 20, 30)')
plot.imview(img[..., 10:40:10], title='Reference', ax=ax[0], fig=fig)
plot.imview(imgn[..., 10:40:10], title='Noisy', ax=ax[1], fig=fig)
plot.imview(imgd[..., 10:40:10], title='Denoised', ax=ax[2], fig=fig)
fig.show()
"""
Get iterations statistics from solver object and plot functional value, ADMM primary and dual residuals, and automatically adjusted ADMM penalty parameter against the iteration number.
"""

its = b.getitstat()
ObjFun = [float(x) for x in its.ObjFun]
PrimalRsdl = [float(x) for x in its.PrimalRsdl]
DualRsdl = [float(x) for x in its.DualRsdl]
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 3, 1)
plot.plot(ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 3, 2)
plot.plot(np.vstack((PrimalRsdl, DualRsdl)).T,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
          lgnd=['Primal', 'Dual'],
          fig=fig)
plot.subplot(1, 3, 3)
plot.plot(its.Rho, xlbl='Iterations', ylbl='Penalty Parameter', fig=fig)
fig.show()

# Wait for enter on keyboard
input()
예제 #18
0
Display original and reconstructed images.
"""

fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(img, title='Original', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(imgr, title='Reconstructed', fig=fig)
fig.show()


"""
Get iterations statistics from solver object and plot functional value, ADMM primary and dual residuals, and automatically adjusted ADMM penalty parameter against the iteration number.
"""

its = b.getitstat()
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 3, 1)
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 3, 2)
plot.plot(its.Rsdl, ptyp='semilogy', xlbl='Iterations', ylbl='Residual',
          fig=fig)
plot.subplot(1, 3, 3)
plot.plot(its.L, xlbl='Iterations',
          ylbl='Inverse of Gradient Step Parameter', fig=fig)
fig.show()


# Wait for enter on keyboard
input()
예제 #19
0
 def test_01(self):
     x = np.linspace(-1, 1, 20)
     y = x**2
     plot.plot(y, title='Plot Test', xlbl='x', ylbl='y', lgnd=('Legend'))
     plot.close()
예제 #20
0
"""
Define an `x` array and three 1-d functions of it.
"""

x = np.linspace(-1, 1, 101)
y1 = np.abs(x)
y2 = np.abs(x)**1.5
y3 = x**2
"""
Plot the three functions on the same axes.
"""

plot.plot(np.stack((y1, y2, y3)).T,
          x,
          xlbl='x',
          ylbl='y',
          title='Plot Example',
          lgnd=('$|x|$', '$|x|^{(3/2)}$', '$x^2$'),
          lglc='upper center')
"""
We can also create a plot and then add to it. In this case we need to create the figure object separately and pass it as argument to the :func:`.plot.plot` function so that it doesn't automatically call `fig.show` after the first plot call.
"""

fig = plot.figure()
plot.plot(np.stack((y1, y2, y3)).T,
          x,
          xlbl='x',
          ylbl='y',
          title='Plot Example',
          lgnd=('$|x|$', '$|x|^{(3/2)}$', '$x^2$'),
          lglc='upper center',
예제 #21
0
 def test_02(self):
     x = np.linspace(-1, 1, 20)
     y = x**2
     fig = plot.figure()
     plot.plot(y, x=x, title='Plot Test', xlbl='x', ylbl='y', fig=fig)
     plot.close()
예제 #22
0
# Parallel evalution of error function on lmbda grid
lrng = np.logspace(1, 2, 10)
sprm, sfvl, fvmx, sidx = util.grid_search(evalerr, (lrng,))
lmbda = sprm[0]
print('Minimum ℓ1 error: %5.2f at 𝜆 = %.2e' % (sfvl, lmbda))


# Initialise and run BPDN object for best lmbda
opt['Verbose'] = True
b = bpdn.BPDN(D, s, lmbda, opt)
b.solve()
print("BPDN solve time: %.2fs" % b.runtime)


# Plot results
plot.plot(np.hstack((x0, b.Y)), fgnm=1, title='Sparse representation',
          lgnd=['Reference', 'Reconstructed'])


# Plot lmbda error curve, functional value, residuals, and rho
its = b.getitstat()
fig2 = plot.figure(2, figsize=(14,14))
plot.subplot(2,2,1)
plot.plot(fvmx, x=lrng, ptyp='semilogx', xlbl='$\lambda$',
          ylbl='Error', fgrf=fig2)
plot.subplot(2,2,2)
plot.plot(its.ObjFun, fgrf=fig2, ptyp='semilogy', xlbl='Iterations',
          ylbl='Functional')
plot.subplot(2,2,3)
plot.plot(np.vstack((its.PrimalRsdl, its.DualRsdl)).T, fgrf=fig2,
          ptyp='semilogy', xlbl='Iterations', ylbl='Residual',
          lgnd=['Primal', 'Dual']);
예제 #23
0
plot.subplot(1, 3, 1)
plot.imview(util.tiledict(D0), title='D0', fig=fig)
plot.subplot(1, 3, 2)
plot.imview(util.tiledict(D11), title='D1 Cauchy', fig=fig)
plot.subplot(1, 3, 3)
plot.imview(util.tiledict(D12), title='D1 BB', fig=fig)
fig.show()
"""
Get iterations statistics from CMOD solver object and plot functional value, residuals, and automatically adjusted L against the iteration number.
"""

its1 = c1.getitstat()
its2 = c2.getitstat()
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 3, 1)
plot.plot(its1.DFid, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.plot(its2.DFid,
          xlbl='Iterations',
          ylbl='Functional',
          lgnd=['Cauchy', 'BB'],
          fig=fig)
plot.subplot(1, 3, 2)
plot.plot(its1.Rsdl,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
          fig=fig)
plot.plot(its2.Rsdl,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
예제 #24
0
d.display_end()
D1 = cp2np(d.getdict())
print("OnlineConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve'))
"""
Display initial and final dictionaries.
"""

D1 = D1.squeeze()
fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), title='D0', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1), title='D1', fig=fig)
fig.show()
"""
Get iterations statistics from solver object and plot functional value.
"""

its = d.getitstat()
DeltaD = [float(x) for x in its.DeltaD]
fig = plot.figure(figsize=(7, 7))
plot.plot(np.vstack((DeltaD, its.Eta)).T,
          xlbl='Iterations',
          lgnd=('Delta D', 'Eta'),
          fig=fig)
fig.show()

# Wait for enter on keyboard
input()
예제 #25
0
D1 = D1.squeeze()
fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), title='D0', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1, dsz), title='D1', fig=fig)
fig.show()
"""
Get iterations statistics from solver object and plot functional value, residuals, and automatically adjusted gradient step parameters against the iteration number.
"""

its = d.getitstat()
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 3, 1)
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 3, 2)
plot.plot(np.vstack((its.X_Rsdl, its.D_Rsdl)).T,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
          lgnd=['X', 'D'],
          fig=fig)
plot.subplot(1, 3, 3)
plot.plot(np.vstack((its.X_L, its.D_L)).T,
          xlbl='Iterations',
          ylbl='Inverse of Gradient Step Parameter',
          ptyp='semilogy',
          lgnd=['$L_X$', '$L_D$'],
          fig=fig)
fig.show()
예제 #26
0
def plot_psf_sections(ref, rca, cdl, grd, title=None, maxcnt=True):

    if maxcnt:
        gc, gr = np.unravel_index(ref.argmax(), ref.shape)
    else:
        gc = ref.shape[0] // 2
        gr = ref.shape[1] // 2
    fig, ax = plot.subplots(nrows=1, ncols=2, sharex=True, sharey=True,
                            figsize=(16, 5))
    if title is not None:
        fig.suptitle(title, fontsize=14)
    plot.plot(ref[gc], grd, c=clrs[0], lw=2, alpha=0.75, fig=fig, ax=ax[0])
    plot.plot(rca[gc], grd, c=clrs[1], lw=2, alpha=0.75, fig=fig, ax=ax[0])
    plot.plot(cdl[gc], grd, c=clrs[2], lw=2, alpha=0.75, title='Row slice',
              lgnd=('Reference', 'RCA', 'CDL'), fig=fig, ax=ax[0])
    plot.plot(ref[:, gr], grd, c=clrs[0], lw=2, alpha=0.75, fig=fig, ax=ax[1])
    plot.plot(rca[:, gr], grd, c=clrs[1], lw=2, alpha=0.75, fig=fig, ax=ax[1])
    plot.plot(cdl[:, gr], grd, c=clrs[2], lw=2, alpha=0.75,
              title='Column slice', lgnd=('Reference', 'RCA', 'CDL'),
              fig=fig, ax=ax[1])
    fig.show()
    return fig, ax
예제 #27
0
"""

fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(img, title='Original', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(imgr, title='Reconstructed', fig=fig)
fig.show()
"""
Get iterations statistics from solver object and plot functional value, ADMM primary and dual residuals, and automatically adjusted ADMM penalty parameter against the iteration number.
"""

its = b.getitstat()
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 3, 1)
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 3, 2)
plot.plot(its.Rsdl,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
          fig=fig)
plot.subplot(1, 3, 3)
plot.plot(its.L,
          xlbl='Iterations',
          ylbl='Inverse of Gradient Step Parameter',
          fig=fig)
fig.show()

# Wait for enter on keyboard
input()
예제 #28
0
d = prlcnscdl.ConvBPDNDictLearn_Consensus(D0, sh, lmbda, opt)
D1 = d.solve()
print("ConvBPDNDictLearn_Consensus solve time: %.2fs" %
      d.timer.elapsed('solve'))


"""
Display initial and final dictionaries.
"""

D1 = D1.squeeze()
fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), title='D0', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1), title='D1', fig=fig)
fig.show()


"""
Get iterations statistics from solver object and plot functional value
"""

its = d.getitstat()
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional')


# Wait for enter on keyboard
input()
예제 #29
0
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0), title='D0', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1), title='D1', fig=fig)
fig.show()


"""
Plot functional value and residuals.
"""

itsx = xstep.getitstat()
itsd = dstep.getitstat()
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 3, 1)
plot.plot(itsx.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 3, 2)
plot.plot(np.vstack((itsx.PrimalRsdl, itsx.DualRsdl, itsd.PrimalRsdl,
          itsd.DualRsdl)).T, ptyp='semilogy', xlbl='Iterations',
          ylbl='Residual', lgnd=['X Primal', 'X Dual', 'D Primal', 'D Dual'],
          fig=fig)
plot.subplot(1, 3, 3)
plot.plot(np.vstack((itsx.Rho, itsd.Rho)).T,  xlbl='Iterations',
          ylbl='Penalty Parameter', ptyp='semilogy', lgnd=['Rho', 'Sigma'],
          fig=fig)
fig.show()


# Wait for enter on keyboard
input()
예제 #30
0
Display original and reconstructed images.
"""

fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(img, title='Original', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(imgr, title='Reconstructed', fig=fig)
fig.show()


"""
Get iterations statistics from solver object and plot functional value, ADMM primary and dual residuals, and automatically adjusted ADMM penalty parameter against the iteration number.
"""

its = b.getitstat()
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 3, 1)
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 3, 2)
plot.plot(np.vstack((its.PrimalRsdl, its.DualRsdl)).T,
          ptyp='semilogy', xlbl='Iterations', ylbl='Residual',
          lgnd=['Primal', 'Dual'], fig=fig)
plot.subplot(1, 3, 3)
plot.plot(its.Rho, xlbl='Iterations', ylbl='Penalty Parameter', fig=fig)
fig.show()


# Wait for enter on keyboard
input()
예제 #31
0
    }
})
"""
Initialise and run BPDNProjL1 object
"""

b = bpdn.BPDNProjL1(D, s, gamma, opt)
x = b.solve()

print("BPDNProjL1 solve time: %.2fs" % b.timer.elapsed('solve'))
"""
Plot comparison of reference and recovered representations.
"""

plot.plot(np.hstack((x0, x)),
          title='Sparse representation',
          lgnd=['Reference', 'Reconstructed'])
"""
Plot functional value, residuals, and rho
"""

its = b.getitstat()
fig = plot.figure(figsize=(20, 5))
plot.subplot(1, 3, 1)
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 3, 2)
plot.plot(np.vstack((its.PrimalRsdl, its.DualRsdl)).T,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
          lgnd=['Primal', 'Dual'],
예제 #32
0
파일: bpdn.py 프로젝트: bwohlberg/sporco
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'))


"""
Plot comparison of reference and recovered representations.
"""

plot.plot(np.hstack((x0, x)), title='Sparse representation',
          lgnd=['Reference', 'Reconstructed'])


"""
Plot lmbda error curve, functional value, residuals, and rho
"""

its = b.getitstat()
fig = plot.figure(figsize=(15, 10))
plot.subplot(2, 2, 1)
plot.plot(fvmx, x=lrng, ptyp='semilogx', xlbl='$\lambda$',
          ylbl='Error', fig=fig)
plot.subplot(2, 2, 2)
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(2, 2, 3)
plot.plot(np.vstack((its.PrimalRsdl, its.DualRsdl)).T,
예제 #33
0
lmbda = 2.98e1

print("")
b = bpdn.BPDN(D, s, lmbda, opt)
x = b.solve()

print("BPDN standard FISTA backtracking solve time: %.2fs" %
      b.timer.elapsed('solve'))
print("")
"""
Plot comparison of reference and recovered representations.
"""

plot.plot(np.hstack((x0, x)),
          title='Sparse representation (standard FISTA)',
          lgnd=['Reference', 'Reconstructed'])
"""
Plot lmbda error curve, functional value, residuals, and rho
"""

its = b.getitstat()
fig = plot.figure(figsize=(21, 7))
plot.subplot(1, 3, 1)
plot.plot(its.ObjFun, xlbl='Iterations', ylbl='Functional', fig=fig)
plot.subplot(1, 3, 2)
plot.plot(its.Rsdl,
          ptyp='semilogy',
          xlbl='Iterations',
          ylbl='Residual',
          fig=fig)