if False:
            init = algo.InitPoint(np.zeros(d),np.zeros(p),[],[])
            outcp = algo.cpBT(theProx2, theGradSmart, proxg, theFunc, hfunc, init, iter=maxIter,
                          beta=tuned,stepInc=1.1,K=Gt,Kstar=G,verbose=False,getFuncVals=False)
            results[(i,'cp')] =  outcp.finalFuncVal


        if False:
            init = algo.InitPoint([],[],np.zeros(d),np.zeros(p))
            outtseng = algo.tseng_product(theFunc, proxfstar_4_tseng, proxg, theGrad, init,verbose=False,getFuncVals=False,
                                      iter=maxIter, gamma1=tuned,gamma2=tuned,G=G,Gt=Gt)
            results[(i,'tseng')] =  outtseng.finalFuncVal

        if False:
            outfrb = algo.for_reflect_back(theFunc,proxfstar_4_tseng,proxg,theGrad,init,iter=maxIter,
                                       gamma0=tuned,gamma1=tuned,G=G,Gt=Gt,verbose=False,getFuncVals=False)
            results[(i,'frb')] =  outfrb.finalFuncVal

        if loss == "log":
            loss2use = "logistic"
        else:
            loss2use = 2

        gamma = 1.0
        if True :
            psObj = ps.ProjSplitFit(gamma)
            proc = lp.Forward2Backtrack()
            psObj.addData(X,y,loss2use,linearOp=H,normalize=False,process=proc,
                          embed=regularizers.L1(scaling=(1-mu)*lam))
            (nbeta,ngamma) = H.shape
            shape = (ngamma-1,ngamma)
                                      iter=maxIter // 2,
                                      gamma1=tsengs[i],
                                      gamma2=tsengs[i],
                                      G=G,
                                      Gt=Gt,
                                      historyFreq=20)

    if runFRB:
        print("FRB")
        outfrb = algo.for_reflect_back(theFunc,
                                       proxfstar_4_tseng,
                                       proxg,
                                       theGrad,
                                       init,
                                       iter=maxIter,
                                       gamma0=frbs[i],
                                       gamma1=frbs[i],
                                       G=G,
                                       Gt=Gt,
                                       verbose=True,
                                       getFuncVals=True,
                                       historyFreq=20)

    if runCP:
        print("cp")
        stepIncAmount = 1.0
        #stepIncAmount = 1.1
        betacp = betacps[i]
        init = algo.InitPoint(np.zeros(d), np.zeros(p), [], [])
        outcp = algo.cpBT(theProx2,
                          theGradSmart,
Beispiel #3
0
                     verbose=verbose,
                     iter=iter,
                     adaptive_gamma=False)

print_results("1fbt", out1f.times[-1], out1f.x1, out1f.grad_evals)

print("=========================")
print("running forward reflected backward (primal-dual)... (frb-pd)")
x0 = np.ones(d) / d

init = algo.InitPoint([], [], np.ones(d) / d, np.zeros(d))
outfrb = algo.for_reflect_back(theFunc,
                               proxfstar4Tseng,
                               proxgstar4Tseng,
                               theGrad,
                               init,
                               gamma0=gamma_frb,
                               gamma1=gamma_frb,
                               iter=iter,
                               hyper_resid=hyper_resid,
                               verbose=verbose)

print_results("frb", outfrb.times[-1], outfrb.x, outfrb.grad_evals)

print("=========================")
print("Running adaptive three operator splitting (ada3op)")
init = algo.InitPoint([], [], np.ones(d) / d, [])
out3op = algo.adap3op(theProx1,
                      theGradSmart,
                      theFunc,
                      theFunc,
                      theProx2,
                              theGrad,
                              init,
                              stepIncrease=step_increase,
                              alpha=initial_stepsize,
                              gamma1=gammatg,
                              gamma2=gammatg,
                              iter=iter)
print_results("tseng-pd", outTseng.x, outTseng.times[-1])

print("running FRB...")
init = algo.InitPoint([], [], np.zeros(d + 1), np.zeros(d + 1))
outFRB = algo.for_reflect_back(theFunc,
                               proxfstar4tseng,
                               proxgstar4tseng,
                               theGrad,
                               init,
                               iter=iter,
                               gamma0=gammafrb,
                               gamma1=gammafrb,
                               stepIncrease=step_increase,
                               lam=initial_stepsize)

print_results("frb-pd", outFRB.x, outFRB.times[-1])

tendFinal = time.time()
print("===============")
print("total running time: " + str(tendFinal - tActualStart))

print("plotting...")

print("plotting stepsizes for ps1fbt and ps2fbt")
markFreq = 100
Beispiel #5
0
outcp = algo.cpBT(theProx2, theGradSmart, proxg, theFunc, hfunc, init, iter=iterOverwrite,
                  beta=betacp,stepInc=1.1,K=Gt,Kstar=G)
print("cp-bt TOTAL running time: "+str(outcp.times[-1]))
print("================")

print("running tseng...")
# Since Tseng computes two forward steps per iteration, only run it for half as
# many iterations to get similar times to the other methods.
init = algo.InitPoint([],[],np.zeros(d),np.zeros(p))
outtseng = algo.tseng_product(theFunc, proxfstar_4_tseng, proxg, theGrad, init,
                              iter=iterOverwrite, gamma1=gammatg,gamma2=gammatg,G=G,Gt=Gt)
print("TOTAL tseng time: "+str(outtseng.times[-1]))
print("================")

print("running frb...")
outfrb = algo.for_reflect_back(theFunc,proxfstar_4_tseng,proxg,theGrad,init,iter=iterOverwrite,
                               gamma0=gammafrb,gamma1=gammafrb,G=G,Gt=Gt)
print("frb running time: "+str(outfrb.times[-1]))
print("================")

print("running ProjSplitFit")
X = sp.load_npz('data/trip_advisor/S_train.npz') # training matrix
H = sp.load_npz('data/trip_advisor/S_A.npz')     # this matrix is called H
y = np.load('data/trip_advisor/y_train.npy')     # training labels

f_ps2fg = []
t_ps2fg = []
f_psbg = []
t_psbg = []
for erg in [False,'simple','weighted']:
    t0 = time.time()
    psObj = ps.ProjSplitFit(gamma2fg)