コード例 #1
0
ファイル: test_cbpdndl.py プロジェクト: zhangyu233/sporco
 def test_02(self):
     lmbda = 1e-1
     opt = cbpdndl.ConvBPDNDictLearn.Options({'MaxMainIter': 10})
     try:
         b = cbpdndl.ConvBPDNDictLearn(self.D0, self.S, lmbda, opt=opt)
         b.solve()
     except Exception as e:
         print(e)
         assert 0
コード例 #2
0
def nn_csc(input_, d_size, lmbda, Iter, visualize = False):
    D0 = np.random.uniform(0, 1.0, d_size);
    opt = cbpdndl.ConvBPDNDictLearn.Options({'Verbose': True, 'MaxMainIter': Iter,
                            'CBPDN': {'rho': 50.0*lmbda + 0.5, 'NonNegCoef': True},
                            'CCMOD': {'rho': 10.0, 'ZeroMean': True}},
                            dmethod='cns');
    d = cbpdndl.ConvBPDNDictLearn(D0, input_, lmbda, opt, dmethod='cns');
    D1 = d.solve();
    print("ConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve'));
    return d, D1, d.getcoef();
コード例 #3
0
def sporcosolve(cri, Dr0, Sr, maxitr=200):
    Dr0 = Dr0.copy()
    Sr = Sr.copy()
    lmbda = 0.2
    opt = cbpdndl.ConvBPDNDictLearn.Options({'Verbose': True, 'MaxMainIter': maxitr,
                            'CBPDN': {'rho': 50.0*lmbda + 0.5},
                            'CCMOD': {'rho': 10.0, 'ZeroMean': True}},
                            dmethod='cns')
    d = cbpdndl.ConvBPDNDictLearn(Dr0.squeeze(), Sr.squeeze(), lmbda, opt, dmethod='cns')
    Dr = d.solve()
    print("ConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve'))
    return Dr
コード例 #4
0
ファイル: test_cbpdndl.py プロジェクト: zhangyu233/sporco
 def test_05(self):
     N = 16
     Nc = 3
     Nd = 5
     M = 4
     K = 3
     D0 = np.random.randn(Nd, Nd, Nc, M)
     S = np.random.randn(N, N, Nc, K)
     lmbda = 1e-1
     opt = cbpdndl.ConvBPDNDictLearn.Options({'MaxMainIter': 10})
     try:
         b = cbpdndl.ConvBPDNDictLearn(D0, S, lmbda, opt=opt)
         b.solve()
     except Exception as e:
         print(e)
         assert 0
コード例 #5
0
ファイル: test_cbpdndl.py プロジェクト: zhangyu233/sporco
 def test_09(self):
     lmbda = 1e-1
     opt = cbpdndl.ConvBPDNDictLearn.Options({'MaxMainIter': 10},
                                             xmethod='fista',
                                             dmethod='cns')
     try:
         b = cbpdndl.ConvBPDNDictLearn(self.D0,
                                       self.S,
                                       lmbda,
                                       opt=opt,
                                       xmethod='fista',
                                       dmethod='cns')
         b.solve()
     except Exception as e:
         print(e)
         assert 0
コード例 #6
0
 def test_05(self):
     lmbda = 1e-1
     Nit = 10
     opts = cbpdndl.ConvBPDNDictLearn.Options(
         {
             'MaxMainIter': Nit,
             'AccurateDFid': True,
             'CBPDN': {
                 'RelaxParam': 1.0,
                 'AutoRho': {
                     'Enabled': False
                 }
             },
             'CCMOD': {
                 'RelaxParam': 1.0,
                 'AutoRho': {
                     'Enabled': False
                 }
             }
         },
         dmethod='cns')
     bs = cbpdndl.ConvBPDNDictLearn(self.D0,
                                    self.S,
                                    lmbda,
                                    opt=opts,
                                    dmethod='cns')
     Ds = bs.solve()
     optp = prlcnscdl.ConvBPDNDictLearn_Consensus.Options({
         'MaxMainIter': Nit,
         'CBPDN': {
             'RelaxParam': 1.0
         },
         'CCMOD': {
             'RelaxParam': 1.0
         }
     })
     bp = prlcnscdl.ConvBPDNDictLearn_Consensus(self.D0,
                                                self.S,
                                                lmbda,
                                                opt=optp,
                                                nproc=2)
     Dp = bp.solve()
     assert np.linalg.norm(Ds - Dp) < 1e-7
     assert np.abs(
         bs.getitstat().ObjFun[-1] - bp.getitstat().ObjFun[-1] < 1e-7)
コード例 #7
0
ファイル: cdl.py プロジェクト: CarloDeVita/MasterThesis
    def findDictionary1(self, epochs):

        #Creazione di un dizionario random

        np.random.seed(12345)
        D0 = np.random.randn(self.dimFilter, self.dimFilter, self.nFilters)

        lmbda = 0.2
        L_sc = 360.0
        L_du = 50.0
        opt = cbpdndl.ConvBPDNDictLearn.Options(
            {
                'Verbose': True,
                'MaxMainIter': epochs,
                'DictSize': D0.shape,
                'CBPDN': {
                    'BackTrack': {
                        'Enabled': True
                    },
                    'L': L_sc
                },
                'CCMOD': {
                    'BackTrack': {
                        'Enabled': True
                    },
                    'L': L_du
                }
            },
            xmethod='fista',
            dmethod='fista')
        d = cbpdndl.ConvBPDNDictLearn(D0,
                                      self.imgs,
                                      lmbda,
                                      opt,
                                      xmethod='fista',
                                      dmethod='fista')
        D1 = d.solve()
        print("ConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve'))
        D1 = D1.squeeze()
        self.D = D1
        self.coef = d.getcoef()
        self.rec = d.reconstruct().squeeze()
        self.d = d  #riferimento alla libreria
コード例 #8
0
ファイル: cdl.py プロジェクト: CarloDeVita/MasterThesis
    def findDictionary(self, epochs):

        #        #Filtro di tikhonov
        #        npd = 16
        #        fltlmbd = 5
        #        sl, sh = util.tikhonov_filter(self.imgs, fltlmbd, npd)
        #        #plot.imview(sl[:,:,1],title='IMG low');

        #Creazione di un dizionario random

        np.random.seed(12345)
        D0 = np.random.randn(self.dimFilter, self.dimFilter, self.nFilters)

        #Opzioni per l'algoritmo DL e Soluzione del problema
        #        lmbda = 0.1
        lmbda = 0.1
        opt = cbpdndl.ConvBPDNDictLearn.Options(
            {
                'Verbose': True,
                'MaxMainIter': epochs,
                'CBPDN': {
                    'rho': 50.0 * lmbda + 0.5
                },
                'CCMOD': {
                    'rho': 10.0,
                    'ZeroMean': True
                }
            },
            dmethod='cns')

        d = cbpdndl.ConvBPDNDictLearn(D0, self.imgs, lmbda, opt, dmethod='cns')
        D1 = d.solve()
        print("ConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve'))

        D1 = D1.squeeze()
        self.D = D1
        self.coef = d.getcoef()
        self.rec = d.reconstruct().squeeze()
        self.d = d  #riferimento alla libreria
コード例 #9
0
def train_batch_model(D0, train_blob, opt, args):
    """Train for batch dictlrn model."""
    logger = logging.getLogger(__name__)
    dname = args.dataset if not args.use_gray else args.dataset + '.gray'
    if os.path.exists(os.path.join(args.output_path, 'iter_record.mat')):
        iter_record = sio.loadmat(
            os.path.join(args.output_path, 'iter_record.mat'))['iter_record']
        selected = list(set(iter_record.ravel().tolist()))
        if args.batch_max_samples > 0 and args.batch_max_samples < len(
                selected):
            selected = selected[:args.batch_max_samples]
        if len(selected) < train_blob.shape[-1]:
            logger.info(
                'Selected %d -> %d train samples for training batch model',
                train_blob.shape[-1], len(selected))
            train_blob = train_blob[..., selected]
    if not args.no_tikhonov_filter:
        # fix lambda to be 5
        _, train_blob = su.tikhonov_filter(train_blob, 5.)
    path = os.path.join(args.output_path, 'ConvBPDNDictLearn')
    if not os.path.exists(path):
        os.makedirs(path)

    def _callback(d):
        """Snapshot dictionaries for every iteration."""
        _D = d.getdict().squeeze()
        np.save(os.path.join(path, '{}.{}.npy'.format(dname, d.j)), _D)
        return 0

    opt['Callback'] = _callback
    solver = cbpdndl.ConvBPDNDictLearn(D0,
                                       train_blob,
                                       args.lmbda,
                                       opt=opt,
                                       xmethod='admm',
                                       dmethod='cns')
    solver.solve()
    return solver
コード例 #10
0
def csc(input_, d_size, lmbda, Iter, visualize=False):
    D0 = np.random.uniform(-1.0, 1.0, d_size)
    opt = cbpdndl.ConvBPDNDictLearn.Options(
        {
            'Verbose': True,
            'MaxMainIter': Iter,
            'CBPDN': {
                'rho': 50.0 * lmbda + 0.5
            },
            'CCMOD': {
                'rho': 10.0,
                'ZeroMean': True
            }
        },
        dmethod='cns')
    d = cbpdndl.ConvBPDNDictLearn(D0, input_, lmbda, opt, dmethod='cns')
    D1 = d.solve()
    print("ConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve'))
    if visualize:
        plot_2([util.tiledict(D0.squeeze()),
                util.tiledict(D1.squeeze())],
               ["initial dictionary", "learned dictionary"])
    return d, D1, d.getcoef()
コード例 #11
0
def learn_dict(signal, atom_length, n_atoms, rng, penalty=PENALTY):
    """
    Return the learned dictionaty

    :param signal: 2d_array with shape (n_time_steps, n_dims)
    :param atom_length: int, length of an atom
    :param n_atoms: int, number of atoms
    :param rng: random number generator
    :param penalty: float, sparsity penalty (Convolutional dictionary learning)
    """
    opt_dl = get_opt_dl(penalty)
    if signal.ndim == 1:
        signal = atleast_2d(signal)
    dimK = signal.shape[1]
    return cbpdndl.ConvBPDNDictLearn(
        D0=rng.randn(atom_length, dimK, n_atoms),  # random init; set to 2 here for multidimensionality
        S=signal,  # signal at hand
        dimK=dimK,  # set to 2 here for multidimensionality
        lmbda=penalty,  # sparsity penalty
        opt=opt_dl,  # options for the optimizations
        xmethod="admm",  # optimization method (sparse coding)
        dmethod="cns",  # optimization method (dict learnin)
    ).solve()
コード例 #12
0
D0 = np.random.randn(10, 10, 32)
lmbda = 0.1
opt = cbpdndl.ConvBPDNDictLearn.Options(
    {
        'Verbose': True,
        'MaxMainIter': 200,
        'CBPDN': {
            'rho': 50.0 * lmbda + 0.5
        },
        'CCMOD': {
            'rho': 10.0,
            'ZeroMean': True
        }
    },
    dmethod='cns')
d = cbpdndl.ConvBPDNDictLearn(D0, sh, lmbda, opt, dmethod='cns')
D1 = d.solve()
print("ConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve'))
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()
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,
コード例 #13
0
                'Enabled': True
            }
        },
        'CCMOD': {
            'rho': 1e2,
            'AutoRho': {
                'Enabled': True
            }
        }
    },
    dmethod='cns')
"""
Create solver object and solve.
"""

d = cbpdndl.ConvBPDNDictLearn(D0, vh, lmbda, opt, dimK=0, dimN=3)
D1 = d.solve()
print("ConvBPDNDictLearn solve time: %.2fs" % d.timer.elapsed('solve'))
"""
Display initial and final dictionaries: central temporal slice
"""

D1 = D1.squeeze()
fig = plot.figure(figsize=(14, 7))
plot.subplot(1, 2, 1)
plot.imview(util.tiledict(D0[..., 2, :]), fig=fig, title='D0')
plot.subplot(1, 2, 2)
plot.imview(util.tiledict(D1[..., 2, :]), fig=fig, title='D1')
fig.show()
"""
Display initial and final dictionaries: central spatial vertical slice
コード例 #14
0
lmbda = 0.2
L_sc = 360.0
L_du = 50.0
dsz = ((8, 8, 3, 32), (12, 12, 3, 32), (16, 16, 3, 32))
opt = cbpdndl.ConvBPDNDictLearn.Options({
                'Verbose': True, 'MaxMainIter': 200, 'DictSize': dsz,
                'CBPDN': {'BackTrack': {'Enabled': True }, 'L': L_sc},
                'CCMOD': {'BackTrack': {'Enabled': True }, 'L': L_du}},
                xmethod='fista', dmethod='fista')


"""
Create solver object and solve.
"""

d = cbpdndl.ConvBPDNDictLearn(D0, sh, lmbda, opt, xmethod='fista',
                              dmethod='fista')
D1 = d.solve()
print("ConvBPDNDictLearn 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, dsz), title='D1', fig=fig)
fig.show()
コード例 #15
0
ファイル: callgraph.py プロジェクト: zhangyu233/sporco
def gengraphs(pth, nopyfftw):
    """
    Generate call graph images when necessary. Parameter pth is the path
    to the directory in which images are to be created. Parameter nopyfftw
    is a flag indicating whether it is necessary to avoid using pyfftw.
    """

    srcmodflt = '^sporco.admm'
    srcqnmflt = r'^((?!<locals>|__new|_name_nested).)*$'
    dstqnmflt = r'^((?!<locals>|__new|_name_nested).)*$'

    fnmsub = ('^sporco.admm.', '')
    grpflt = r'^[^\.]*.[^\.]*'
    lnkpfx = '../../modules/'
    lnksub = (r'^([^\.]*).([^\.]*)(?:(.__init__|.__call__)|(.[^\.]*))',
              lnkpfx + r'sporco.admm.\1.html#sporco.admm.\1.\2\4')

    fntsz = 9
    fntfm = 'Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans'
    kwargs = {'fntsz': fntsz, 'fntfm': fntfm, 'rmsz': True}

    ct = jonga.CallTracer(srcmodflt=srcmodflt,
                          srcqnmflt=srcqnmflt,
                          dstqnmflt=dstqnmflt,
                          fnmsub=fnmsub,
                          grpflt=grpflt,
                          lnksub=lnksub)

    # Make destination directory if it doesn't exist
    if not os.path.exists(pth):
        os.makedirs(pth, exist_ok=True)

    # Handle environment in which pyfftw is unavailable
    if nopyfftw:
        import numpy.fft as npfft
        import sporco.linalg as spl

        def empty(shape, dtype, order='C', n=None):
            return np.zeros(shape, dtype=dtype)

        empty.__doc__ = spl.pyfftw_empty_aligned.__doc__
        spl.pyfftw_empty_aligned = empty

        def rfftn_empty(shape, axes, dtype, order='C', n=None):
            ashp = list(shape)
            raxis = axes[-1]
            ashp[raxis] = ashp[raxis] // 2 + 1
            cdtype = spl.complex_dtype(dtype)
            return np.zeros(ashp, dtype=cdtype)

        rfftn_empty.__doc__ = spl.pyfftw_rfftn_empty_aligned.__doc__
        spl.pyfftw_rfftn_empty_aligned = rfftn_empty

        npfft.fftn.__doc__ = spl.fftn.__doc__
        spl.fftn = npfft.fftn
        npfft.ifftn.__doc__ = spl.ifftn.__doc__
        spl.ifftn = npfft.ifftn
        npfft.rfftn.__doc__ = spl.rfftn.__doc__
        spl.rfftn = npfft.rfftn
        npfft.irfftn.__doc__ = spl.irfftn.__doc__
        spl.irfftn = npfft.irfftn

    import numpy as np
    np.random.seed(12345)

    #### bpdn module
    from sporco.admm import bpdn
    mdnm = 'sporco.admm.bpdn'

    D = np.random.randn(8, 16)
    s = np.random.randn(8, 1)
    lmbda = 0.1

    ## BPDN class
    opt = bpdn.BPDN.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'bpdn_init.svg', **kwargs):
        b = bpdn.BPDN(D, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'bpdn_solve.svg', **kwargs):
        b.solve()

    ## BPDNJoint class
    opt = bpdn.BPDNJoint.Options({'Verbose': False, 'MaxMainIter': 1})
    mu = 0.01

    with CallGraph(ct, mdnm, pth, 'bpdnjnt_init.svg', **kwargs):
        b = bpdn.BPDNJoint(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'bpdnjnt_solve.svg', **kwargs):
        b.solve()

    ## ElasticNet class
    opt = bpdn.ElasticNet.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'elnet_init.svg', **kwargs):
        b = bpdn.ElasticNet(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'elnet_solve.svg', **kwargs):
        b.solve()

    # BPDNProjL1 class
    opt = bpdn.BPDNProjL1.Options({'Verbose': False, 'MaxMainIter': 1})
    gamma = 2.0

    with CallGraph(ct, mdnm, pth, 'bpdnprjl1_init.svg', **kwargs):
        b = bpdn.BPDNProjL1(D, s, gamma, opt)

    with CallGraph(ct, mdnm, pth, 'bpdnprjl1_solve.svg', **kwargs):
        b.solve()

    ## MinL1InL2Ball class
    opt = bpdn.MinL1InL2Ball.Options({'Verbose': False, 'MaxMainIter': 1})
    epsilon = 1.0

    with CallGraph(ct, mdnm, pth, 'bpdnml1l2_init.svg', **kwargs):
        b = bpdn.MinL1InL2Ball(D, s, epsilon, opt)

    with CallGraph(ct, mdnm, pth, 'bpdnml1l2_solve.svg', **kwargs):
        b.solve()

    #### cbpdn module
    from sporco.admm import cbpdn
    mdnm = 'sporco.admm.cbpdn'

    D = np.random.randn(4, 4, 16)
    s = np.random.randn(8, 8)
    lmbda = 0.1

    ## ConvBPDN class
    opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'cbpdn_init.svg', **kwargs):
        b = cbpdn.ConvBPDN(D, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdn_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNJoint class
    opt = cbpdn.ConvBPDNJoint.Options({'Verbose': False, 'MaxMainIter': 1})
    mu = 0.01

    with CallGraph(ct, mdnm, pth, 'cbpdnjnt_init.svg', **kwargs):
        b = cbpdn.ConvBPDNJoint(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnjnt_solve.svg', **kwargs):
        b.solve()

    ## ConvElasticNet class
    opt = cbpdn.ConvElasticNet.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'celnet_init.svg', **kwargs):
        b = cbpdn.ConvElasticNet(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'celnet_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNGradReg class
    opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'cbpdngrd_init.svg', **kwargs):
        b = cbpdn.ConvBPDNGradReg(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdngrd_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNProjL1 class
    opt = cbpdn.ConvBPDNProjL1.Options({'Verbose': False, 'MaxMainIter': 1})
    gamma = 0.5

    with CallGraph(ct, mdnm, pth, 'cbpdnprjl1_init.svg', **kwargs):
        b = cbpdn.ConvBPDNProjL1(D, s, gamma, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnprjl1_solve.svg', **kwargs):
        b.solve()

    ## ConvMinL1InL2Ball class
    opt = cbpdn.ConvMinL1InL2Ball.Options({'Verbose': False, 'MaxMainIter': 1})
    epsilon = 0.5

    with CallGraph(ct, mdnm, pth, 'cbpdnml1l2_init.svg', **kwargs):
        b = cbpdn.ConvMinL1InL2Ball(D, s, epsilon, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnml1l2_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNMaskDcpl class
    opt = cbpdn.ConvBPDNMaskDcpl.Options({'Verbose': False, 'MaxMainIter': 1})
    W = np.ones(s.shape)

    with CallGraph(ct, mdnm, pth, 'cbpdnmd_init.svg', **kwargs):
        b = cbpdn.ConvBPDNMaskDcpl(D, s, lmbda, W, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnmd_solve.svg', **kwargs):
        b.solve()

    ## ConvL1L1Grd class
    opt = cbpdn.ConvL1L1Grd.Options({'Verbose': False, 'MaxMainIter': 1})
    mu = 1e-2

    with CallGraph(ct, mdnm, pth, 'cl1l1grd_init.svg', **kwargs):
        b = cbpdn.ConvL1L1Grd(D, s, lmbda, mu, W, opt)

    with CallGraph(ct, mdnm, pth, 'cl1l1grd_solve.svg', **kwargs):
        b.solve()

    #### cbpdntv module
    from sporco.admm import cbpdntv
    mdnm = 'sporco.admm.cbpdntv'

    D = np.random.randn(4, 4, 16)
    s = np.random.randn(8, 8)
    lmbda = 0.1
    mu = 0.01

    ## ConvBPDNScalarTV class
    opt = cbpdntv.ConvBPDNScalarTV.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'cbpdnstv_init.svg', **kwargs):
        b = cbpdntv.ConvBPDNScalarTV(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnstv_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNVectorTV class
    opt = cbpdntv.ConvBPDNVectorTV.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'cbpdnvtv_init.svg', **kwargs):
        b = cbpdntv.ConvBPDNVectorTV(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnvtv_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNRecTV class
    opt = cbpdntv.ConvBPDNRecTV.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'cbpdnrtv_init.svg', **kwargs):
        b = cbpdntv.ConvBPDNRecTV(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnrtv_solve.svg', **kwargs):
        b.solve()

    #### cmod module
    from sporco.admm import cmod
    mdnm = 'sporco.admm.cmod'

    X = np.random.randn(8, 16)
    S = np.random.randn(8, 16)

    ## CnstrMOD class
    opt = cmod.CnstrMOD.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'cmod_init.svg', **kwargs):
        b = cmod.CnstrMOD(X, S, opt=opt)

    with CallGraph(ct, mdnm, pth, 'cmod_solve.svg', **kwargs):
        b.solve()

    #### ccmod module
    from sporco.admm import ccmod
    mdnm = 'sporco.admm.ccmod'

    X = np.random.randn(8, 8, 1, 2, 1)
    S = np.random.randn(8, 8, 2)
    dsz = (4, 4, 1)

    ## ConvCnstrMOD_IterSM class
    opt = ccmod.ConvCnstrMOD_IterSM.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'ccmodism_init.svg', **kwargs):
        b = ccmod.ConvCnstrMOD_IterSM(X, S, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodism_solve.svg', **kwargs):
        b.solve()

    ## ConvCnstrMOD_CG class
    opt = ccmod.ConvCnstrMOD_CG.Options({
        'Verbose': False,
        'MaxMainIter': 1,
        'CG': {
            'MaxIter': 1
        }
    })

    with CallGraph(ct, mdnm, pth, 'ccmodcg_init.svg', **kwargs):
        b = ccmod.ConvCnstrMOD_CG(X, S, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodcg_solve.svg', **kwargs):
        b.solve()

    ## ConvCnstrMOD_Consensus class
    opt = ccmod.ConvCnstrMOD_Consensus.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'ccmodcnsns_init.svg', **kwargs):
        b = ccmod.ConvCnstrMOD_Consensus(X, S, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodcnsns_solve.svg', **kwargs):
        b.solve()

    #### ccmodmd module
    from sporco.admm import ccmodmd
    mdnm = 'sporco.admm.ccmodmd'

    X = np.random.randn(8, 8, 1, 2, 1)
    S = np.random.randn(8, 8, 2)
    W = np.array([1.0])
    dsz = (4, 4, 1)

    ## ConvCnstrMODMaskDcpl_IterSM class
    opt = ccmodmd.ConvCnstrMODMaskDcpl_IterSM.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'ccmodmdism_init.svg', **kwargs):
        b = ccmodmd.ConvCnstrMODMaskDcpl_IterSM(X, S, W, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodmdism_solve.svg', **kwargs):
        b.solve()

    ## ConvCnstrMODMaskDcpl_CG class
    opt = ccmodmd.ConvCnstrMODMaskDcpl_CG.Options({
        'Verbose': False,
        'MaxMainIter': 1,
        'CG': {
            'MaxIter': 1
        }
    })

    with CallGraph(ct, mdnm, pth, 'ccmodmdcg_init.svg', **kwargs):
        b = ccmodmd.ConvCnstrMODMaskDcpl_CG(X, S, W, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodmdcg_solve.svg', **kwargs):
        b.solve()

    ## ConvCnstrMODMaskDcpl_Consensus class
    opt = ccmodmd.ConvCnstrMODMaskDcpl_Consensus.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'ccmodmdcnsns_init.svg', **kwargs):
        b = ccmodmd.ConvCnstrMODMaskDcpl_Consensus(X, S, W, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodmdcnsns_solve.svg', **kwargs):
        b.solve()

    #### tvl1 module
    from sporco.admm import tvl1
    mdnm = 'sporco.admm.tvl1'

    s = np.random.randn(16, 16)
    lmbda = 0.1

    ## TVL1Denoise class
    opt = tvl1.TVL1Denoise.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'tvl1den_init.svg', **kwargs):
        b = tvl1.TVL1Denoise(s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'tvl1den_solve.svg', **kwargs):
        b.solve()

    ## TVL1Deconv class
    opt = tvl1.TVL1Deconv.Options({'Verbose': False, 'MaxMainIter': 1})
    h = np.random.randn(3, 3)

    with CallGraph(ct, mdnm, pth, 'tvl1dcn_init.svg', **kwargs):
        b = tvl1.TVL1Deconv(h, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'tvl1dcn_solve.svg', **kwargs):
        b.solve()

    #### tvl2 module
    from sporco.admm import tvl2
    mdnm = 'sporco.admm.tvl2'

    s = np.random.randn(16, 16)
    lmbda = 0.1

    ## TVL2Denoise class
    opt = tvl2.TVL2Denoise.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'tvl2den_init.svg', **kwargs):
        b = tvl2.TVL2Denoise(s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'tvl2den_solve.svg', **kwargs):
        b.solve()

    ## TVL2Deconv class
    opt = tvl2.TVL2Deconv.Options({'Verbose': False, 'MaxMainIter': 1})
    h = np.random.randn(3, 3)

    with CallGraph(ct, mdnm, pth, 'tvl2dcn_init.svg', **kwargs):
        b = tvl2.TVL2Deconv(h, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'tvl2dcn_solve.svg', **kwargs):
        b.solve()

    srcmodflt = '^sporco.fista'
    fnmsub = ('^sporco.fista.', '')
    lnksub = (r'^([^\.]*).([^\.]*)(?:(.__init__|.__call__)|(.[^\.]*))',
              lnkpfx + r'sporco.fista.\1.html#sporco.fista.\1.\2\4')
    ct = jonga.CallTracer(srcmodflt=srcmodflt,
                          srcqnmflt=srcqnmflt,
                          dstqnmflt=dstqnmflt,
                          fnmsub=fnmsub,
                          grpflt=grpflt,
                          lnksub=lnksub)

    #### fista.cbpdn module
    from sporco.fista import cbpdn
    mdnm = 'sporco.fista.cbpdn'

    D = np.random.randn(4, 4, 16)
    s = np.random.randn(8, 8)
    lmbda = 0.1

    ## ConvBPDN class
    opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'fista_cbpdn_init.svg', **kwargs):
        b = cbpdn.ConvBPDN(D, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'fista_cbpdn_solve.svg', **kwargs):
        b.solve()

    #### fista.ccmod module
    from sporco.fista import ccmod
    mdnm = 'sporco.fista.ccmod'

    X = np.random.randn(8, 8, 1, 2, 1)
    S = np.random.randn(8, 8, 2)
    dsz = (4, 4, 1)

    ## ConvCnstrMOD class
    opt = ccmod.ConvCnstrMOD.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'ccmodfista_init.svg', **kwargs):
        b = ccmod.ConvCnstrMOD(X, S, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodfista_solve.svg', **kwargs):
        b.solve()

    ## ConvCnstrMODMask class
    opt = ccmod.ConvCnstrMODMask.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'ccmodmdfista_init.svg', **kwargs):
        b = ccmod.ConvCnstrMODMask(X, S, W, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodmdfista_solve.svg', **kwargs):
        b.solve()

    srcmodflt = '^sporco.dictlrn'
    fnmsub = ('^sporco.dictlrn.', '')
    lnksub = (r'^([^\.]*).([^\.]*)(?:(.__init__|.__call__)|(.[^\.]*))',
              lnkpfx + r'sporco.dictlrn.\1.html#sporco.dictlrn.\1.\2\4')
    ct = jonga.CallTracer(srcmodflt=srcmodflt,
                          srcqnmflt=srcqnmflt,
                          dstqnmflt=dstqnmflt,
                          fnmsub=fnmsub,
                          grpflt=grpflt,
                          lnksub=lnksub)

    #### bpdndl module
    from sporco.dictlrn import bpdndl
    mdnm = 'sporco.dictlrn.bpdndl'

    D0 = np.random.randn(8, 8)
    S = np.random.randn(8, 16)
    lmbda = 0.1

    ## BPDNDictLearn class
    opt = bpdndl.BPDNDictLearn.Options({
        'Verbose': False,
        'MaxMainIter': 1,
        'AccurateDFid': True
    })

    with CallGraph(ct, mdnm, pth, 'bpdndl_init.svg', **kwargs):
        b = bpdndl.BPDNDictLearn(D0, S, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'bpdndl_solve.svg', **kwargs):
        b.solve()

    #### cbpdndl module
    from sporco.dictlrn import cbpdndl
    mdnm = 'sporco.dictlrn.cbpdndl'

    D0 = np.random.randn(4, 4, 16)
    s = np.random.randn(8, 8, 10)
    lmbda = 0.1

    ## ConvBPDNDictLearn class
    opt = cbpdndl.ConvBPDNDictLearn.Options({
        'Verbose': False,
        'MaxMainIter': 1,
        'AccurateDFid': True
    })

    with CallGraph(ct, mdnm, pth, 'cbpdndl_init.svg', **kwargs):
        b = cbpdndl.ConvBPDNDictLearn(D0, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdndl_solve.svg', **kwargs):
        b.solve()

    #### cbpdndlmd module
    from sporco.dictlrn import cbpdndlmd
    mdnm = 'sporco.dictlrn.cbpdndlmd'

    ## ConvBPDNMaskDcplDictLearn class
    W = np.array([1.0])
    opt = cbpdndlmd.ConvBPDNMaskDictLearn.Options({
        'Verbose': False,
        'MaxMainIter': 1,
        'AccurateDFid': True
    })

    with CallGraph(ct, mdnm, pth, 'cbpdnmddl_init.svg', **kwargs):
        b = cbpdndlmd.ConvBPDNMaskDictLearn(D0, s, lmbda, W, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnmddl_solve.svg', **kwargs):
        b.solve()
コード例 #16
0
ファイル: callgraph.py プロジェクト: young-oct/complex_sporco
def gengraphs(pth):
    """
    Generate call graph images when necessary. Parameter pth is the path
    to the directory in which images are to be created.
    """

    srcmodflt = '^sporco.admm'
    srcqnmflt = r'^((?!<locals>|__new|_name_nested).)*$'
    dstqnmflt = r'^((?!<locals>|__new|_name_nested).)*$'

    fnmsub = ('^sporco.admm.', '')
    grpflt = r'^[^\.]*.[^\.]*'
    lnkpfx = '../../modules/'
    lnksub = (r'^([^\.]*).([^\.]*)(?:(.__init__|.__call__)|(.[^\.]*))',
              lnkpfx + r'sporco.admm.\1.html#sporco.admm.\1.\2\4')

    fntsz = 9
    fntfm = 'Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans'
    kwargs = {'fntsz': fntsz, 'fntfm': fntfm, 'rmsz': True}

    ct = jonga.CallTracer(srcmodflt=srcmodflt,
                          srcqnmflt=srcqnmflt,
                          dstqnmflt=dstqnmflt,
                          fnmsub=fnmsub,
                          grpflt=grpflt,
                          lnksub=lnksub)

    # Make destination directory if it doesn't exist
    if not os.path.exists(pth):
        os.makedirs(pth, exist_ok=True)

    import numpy as np
    np.random.seed(12345)

    #### bpdn module
    from sporco.admm import bpdn
    mdnm = 'sporco.admm.bpdn'

    D = np.random.randn(8, 16)
    s = np.random.randn(8, 1)
    lmbda = 0.1

    ## BPDN class
    opt = bpdn.BPDN.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'bpdn_init.svg', **kwargs):
        b = bpdn.BPDN(D, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'bpdn_solve.svg', **kwargs):
        b.solve()

    ## BPDNJoint class
    opt = bpdn.BPDNJoint.Options({'Verbose': False, 'MaxMainIter': 1})
    mu = 0.01

    with CallGraph(ct, mdnm, pth, 'bpdnjnt_init.svg', **kwargs):
        b = bpdn.BPDNJoint(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'bpdnjnt_solve.svg', **kwargs):
        b.solve()

    ## ElasticNet class
    opt = bpdn.ElasticNet.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'elnet_init.svg', **kwargs):
        b = bpdn.ElasticNet(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'elnet_solve.svg', **kwargs):
        b.solve()

    # BPDNProjL1 class
    opt = bpdn.BPDNProjL1.Options({'Verbose': False, 'MaxMainIter': 1})
    gamma = 2.0

    with CallGraph(ct, mdnm, pth, 'bpdnprjl1_init.svg', **kwargs):
        b = bpdn.BPDNProjL1(D, s, gamma, opt)

    with CallGraph(ct, mdnm, pth, 'bpdnprjl1_solve.svg', **kwargs):
        b.solve()

    ## MinL1InL2Ball class
    opt = bpdn.MinL1InL2Ball.Options({'Verbose': False, 'MaxMainIter': 1})
    epsilon = 1.0

    with CallGraph(ct, mdnm, pth, 'bpdnml1l2_init.svg', **kwargs):
        b = bpdn.MinL1InL2Ball(D, s, epsilon, opt)

    with CallGraph(ct, mdnm, pth, 'bpdnml1l2_solve.svg', **kwargs):
        b.solve()

    #### cbpdn module
    from sporco.admm import cbpdn
    mdnm = 'sporco.admm.cbpdn'

    D = np.random.randn(4, 4, 16)
    s = np.random.randn(8, 8)
    lmbda = 0.1

    ## ConvBPDN class
    opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'cbpdn_init.svg', **kwargs):
        b = cbpdn.ConvBPDN(D, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdn_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNJoint class
    opt = cbpdn.ConvBPDNJoint.Options({'Verbose': False, 'MaxMainIter': 1})
    mu = 0.01

    with CallGraph(ct, mdnm, pth, 'cbpdnjnt_init.svg', **kwargs):
        b = cbpdn.ConvBPDNJoint(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnjnt_solve.svg', **kwargs):
        b.solve()

    ## ConvElasticNet class
    opt = cbpdn.ConvElasticNet.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'celnet_init.svg', **kwargs):
        b = cbpdn.ConvElasticNet(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'celnet_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNGradReg class
    opt = cbpdn.ConvBPDNGradReg.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'cbpdngrd_init.svg', **kwargs):
        b = cbpdn.ConvBPDNGradReg(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdngrd_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNProjL1 class
    opt = cbpdn.ConvBPDNProjL1.Options({'Verbose': False, 'MaxMainIter': 1})
    gamma = 0.5

    with CallGraph(ct, mdnm, pth, 'cbpdnprjl1_init.svg', **kwargs):
        b = cbpdn.ConvBPDNProjL1(D, s, gamma, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnprjl1_solve.svg', **kwargs):
        b.solve()

    ## ConvMinL1InL2Ball class
    opt = cbpdn.ConvMinL1InL2Ball.Options({'Verbose': False, 'MaxMainIter': 1})
    epsilon = 0.5

    with CallGraph(ct, mdnm, pth, 'cbpdnml1l2_init.svg', **kwargs):
        b = cbpdn.ConvMinL1InL2Ball(D, s, epsilon, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnml1l2_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNMaskDcpl class
    opt = cbpdn.ConvBPDNMaskDcpl.Options({'Verbose': False, 'MaxMainIter': 1})
    W = np.ones(s.shape)

    with CallGraph(ct, mdnm, pth, 'cbpdnmd_init.svg', **kwargs):
        b = cbpdn.ConvBPDNMaskDcpl(D, s, lmbda, W, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnmd_solve.svg', **kwargs):
        b.solve()

    ## ConvL1L1Grd class
    opt = cbpdn.ConvL1L1Grd.Options({'Verbose': False, 'MaxMainIter': 1})
    mu = 1e-2

    with CallGraph(ct, mdnm, pth, 'cl1l1grd_init.svg', **kwargs):
        b = cbpdn.ConvL1L1Grd(D, s, lmbda, mu, W, opt)

    with CallGraph(ct, mdnm, pth, 'cl1l1grd_solve.svg', **kwargs):
        b.solve()

    #### cbpdntv module
    from sporco.admm import cbpdntv
    mdnm = 'sporco.admm.cbpdntv'

    D = np.random.randn(4, 4, 16)
    s = np.random.randn(8, 8)
    lmbda = 0.1
    mu = 0.01

    ## ConvBPDNScalarTV class
    opt = cbpdntv.ConvBPDNScalarTV.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'cbpdnstv_init.svg', **kwargs):
        b = cbpdntv.ConvBPDNScalarTV(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnstv_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNVectorTV class
    opt = cbpdntv.ConvBPDNVectorTV.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'cbpdnvtv_init.svg', **kwargs):
        b = cbpdntv.ConvBPDNVectorTV(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnvtv_solve.svg', **kwargs):
        b.solve()

    ## ConvBPDNRecTV class
    opt = cbpdntv.ConvBPDNRecTV.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'cbpdnrtv_init.svg', **kwargs):
        b = cbpdntv.ConvBPDNRecTV(D, s, lmbda, mu, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnrtv_solve.svg', **kwargs):
        b.solve()

    #### cbpdnin module
    from sporco.admm import cbpdnin
    mdnm = 'sporco.admm.cbpdnin'

    D = np.random.randn(4, 4, 32)
    s = np.random.randn(8, 8)
    lmbda = 0.1
    mu = 0.01
    Wg = np.append(np.eye(16), np.eye(16), axis=-1)

    ## ConvBPDNInhib class
    opt = cbpdnin.ConvBPDNInhib.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'cbpdnin_init.svg', **kwargs):
        b = cbpdnin.ConvBPDNInhib(D,
                                  s,
                                  Wg,
                                  Whn=4,
                                  lmbda=lmbda,
                                  mu=mu,
                                  gamma=None,
                                  opt=opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnin_solve.svg', **kwargs):
        b.solve()

    #### cmod module
    from sporco.admm import cmod
    mdnm = 'sporco.admm.cmod'

    X = np.random.randn(8, 16)
    S = np.random.randn(8, 16)

    ## CnstrMOD class
    opt = cmod.CnstrMOD.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'cmod_init.svg', **kwargs):
        b = cmod.CnstrMOD(X, S, opt=opt)

    with CallGraph(ct, mdnm, pth, 'cmod_solve.svg', **kwargs):
        b.solve()

    #### ccmod module
    from sporco.admm import ccmod
    mdnm = 'sporco.admm.ccmod'

    X = np.random.randn(8, 8, 1, 2, 1)
    S = np.random.randn(8, 8, 2)
    dsz = (4, 4, 1)

    ## ConvCnstrMOD_IterSM class
    opt = ccmod.ConvCnstrMOD_IterSM.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'ccmodism_init.svg', **kwargs):
        b = ccmod.ConvCnstrMOD_IterSM(X, S, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodism_solve.svg', **kwargs):
        b.solve()

    ## ConvCnstrMOD_CG class
    opt = ccmod.ConvCnstrMOD_CG.Options({
        'Verbose': False,
        'MaxMainIter': 1,
        'CG': {
            'MaxIter': 1
        }
    })

    with CallGraph(ct, mdnm, pth, 'ccmodcg_init.svg', **kwargs):
        b = ccmod.ConvCnstrMOD_CG(X, S, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodcg_solve.svg', **kwargs):
        b.solve()

    ## ConvCnstrMOD_Consensus class
    opt = ccmod.ConvCnstrMOD_Consensus.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'ccmodcnsns_init.svg', **kwargs):
        b = ccmod.ConvCnstrMOD_Consensus(X, S, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodcnsns_solve.svg', **kwargs):
        b.solve()

    #### ccmodmd module
    from sporco.admm import ccmodmd
    mdnm = 'sporco.admm.ccmodmd'

    X = np.random.randn(8, 8, 1, 2, 1)
    S = np.random.randn(8, 8, 2)
    W = np.array([1.0])
    dsz = (4, 4, 1)

    ## ConvCnstrMODMaskDcpl_IterSM class
    opt = ccmodmd.ConvCnstrMODMaskDcpl_IterSM.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'ccmodmdism_init.svg', **kwargs):
        b = ccmodmd.ConvCnstrMODMaskDcpl_IterSM(X, S, W, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodmdism_solve.svg', **kwargs):
        b.solve()

    ## ConvCnstrMODMaskDcpl_CG class
    opt = ccmodmd.ConvCnstrMODMaskDcpl_CG.Options({
        'Verbose': False,
        'MaxMainIter': 1,
        'CG': {
            'MaxIter': 1
        }
    })

    with CallGraph(ct, mdnm, pth, 'ccmodmdcg_init.svg', **kwargs):
        b = ccmodmd.ConvCnstrMODMaskDcpl_CG(X, S, W, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodmdcg_solve.svg', **kwargs):
        b.solve()

    ## ConvCnstrMODMaskDcpl_Consensus class
    opt = ccmodmd.ConvCnstrMODMaskDcpl_Consensus.Options({
        'Verbose': False,
        'MaxMainIter': 1
    })

    with CallGraph(ct, mdnm, pth, 'ccmodmdcnsns_init.svg', **kwargs):
        b = ccmodmd.ConvCnstrMODMaskDcpl_Consensus(X, S, W, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodmdcnsns_solve.svg', **kwargs):
        b.solve()

    #### tvl1 module
    from sporco.admm import tvl1
    mdnm = 'sporco.admm.tvl1'

    s = np.random.randn(16, 16)
    lmbda = 0.1

    ## TVL1Denoise class
    opt = tvl1.TVL1Denoise.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'tvl1den_init.svg', **kwargs):
        b = tvl1.TVL1Denoise(s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'tvl1den_solve.svg', **kwargs):
        b.solve()

    ## TVL1Deconv class
    opt = tvl1.TVL1Deconv.Options({'Verbose': False, 'MaxMainIter': 1})
    h = np.random.randn(3, 3)

    with CallGraph(ct, mdnm, pth, 'tvl1dcn_init.svg', **kwargs):
        b = tvl1.TVL1Deconv(h, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'tvl1dcn_solve.svg', **kwargs):
        b.solve()

    #### tvl2 module
    from sporco.admm import tvl2
    mdnm = 'sporco.admm.tvl2'

    s = np.random.randn(16, 16)
    lmbda = 0.1

    ## TVL2Denoise class
    opt = tvl2.TVL2Denoise.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'tvl2den_init.svg', **kwargs):
        b = tvl2.TVL2Denoise(s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'tvl2den_solve.svg', **kwargs):
        b.solve()

    ## TVL2Deconv class
    opt = tvl2.TVL2Deconv.Options({'Verbose': False, 'MaxMainIter': 1})
    h = np.random.randn(3, 3)

    with CallGraph(ct, mdnm, pth, 'tvl2dcn_init.svg', **kwargs):
        b = tvl2.TVL2Deconv(h, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'tvl2dcn_solve.svg', **kwargs):
        b.solve()

    srcmodflt = '^sporco.fista'
    fnmsub = ('^sporco.fista.', '')
    lnksub = (r'^([^\.]*).([^\.]*)(?:(.__init__|.__call__)|(.[^\.]*))',
              lnkpfx + r'sporco.fista.\1.html#sporco.fista.\1.\2\4')
    ct = jonga.CallTracer(srcmodflt=srcmodflt,
                          srcqnmflt=srcqnmflt,
                          dstqnmflt=dstqnmflt,
                          fnmsub=fnmsub,
                          grpflt=grpflt,
                          lnksub=lnksub)

    #### fista.cbpdn module
    from sporco.fista import cbpdn
    mdnm = 'sporco.fista.cbpdn'

    D = np.random.randn(4, 4, 16)
    s = np.random.randn(8, 8)
    lmbda = 0.1

    ## ConvBPDN class
    opt = cbpdn.ConvBPDN.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'fista_cbpdn_init.svg', **kwargs):
        b = cbpdn.ConvBPDN(D, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'fista_cbpdn_solve.svg', **kwargs):
        b.solve()

    #### fista.ccmod module
    from sporco.fista import ccmod
    mdnm = 'sporco.fista.ccmod'

    X = np.random.randn(8, 8, 1, 2, 1)
    S = np.random.randn(8, 8, 2)
    dsz = (4, 4, 1)

    ## ConvCnstrMOD class
    opt = ccmod.ConvCnstrMOD.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'ccmodfista_init.svg', **kwargs):
        b = ccmod.ConvCnstrMOD(X, S, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodfista_solve.svg', **kwargs):
        b.solve()

    ## ConvCnstrMODMask class
    opt = ccmod.ConvCnstrMODMask.Options({'Verbose': False, 'MaxMainIter': 1})

    with CallGraph(ct, mdnm, pth, 'ccmodmdfista_init.svg', **kwargs):
        b = ccmod.ConvCnstrMODMask(X, S, W, dsz=dsz, opt=opt)

    with CallGraph(ct, mdnm, pth, 'ccmodmdfista_solve.svg', **kwargs):
        b.solve()

    srcmodflt = '^sporco.dictlrn'
    fnmsub = ('^sporco.dictlrn.', '')
    lnksub = (r'^([^\.]*).([^\.]*)(?:(.__init__|.__call__)|(.[^\.]*))',
              lnkpfx + r'sporco.dictlrn.\1.html#sporco.dictlrn.\1.\2\4')
    ct = jonga.CallTracer(srcmodflt=srcmodflt,
                          srcqnmflt=srcqnmflt,
                          dstqnmflt=dstqnmflt,
                          fnmsub=fnmsub,
                          grpflt=grpflt,
                          lnksub=lnksub)

    #### bpdndl module
    from sporco.dictlrn import bpdndl
    mdnm = 'sporco.dictlrn.bpdndl'

    D0 = np.random.randn(8, 8)
    S = np.random.randn(8, 16)
    lmbda = 0.1

    ## BPDNDictLearn class
    opt = bpdndl.BPDNDictLearn.Options({
        'Verbose': False,
        'MaxMainIter': 1,
        'AccurateDFid': True
    })

    with CallGraph(ct, mdnm, pth, 'bpdndl_init.svg', **kwargs):
        b = bpdndl.BPDNDictLearn(D0, S, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'bpdndl_solve.svg', **kwargs):
        b.solve()

    #### cbpdndl module
    from sporco.dictlrn import cbpdndl
    mdnm = 'sporco.dictlrn.cbpdndl'

    D0 = np.random.randn(4, 4, 16)
    s = np.random.randn(8, 8, 10)
    lmbda = 0.1

    ## ConvBPDNDictLearn class
    opt = cbpdndl.ConvBPDNDictLearn.Options({
        'Verbose': False,
        'MaxMainIter': 1,
        'AccurateDFid': True
    })

    with CallGraph(ct, mdnm, pth, 'cbpdndl_init.svg', **kwargs):
        b = cbpdndl.ConvBPDNDictLearn(D0, s, lmbda, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdndl_solve.svg', **kwargs):
        b.solve()

    #### cbpdndlmd module
    from sporco.dictlrn import cbpdndlmd
    mdnm = 'sporco.dictlrn.cbpdndlmd'

    ## ConvBPDNMaskDcplDictLearn class
    W = np.array([1.0])
    opt = cbpdndlmd.ConvBPDNMaskDictLearn.Options({
        'Verbose': False,
        'MaxMainIter': 1,
        'AccurateDFid': True
    })

    with CallGraph(ct, mdnm, pth, 'cbpdnmddl_init.svg', **kwargs):
        b = cbpdndlmd.ConvBPDNMaskDictLearn(D0, s, lmbda, W, opt)

    with CallGraph(ct, mdnm, pth, 'cbpdnmddl_solve.svg', **kwargs):
        b.solve()
コード例 #17
0
# training, offline learning
np.random.seed(0)

s = np.transpose(imgs[..., 0], (1, 2, 0))
sl, sh = util.tikhonov_filter(s, args.lmbdaPre)

D0 = np.random.normal(size = args.kernelSize + [args.nChannels]).astype(np.float32)

opt = cbpdndl.ConvBPDNDictLearn.Options({'Verbose': True, 'MaxMainIter': args.nPreIter,
                                         'CBPDN': {'rho': 100*args.lmbda + 1, 
                                                   'AutoRho': {'Enabled': True}, 
                                                   'RelaxParam': 1.8, 
                                                   'RelStopTol': 1e-7},
                                         'CCMOD': {'rho': 10.0, 'ZeroMean': False}}, 
                                        dmethod='cns')
learner = cbpdndl.ConvBPDNDictLearn(D0, sh, args.lmbda, opt, dmethod='cns')
learner.solve()

D1 = learner.getdict()
D1 = D1.squeeze()

if not os.path.exists(os.path.dirname(args.checkPoint)):
    os.makedirs(os.path.dirname(args.checkPoint))
np.save(args.checkPoint, D1)


# In[21]:


if showPlots:
    plt.imshow(sporco.util.tiledict(D1))
コード例 #18
0
        'CBPDN': {
            'Backtrack': BacktrackStandard(gamma_u=1.1),
            'L': L_sc
        },
        'CCMOD': {
            'Backtrack': BacktrackStandard(),
            'L': L_du
        }
    },
    xmethod='pgm',
    dmethod='pgm')
"""
Create solver object and solve.
"""

d = cbpdndl.ConvBPDNDictLearn(D0, sh, lmbda, opt, xmethod='pgm', dmethod='pgm')
D1 = d.solve()
print("ConvBPDNDictLearn 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, 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.