CSC with a Spatial Mask

This example demonstrates the use of cbpdn.AddMaskSim for convolutional sparse coding with a spatial mask [34]. If the sporco-cuda extension is installed and a GPU is available, a GPU accelerated version is used. The example problem is inpainting of randomly distributed corruption of a greyscale image.

from __future__ import print_function
from builtins import input
from builtins import range

import pyfftw   # See
import numpy as np

from sporco import util
from sporco import metric
from sporco import linalg
from sporco import plot
from sporco.admm import tvl2
from sporco.admm import cbpdn
from sporco import cuda

# If running in a notebook, try to use wurlitzer so that output from the CUDA
# code will be properly captured in the notebook.
sys_pipes = util.notebook_system_output()

Load a reference image.

img = util.ExampleImages().image('monarch.png', zoom=0.5, scaled=True,
                                 gray=True, idxexp=np.s_[:, 160:672])

Create random mask and apply to reference image to obtain test image. (The call to numpy.random.seed ensures that the pseudo-random noise is reproducible.)

frc = 0.5
msk = util.rndmask(img.shape, frc, dtype=np.float32)
imgw = msk * img

Define pad and crop functions.

pn = 8
spad = lambda x:  np.pad(x, pn, mode='symmetric')
zpad = lambda x:  np.pad(x, pn, mode='constant')
crop = lambda x: x[pn:-pn, pn:-pn]

Construct padded mask and test image.

mskp = zpad(msk)
imgwp = spad(imgw)

\(\ell_2\)-TV denoising with a spatial mask as a non-linear lowpass filter. The highpass component is the difference between the test image and the lowpass component, multiplied by the mask for faster convergence of the convolutional sparse coding (see [44]).

lmbda = 0.05
opt = tvl2.TVL2Denoise.Options({'Verbose': False, 'MaxMainIter': 200,
                    'DFidWeight': mskp, 'gEvalY': False,
                    'AutoRho': {'Enabled': True}})
b = tvl2.TVL2Denoise(imgwp, lmbda, opt)
sl = b.solve()
sh = mskp * (imgwp - sl)

Load dictionary.

D = util.convdicts()['G:8x8x128']

Set up admm.cbpdn.ConvBPDN options.

lmbda = 2e-2
opt = cbpdn.ConvBPDN.Options({'Verbose': True, 'MaxMainIter': 200,
                    'HighMemSolve': True, 'RelStopTol': 5e-3,
                    'AuxVarObj': False, 'RelaxParam': 1.8,
                    'rho': 5e1*lmbda + 1e-1, 'AutoRho': {'Enabled': False,
                    'StdResiduals': False}})

Construct admm.cbpdn.AddMaskSim wrapper for admm.cbpdn.ConvBPDN and solve via wrapper. This example could also have made use of admm.cbpdn.ConvBPDNMaskDcpl (see example cbpdn_md_gry), which has similar performance in this application, but admm.cbpdn.AddMaskSim has the advantage of greater flexibility in that the wrapper can be applied to a variety of CSC solver objects. If the sporco-cuda extension is installed and a GPU is available, use the CUDA implementation of this combination.

if cuda.device_count() > 0:
    ams = None
    print('%s GPU found: running CUDA solver' % cuda.device_name())
    tm = util.Timer()
    with sys_pipes(), util.ContextTimer(tm):
        X = cuda.cbpdnmsk(D, sh, mskp, lmbda, opt)
    t = tm.elapsed()
    imgr = crop(sl + np.sum(linalg.fftconv(D, X), axis=-1))
    ams = cbpdn.AddMaskSim(cbpdn.ConvBPDN, D, sh, mskp, lmbda, opt=opt)
    X = ams.solve()
    t = ams.timer.elapsed('solve')
    imgr = crop(sl + ams.reconstruct().squeeze())
