コード例 #1
0
ファイル: ml.py プロジェクト: petpp/spdhg_pet
                tau = rho / norm_K
                f = KL
                A = K

                pdhg(x, f, g, A, tau, sigma, niter, callback=cb)

            elif alg.startswith('SPDHG1'):
                norm_K = misc.norms(
                    Ks, '{}/norm_{}subsets.npy'.format(folder_norms,
                                                       nsub[alg]))
                sigma = [rho / nk for nk in norm_K]
                tau = rho / (len(Ks) * max(norm_K))
                f = KLs
                A = Ks

                spdhg(x, f, g, A, tau, sigma, niter, callback=cb)

            elif alg.startswith('PDHG2'):
                f = KL
                A = K

                one = A.domain.one()
                tmp = A.range.element()
                A(one, out=tmp)
                tmp.ufuncs.maximum(tol_step, out=tmp)
                sigma = rho / tmp

                one = A.range.one()
                tmp = A.domain.element()
                A.adjoint(one, out=tmp)
                tmp.ufuncs.maximum(tol_step, out=tmp)
コード例 #2
0
        assert False, "Parameters not defined"

    # function that selects the indices every iteration
    def fun_select(k):
        return sub2ind[int(np.random.choice(n, 1, p=prob_subset))]

    # output function to be used within the iterations
    callback = (odl.solvers.CallbackPrintIteration(step=n, end=', ') &
                odl.solvers.CallbackPrintTiming(step=n, cumulative=True) &
                CallbackStore(alg, iter_save[alg], iter_plot[alg]))

    x, y = X.zero(), Y.zero()  # initialise variables
    callback([x, y])

    if alg.startswith('pdhg') or alg.startswith('spdhg'):
        spdhg(x, f, g, A, tau, sigma, niter[alg], prob=prob, y=y,
              fun_select=fun_select, callback=callback)

    elif alg.startswith('pa_pdhg') or alg.startswith('pa_spdhg'):
        pa_spdhg(x, f, g, A, tau, sigma, niter[alg], mu_g, prob=prob, y=y,
                 fun_select=fun_select, callback=callback)

    elif alg.startswith('pesquet'):
        spdhg_pesquet(x, f, g, A, tau, sigma, niter[alg], y=y,
                      fun_select=fun_select, callback=callback)

    else:
        assert False, "Algorithm not defined"

    np.save('{}/{}_output'.format(folder_npy, alg), (iter_save[alg],
            niter[alg], x, callback.callbacks[1].out, nsub[alg]), 
            allow_pickle=True)
コード例 #3
0
ファイル: map_atv.py プロジェクト: petpp/spdhg_pet
                    norm_A = misc.norm(A, '{}/norm_tv.npy'.format(folder_main))
                    sigma = rho / norm_A
                    tau = rho / norm_A

                    pdhg(x, f, g, A, tau, sigma, niter, callback=cb)

                elif alg.startswith('SPDHG1'):
                    sigma = [rho / nAi for nAi in norm_Ai]
                    tau = rho * min(
                        [pi / nAi for pi, nAi in zip(prob, norm_Ai)])

                    spdhg(x,
                          f,
                          g,
                          A,
                          tau,
                          sigma,
                          niter,
                          prob=prob,
                          callback=cb)

                elif alg.startswith('PDHG2'):
                    one = A[0].domain.one()
                    tmp = A[0].range.element()
                    A[0](one, out=tmp)
                    tmp.ufuncs.maximum(tol_step, out=tmp)
                    sigma = [rho / tmp, rho / norm_D]

                    one = A[0].range.one()
                    tmp = A[0].domain.element()
                    A[0].adjoint(one, out=tmp)