From fe871b85377fde1446cca169539c18fa7ec2391f Mon Sep 17 00:00:00 2001 From: Mihir Paradkar Date: Mon, 16 Jan 2017 23:54:11 -0500 Subject: [PATCH] Added inner iterations to allow learning new examples --- src/fit.jl | 25 ++++++++++++++----------- src/fit_multithread.jl | 25 ++++++++++++++----------- src/fit_sparse.jl | 25 ++++++++++++++----------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/fit.jl b/src/fit.jl index dcce46c..f887500 100644 --- a/src/fit.jl +++ b/src/fit.jl @@ -191,7 +191,7 @@ function LowRankModels.fit!(g::GGLRM, tm = 0 update_ch!(ch, tm, whole_objective(g,XY)) - + (objx, objy) = (NaN, NaN) #Step sizes αx = params.stepsize αy = params.stepsize @@ -210,17 +210,20 @@ function LowRankModels.fit!(g::GGLRM, if verbose println("Fitting GGLRM") end for t in 1:params.max_iter #X update----------------------------------------------------------------- - #_threadedupdateGradX!(g,XY,gx) - _updateGradX!(g,XY,gx) - #Take a prox step with line search - αx, objx = _proxStepX!(g, params, newX, gx, XY, newXY, αx) - At_mul_B!(XY, X, Y) #Get the new XY matrix for objective - + for xit in 1:params.inner_iter_X + #_threadedupdateGradX!(g,XY,gx) + _updateGradX!(g,XY,gx) + #Take a prox step with line search + αx, objx = _proxStepX!(g, params, newX, gx, XY, newXY, αx) + At_mul_B!(XY, X, Y) #Get the new XY matrix for objective + end #Y Update--------------------------------------------------------------- - #_threadedupdateGradY!(g,XY,gy) - _updateGradY!(g,XY,gy) - αy, objy = _proxStepY!(g, params, newY, gy, XY, newXY, αy) - At_mul_B!(XY, X, Y) #Get the new XY matrix for objective + for yit in 1:params.inner_iter_Y + #_threadedupdateGradY!(g,XY,gy) + _updateGradY!(g,XY,gy) + αy, objy = _proxStepY!(g, params, newY, gy, XY, newXY, αy) + At_mul_B!(XY, X, Y) #Get the new XY matrix for objective + end if t % 10 == 0 if verbose println("Iteration $t, objective value: $(objy + evaluate(rx, g.X))") diff --git a/src/fit_multithread.jl b/src/fit_multithread.jl index 212a5a1..d5facd5 100644 --- a/src/fit_multithread.jl +++ b/src/fit_multithread.jl @@ -155,7 +155,7 @@ function fit_multithread!(g::GGLRM, tm = 0 update_ch!(ch, tm, whole_objective(g,XY)) - + (objx, objy) = NaN, NaN #Step sizes αx = params.stepsize αy = params.stepsize @@ -174,17 +174,20 @@ function fit_multithread!(g::GGLRM, if verbose println("Fitting GGLRM") end for t in 1:params.max_iter #X update----------------------------------------------------------------- - #_threadedupdateGradX!(g,XY,gx) - _threadedupdateGradX!(g,XY,gx) - #Take a prox step with line search - αx, objx = _threadedproxStepX!(g, params, newX, gx, XY, newXY, αx) - At_mul_B!(XY, X, Y) #Get the new XY matrix for objective - + for xit in 1:params.inner_iter_X + #_threadedupdateGradX!(g,XY,gx) + _threadedupdateGradX!(g,XY,gx) + #Take a prox step with line search + αx, objx = _threadedproxStepX!(g, params, newX, gx, XY, newXY, αx) + At_mul_B!(XY, X, Y) #Get the new XY matrix for objective + end #Y Update--------------------------------------------------------------- - #_threadedupdateGradY!(g,XY,gy) - _threadedupdateGradY!(g,XY,gy) - αy, objy = _threadedproxStepY!(g, params, newY, gy, XY, newXY, αy) - At_mul_B!(XY, X, Y) #Get the new XY matrix for objective + for yit in 1:params.inner_iter_Y + #_threadedupdateGradY!(g,XY,gy) + _threadedupdateGradY!(g,XY,gy) + αy, objy = _threadedproxStepY!(g, params, newY, gy, XY, newXY, αy) + At_mul_B!(XY, X, Y) #Get the new XY matrix for objective + end if t % 10 == 0 if verbose println("Iteration $t, objective value: $(objy + evaluate(rx, g.X))") diff --git a/src/fit_sparse.jl b/src/fit_sparse.jl index f2d54ca..6b31212 100644 --- a/src/fit_sparse.jl +++ b/src/fit_sparse.jl @@ -187,7 +187,7 @@ function fit_sparse!(g::GGLRM, tm = 0 update_ch!(ch, tm, sparse_whole_objective(g,XY)) - + (objx, objy) = NaN, NaN #Step sizes αx = params.stepsize αy = params.stepsize @@ -206,17 +206,20 @@ function fit_sparse!(g::GGLRM, if verbose println("Fitting GGLRM") end for t in 1:params.max_iter #X update----------------------------------------------------------------- - #_threadedupdateGradX!(g,XY,gx) - _threadedupdateGradX!(g,XY,gx) - #Take a prox step with line search - αx, objx = _threadedproxStepX!(g, params, newX, gx, XY, newXY, αx) - reconstruct_obs!(g, XY) #Get the new XY matrix for objective - + for xit in 1:params.inner_iter_X + #_threadedupdateGradX!(g,XY,gx) + _threadedupdateGradX!(g,XY,gx) + #Take a prox step with line search + αx, objx = _threadedproxStepX!(g, params, newX, gx, XY, newXY, αx) + reconstruct_obs!(g, XY) #Get the new XY matrix for objective + end #Y Update--------------------------------------------------------------- - #_threadedupdateGradY!(g,XY,gy) - _threadedupdateGradY!(g,XY,gy) - αy, objy = _threadedproxStepY!(g, params, newY, gy, XY, newXY, αy) - reconstruct_obs!(g, XY) #Get the new XY matrix for objective + for yit in 1:params.inner_iter_Y + #_threadedupdateGradY!(g,XY,gy) + _threadedupdateGradY!(g,XY,gy) + αy, objy = _threadedproxStepY!(g, params, newY, gy, XY, newXY, αy) + reconstruct_obs!(g, XY) #Get the new XY matrix for objective + end if t % 10 == 0 if verbose println("Iteration $t, objective value: $(objy + evaluate(rx, g.X))")