Tesla K40c GPU found: running CUDA solver
Itn   Fnc       DFid      Regℓ1     r         s         ρ
   0  3.10e+01  4.24e-02  1.55e+03  9.94e-01  1.85e-01  1.10e+00
   1  2.71e+01  2.17e-01  1.35e+03  8.05e-01  2.20e-01  1.10e+00
   2  2.54e+01  3.46e-01  1.25e+03  4.52e-01  1.83e-01  1.10e+00
   3  2.44e+01  4.27e-01  1.20e+03  3.05e-01  1.48e-01  1.10e+00
   4  2.36e+01  4.89e-01  1.16e+03  2.30e-01  1.24e-01  1.10e+00
   5  2.32e+01  5.39e-01  1.13e+03  1.87e-01  1.07e-01  1.10e+00
   6  2.29e+01  5.79e-01  1.12e+03  1.60e-01  9.26e-02  1.10e+00
   7  2.28e+01  6.13e-01  1.11e+03  1.41e-01  8.11e-02  1.10e+00
   8  2.27e+01  6.43e-01  1.10e+03  1.27e-01  7.20e-02  1.10e+00
   9  2.26e+01  6.71e-01  1.10e+03  1.17e-01  6.49e-02  1.10e+00
  10  2.24e+01  6.99e-01  1.08e+03  1.09e-01  5.96e-02  1.10e+00
  11  2.21e+01  7.26e-01  1.07e+03  1.02e-01  5.56e-02  1.10e+00
  12  2.18e+01  7.53e-01  1.05e+03  9.67e-02  5.27e-02  1.10e+00
  13  2.15e+01  7.78e-01  1.04e+03  9.20e-02  5.06e-02  1.10e+00
  14  2.12e+01  8.02e-01  1.02e+03  8.64e-02  4.88e-02  1.10e+00
  15  2.10e+01  8.24e-01  1.01e+03  8.44e-02  4.75e-02  1.10e+00
  16  2.08e+01  8.43e-01  9.95e+02  8.12e-02  4.63e-02  1.10e+00
  17  2.05e+01  8.60e-01  9.84e+02  7.83e-02  4.52e-02  1.10e+00
  18  2.04e+01  8.76e-01  9.74e+02  7.55e-02  4.40e-02  1.10e+00
  19  2.02e+01  8.91e-01  9.66e+02  7.30e-02  4.26e-02  1.10e+00
  20  2.01e+01  9.06e-01  9.59e+02  7.07e-02  4.08e-02  1.10e+00
  21  1.99e+01  9.22e-01  9.47e+02  6.84e-02  3.90e-02  1.10e+00
  22  1.96e+01  9.39e-01  9.31e+02  6.58e-02  3.76e-02  1.10e+00
  23  1.92e+01  9.57e-01  9.10e+02  6.40e-02  3.62e-02  1.10e+00
  24  1.87e+01  9.76e-01  8.86e+02  6.17e-02  3.50e-02  1.10e+00
  25  1.82e+01  9.96e-01  8.62e+02  5.98e-02  3.37e-02  1.10e+00
  26  1.78e+01  1.02e+00  8.40e+02  5.78e-02  3.25e-02  1.10e+00
  27  1.74e+01  1.04e+00  8.19e+02  5.50e-02  3.12e-02  1.10e+00
  28  1.71e+01  1.05e+00  8.01e+02  5.41e-02  3.00e-02  1.10e+00
  29  1.68e+01  1.07e+00  7.86e+02  5.23e-02  2.89e-02  1.10e+00
  30  1.65e+01  1.09e+00  7.73e+02  5.07e-02  2.80e-02  1.10e+00
  31  1.63e+01  1.11e+00  7.61e+02  4.89e-02  2.70e-02  1.10e+00
  32  1.61e+01  1.12e+00  7.51e+02  4.76e-02  2.62e-02  1.10e+00
  33  1.60e+01  1.13e+00  7.42e+02  4.62e-02  2.53e-02  1.10e+00
  34  1.58e+01  1.15e+00  7.34e+02  4.47e-02  2.45e-02  1.10e+00
  35  1.57e+01  1.16e+00  7.27e+02  4.37e-02  2.38e-02  1.10e+00
  36  1.56e+01  1.17e+00  7.19e+02  4.26e-02  2.30e-02  1.10e+00
  37  1.54e+01  1.18e+00  7.12e+02  4.14e-02  2.24e-02  1.10e+00
  38  1.53e+01  1.19e+00  7.03e+02  4.03e-02  2.18e-02  1.10e+00
  39  1.51e+01  1.19e+00  6.94e+02  3.86e-02  2.12e-02  1.10e+00
  40  1.49e+01  1.20e+00  6.85e+02  3.83e-02  2.07e-02  1.10e+00
  41  1.47e+01  1.21e+00  6.75e+02  3.70e-02  2.02e-02  1.10e+00
  42  1.45e+01  1.22e+00  6.66e+02  3.64e-02  1.98e-02  1.10e+00
  43  1.44e+01  1.23e+00  6.57e+02  3.51e-02  1.93e-02  1.10e+00
  44  1.42e+01  1.24e+00  6.50e+02  3.45e-02  1.88e-02  1.10e+00
  45  1.41e+01  1.24e+00  6.43e+02  3.32e-02  1.83e-02  1.10e+00
  46  1.40e+01  1.25e+00  6.36e+02  3.31e-02  1.78e-02  1.10e+00
  47  1.39e+01  1.26e+00  6.31e+02  3.22e-02  1.73e-02  1.10e+00
  48  1.38e+01  1.26e+00  6.25e+02  3.16e-02  1.69e-02  1.10e+00
  49  1.37e+01  1.27e+00  6.19e+02  3.07e-02  1.65e-02  1.10e+00
  50  1.35e+01  1.28e+00  6.14e+02  3.02e-02  1.61e-02  1.10e+00
  51  1.34e+01  1.28e+00  6.08e+02  2.95e-02  1.58e-02  1.10e+00
  52  1.33e+01  1.29e+00  6.02e+02  2.89e-02  1.54e-02  1.10e+00
  53  1.32e+01  1.29e+00  5.97e+02  2.83e-02  1.52e-02  1.10e+00
  54  1.31e+01  1.30e+00  5.92e+02  2.77e-02  1.48e-02  1.10e+00
  55  1.30e+01  1.30e+00  5.87e+02  2.70e-02  1.45e-02  1.10e+00
  56  1.30e+01  1.30e+00  5.83e+02  2.64e-02  1.42e-02  1.10e+00
  57  1.29e+01  1.30e+00  5.78e+02  2.61e-02  1.39e-02  1.10e+00
  58  1.28e+01  1.31e+00  5.74e+02  2.56e-02  1.36e-02  1.10e+00
  59  1.27e+01  1.31e+00  5.69e+02  2.51e-02  1.33e-02  1.10e+00
  60  1.26e+01  1.31e+00  5.65e+02  2.46e-02  1.31e-02  1.10e+00
  61  1.25e+01  1.32e+00  5.60e+02  2.42e-02  1.28e-02  1.10e+00
  62  1.24e+01  1.32e+00  5.56e+02  2.38e-02  1.25e-02  1.10e+00
  63  1.24e+01  1.32e+00  5.52e+02  2.33e-02  1.23e-02  1.10e+00
  64  1.23e+01  1.32e+00  5.47e+02  2.29e-02  1.21e-02  1.10e+00
  65  1.22e+01  1.33e+00  5.43e+02  2.25e-02  1.19e-02  1.10e+00
  66  1.21e+01  1.33e+00  5.38e+02  2.21e-02  1.17e-02  1.10e+00
  67  1.20e+01  1.33e+00  5.34e+02  2.18e-02  1.15e-02  1.10e+00
  68  1.19e+01  1.33e+00  5.30e+02  2.14e-02  1.14e-02  1.10e+00
  69  1.19e+01  1.34e+00  5.27e+02  2.10e-02  1.12e-02  1.10e+00
  70  1.18e+01  1.34e+00  5.23e+02  2.06e-02  1.10e-02  1.10e+00
  71  1.18e+01  1.34e+00  5.20e+02  2.03e-02  1.08e-02  1.10e+00
  72  1.17e+01  1.34e+00  5.18e+02  1.99e-02  1.06e-02  1.10e+00
  73  1.17e+01  1.35e+00  5.15e+02  1.97e-02  1.03e-02  1.10e+00
  74  1.16e+01  1.35e+00  5.13e+02  1.94e-02  1.01e-02  1.10e+00
  75  1.16e+01  1.35e+00  5.10e+02  1.91e-02  9.94e-03  1.10e+00
  76  1.15e+01  1.35e+00  5.08e+02  1.88e-02  9.72e-03  1.10e+00
  77  1.15e+01  1.36e+00  5.05e+02  1.85e-02  9.56e-03  1.10e+00
  78  1.14e+01  1.36e+00  5.02e+02  1.79e-02  9.40e-03  1.10e+00
  79  1.13e+01  1.36e+00  4.99e+02  1.77e-02  9.24e-03  1.10e+00
  80  1.13e+01  1.36e+00  4.95e+02  1.75e-02  9.11e-03  1.10e+00
  81  1.12e+01  1.37e+00  4.92e+02  1.73e-02  8.99e-03  1.10e+00
  82  1.11e+01  1.37e+00  4.89e+02  1.71e-02  8.87e-03  1.10e+00
  83  1.11e+01  1.37e+00  4.86e+02  1.68e-02  8.76e-03  1.10e+00
  84  1.10e+01  1.37e+00  4.83e+02  1.66e-02  8.63e-03  1.10e+00
  85  1.10e+01  1.37e+00  4.80e+02  1.63e-02  8.51e-03  1.10e+00
  86  1.09e+01  1.38e+00  4.78e+02  1.61e-02  8.37e-03  1.10e+00
  87  1.09e+01  1.38e+00  4.75e+02  1.58e-02  8.24e-03  1.10e+00
  88  1.08e+01  1.38e+00  4.73e+02  1.56e-02  8.12e-03  1.10e+00
  89  1.08e+01  1.38e+00  4.71e+02  1.54e-02  8.00e-03  1.10e+00
  90  1.08e+01  1.38e+00  4.69e+02  1.52e-02  7.86e-03  1.10e+00
  91  1.07e+01  1.39e+00  4.67e+02  1.47e-02  7.73e-03  1.10e+00
  92  1.07e+01  1.39e+00  4.65e+02  1.47e-02  7.60e-03  1.10e+00
  93  1.06e+01  1.39e+00  4.63e+02  1.45e-02  7.50e-03  1.10e+00
  94  1.06e+01  1.39e+00  4.61e+02  1.42e-02  7.35e-03  1.10e+00
  95  1.06e+01  1.39e+00  4.59e+02  1.42e-02  7.24e-03  1.10e+00
  96  1.05e+01  1.40e+00  4.57e+02  1.38e-02  7.12e-03  1.10e+00
  97  1.05e+01  1.40e+00  4.55e+02  1.37e-02  7.01e-03  1.10e+00
  98  1.05e+01  1.40e+00  4.54e+02  1.35e-02  6.90e-03  1.10e+00
  99  1.04e+01  1.40e+00  4.52e+02  1.34e-02  6.80e-03  1.10e+00
 100  1.04e+01  1.40e+00  4.50e+02  1.31e-02  6.69e-03  1.10e+00
 101  1.04e+01  1.40e+00  4.49e+02  1.30e-02  6.60e-03  1.10e+00
 102  1.03e+01  1.40e+00  4.47e+02  1.29e-02  6.50e-03  1.10e+00
 103  1.03e+01  1.41e+00  4.45e+02  1.26e-02  6.42e-03  1.10e+00
 104  1.03e+01  1.41e+00  4.43e+02  1.25e-02  6.33e-03  1.10e+00
 105  1.02e+01  1.41e+00  4.42e+02  1.23e-02  6.25e-03  1.10e+00
 106  1.02e+01  1.41e+00  4.40e+02  1.21e-02  6.18e-03  1.10e+00
 107  1.02e+01  1.41e+00  4.38e+02  1.20e-02  6.10e-03  1.10e+00
 108  1.01e+01  1.41e+00  4.36e+02  1.18e-02  6.03e-03  1.10e+00
 109  1.01e+01  1.41e+00  4.34e+02  1.16e-02  5.95e-03  1.10e+00
 110  1.01e+01  1.41e+00  4.33e+02  1.15e-02  5.87e-03  1.10e+00
 111  1.00e+01  1.42e+00  4.31e+02  1.13e-02  5.79e-03  1.10e+00
 112  1.00e+01  1.42e+00  4.29e+02  1.12e-02  5.71e-03  1.10e+00
 113  9.97e+00  1.42e+00  4.28e+02  1.11e-02  5.64e-03  1.10e+00
 114  9.95e+00  1.42e+00  4.26e+02  1.07e-02  5.56e-03  1.10e+00
 115  9.92e+00  1.42e+00  4.25e+02  1.08e-02  5.50e-03  1.10e+00
 116  9.89e+00  1.42e+00  4.24e+02  1.05e-02  5.41e-03  1.10e+00
 117  9.87e+00  1.42e+00  4.22e+02  1.05e-02  5.35e-03  1.10e+00
 118  9.84e+00  1.42e+00  4.21e+02  1.03e-02  5.27e-03  1.10e+00
 119  9.81e+00  1.42e+00  4.19e+02  1.01e-02  5.21e-03  1.10e+00
 120  9.78e+00  1.42e+00  4.18e+02  1.01e-02  5.14e-03  1.10e+00
 121  9.76e+00  1.42e+00  4.17e+02  9.97e-03  5.07e-03  1.10e+00
 122  9.73e+00  1.42e+00  4.16e+02  9.84e-03  5.04e-03  1.10e+00
 123  9.71e+00  1.42e+00  4.14e+02  9.72e-03  4.95e-03  1.10e+00
 124  9.69e+00  1.43e+00  4.13e+02  9.59e-03  4.90e-03  1.10e+00
 125  9.66e+00  1.43e+00  4.12e+02  9.49e-03  4.82e-03  1.10e+00
 126  9.64e+00  1.43e+00  4.11e+02  9.37e-03  4.76e-03  1.10e+00
 127  9.62e+00  1.43e+00  4.09e+02  9.26e-03  4.70e-03  1.10e+00
 128  9.59e+00  1.43e+00  4.08e+02  8.95e-03  4.64e-03  1.10e+00
 129  9.57e+00  1.43e+00  4.07e+02  9.06e-03  4.58e-03  1.10e+00
 130  9.55e+00  1.43e+00  4.06e+02  8.92e-03  4.52e-03  1.10e+00
 131  9.53e+00  1.43e+00  4.05e+02  8.81e-03  4.47e-03  1.10e+00
 132  9.51e+00  1.43e+00  4.04e+02  8.71e-03  4.41e-03  1.10e+00
 133  9.48e+00  1.43e+00  4.03e+02  8.60e-03  4.35e-03  1.10e+00
 134  9.46e+00  1.43e+00  4.02e+02  8.50e-03  4.29e-03  1.10e+00
 135  9.44e+00  1.43e+00  4.01e+02  8.40e-03  4.24e-03  1.10e+00
 136  9.43e+00  1.43e+00  4.00e+02  8.30e-03  4.18e-03  1.10e+00
 137  9.41e+00  1.43e+00  3.99e+02  8.19e-03  4.13e-03  1.10e+00
 138  9.39e+00  1.44e+00  3.98e+02  8.10e-03  4.08e-03  1.10e+00
 139  9.37e+00  1.44e+00  3.97e+02  7.92e-03  4.03e-03  1.10e+00
 140  9.35e+00  1.44e+00  3.96e+02  7.93e-03  3.99e-03  1.10e+00
 141  9.33e+00  1.44e+00  3.95e+02  7.82e-03  3.94e-03  1.10e+00
 142  9.31e+00  1.44e+00  3.94e+02  7.73e-03  3.91e-03  1.10e+00
 143  9.29e+00  1.44e+00  3.93e+02  7.64e-03  3.85e-03  1.10e+00
 144  9.27e+00  1.44e+00  3.92e+02  7.56e-03  3.82e-03  1.10e+00
 145  9.25e+00  1.44e+00  3.91e+02  7.47e-03  3.77e-03  1.10e+00
 146  9.23e+00  1.44e+00  3.90e+02  7.32e-03  3.73e-03  1.10e+00
 147  9.21e+00  1.44e+00  3.89e+02  7.30e-03  3.69e-03  1.10e+00
 148  9.20e+00  1.44e+00  3.88e+02  7.22e-03  3.64e-03  1.10e+00
 149  9.18e+00  1.44e+00  3.87e+02  7.22e-03  3.62e-03  1.10e+00
 150  9.16e+00  1.44e+00  3.86e+02  7.05e-03  3.56e-03  1.10e+00
 151  9.15e+00  1.44e+00  3.85e+02  6.98e-03  3.53e-03  1.10e+00
 152  9.13e+00  1.44e+00  3.84e+02  6.90e-03  3.48e-03  1.10e+00
 153  9.12e+00  1.44e+00  3.84e+02  6.79e-03  3.44e-03  1.10e+00
 154  9.10e+00  1.44e+00  3.83e+02  6.61e-03  3.40e-03  1.10e+00
 155  9.09e+00  1.45e+00  3.82e+02  6.68e-03  3.37e-03  1.10e+00
 156  9.07e+00  1.45e+00  3.81e+02  6.60e-03  3.33e-03  1.10e+00
 157  9.06e+00  1.45e+00  3.80e+02  6.53e-03  3.29e-03  1.10e+00
 158  9.04e+00  1.45e+00  3.80e+02  6.38e-03  3.25e-03  1.10e+00
 159  9.03e+00  1.45e+00  3.79e+02  6.39e-03  3.22e-03  1.10e+00
 160  9.01e+00  1.45e+00  3.78e+02  6.32e-03  3.18e-03  1.10e+00
 161  9.00e+00  1.45e+00  3.77e+02  6.26e-03  3.15e-03  1.10e+00
 162  8.98e+00  1.45e+00  3.77e+02  6.19e-03  3.11e-03  1.10e+00
 163  8.97e+00  1.45e+00  3.76e+02  6.12e-03  3.07e-03  1.10e+00
 164  8.95e+00  1.45e+00  3.75e+02  6.06e-03  3.03e-03  1.10e+00
 165  8.94e+00  1.45e+00  3.75e+02  6.00e-03  3.00e-03  1.10e+00
 166  8.93e+00  1.45e+00  3.74e+02  5.93e-03  2.97e-03  1.10e+00
 167  8.92e+00  1.45e+00  3.73e+02  5.87e-03  2.93e-03  1.10e+00
 168  8.90e+00  1.45e+00  3.73e+02  5.81e-03  2.90e-03  1.10e+00
 169  8.89e+00  1.45e+00  3.72e+02  5.67e-03  2.88e-03  1.10e+00
 170  8.88e+00  1.45e+00  3.71e+02  5.68e-03  2.84e-03  1.10e+00
 171  8.87e+00  1.45e+00  3.71e+02  5.59e-03  2.81e-03  1.10e+00
 172  8.85e+00  1.45e+00  3.70e+02  5.54e-03  2.79e-03  1.10e+00
 173  8.84e+00  1.45e+00  3.69e+02  5.50e-03  2.76e-03  1.10e+00
 174  8.83e+00  1.45e+00  3.69e+02  5.40e-03  2.73e-03  1.10e+00
 175  8.82e+00  1.45e+00  3.68e+02  5.37e-03  2.71e-03  1.10e+00
 176  8.81e+00  1.45e+00  3.68e+02  5.34e-03  2.67e-03  1.10e+00
 177  8.80e+00  1.46e+00  3.67e+02  5.28e-03  2.64e-03  1.10e+00
 178  8.79e+00  1.46e+00  3.67e+02  5.23e-03  2.61e-03  1.10e+00
 179  8.78e+00  1.46e+00  3.66e+02  5.13e-03  2.58e-03  1.10e+00
 180  8.77e+00  1.46e+00  3.66e+02  5.13e-03  2.55e-03  1.10e+00
 181  8.76e+00  1.46e+00  3.65e+02  5.04e-03  2.52e-03  1.10e+00
 182  8.75e+00  1.46e+00  3.65e+02  4.93e-03  2.49e-03  1.10e+00

Display solve time and reconstruction performance.

print("AddMaskSim wrapped ConvBPDN solve time: %.2fs" % t)
print("Corrupted image PSNR: %5.2f dB" % metric.psnr(img, imgw))
print("Recovered image PSNR: %5.2f dB" % metric.psnr(img, imgr))
AddMaskSim wrapped ConvBPDN solve time: 3.13s
Corrupted image PSNR:  9.17 dB
Recovered image PSNR: 24.57 dB

Display reference, test, and reconstructed image

fig = plot.figure(figsize=(21, 7))
plot.subplot(1, 3, 1)
plot.imview(img, title='Reference image', fig=fig)
plot.subplot(1, 3, 2)
plot.imview(imgw, title='Corrupted image', fig=fig)
plot.subplot(1, 3, 3)
plot.imview(imgr, title='Reconstructed image', fig=fig)

Display lowpass component and sparse representation

fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(sl,, title='Lowpass component', fig=fig)
plot.subplot(1, 2, 2)
plot.imview(np.sum(abs(X).squeeze(), axis=-1),,
            title='Sparse representation', fig=fig)

Plot functional value, residuals, and rho (not available if GPU implementation used).

if ams is not None:
    its = ams.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(np.vstack((its.PrimalRsdl, its.DualRsdl)).T, ptyp='semilogy',
              xlbl='Iterations', ylbl='Residual', lgnd=['Primal', 'Dual'],
    plot.subplot(1, 3, 3)
    plot.plot(its.Rho, xlbl='Iterations', ylbl='Penalty Parameter', fig=fig)