Skip to content

Commit 0ca6b5e

Browse files
committed
less storing, more consistent names
1 parent 43d1ae7 commit 0ca6b5e

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

src/algorithms/drls.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ update_direction_state!(iter::DRLSIteration, state::DRLSState) =
147147

148148
function Base.iterate(iter::DRLSIteration{R,Tx,Tf}, state::DRLSState) where {R,Tx,Tf}
149149
# retrieve merit and set threshold
150-
DRE_curr = state.merit
151-
threshold = iter.dre_sign * DRE_curr - iter.c / iter.gamma * norm(state.res)^2
150+
DRE_x = state.merit
151+
threshold = iter.dre_sign * DRE_x - iter.c / iter.gamma * norm(state.res)^2
152152

153153
set_next_direction!(iter, state)
154154

@@ -163,13 +163,14 @@ function Base.iterate(iter::DRLSIteration{R,Tx,Tf}, state::DRLSState) where {R,T
163163
state.g_v = prox!(state.v, iter.g, state.w, iter.gamma)
164164
state.res .= state.u .- state.v
165165
state.xbar .= state.x .- iter.lambda * state.res
166+
DRE_x = DRE(state)
166167

167168
update_direction_state!(iter, state)
168169

169170
a, b, c = R(0), R(0), R(0)
170171

171172
for k = 1:iter.max_backtracks
172-
if iter.dre_sign * DRE(state) <= threshold
173+
if iter.dre_sign * DRE_x <= threshold
173174
break
174175
end
175176

@@ -195,9 +196,10 @@ function Base.iterate(iter::DRLSIteration{R,Tx,Tf}, state::DRLSState) where {R,T
195196
state.g_v = prox!(state.v, iter.g, state.w, iter.gamma)
196197
state.res .= state.u .- state.v
197198
state.xbar .= state.x .- iter.lambda * state.res
199+
DRE_x = DRE(state)
198200
end
199201
# update merit with averaging rule
200-
state.merit = (1 - iter.monotonicity) * state.merit + iter.monotonicity * DRE(state)
202+
state.merit = (1 - iter.monotonicity) * state.merit + iter.monotonicity * DRE_x
201203

202204
return state, state
203205
end

src/algorithms/panoc.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function Base.iterate(iter::PANOCIteration{R,Tx,Tf}, state::PANOCState) where {R
145145

146146
if iter.adaptive == true
147147
gamma_prev = state.gamma
148-
state.gamma, state.g_z, f_Az, f_Az_upp = backtrack_stepsize!(
148+
state.gamma, state.g_z, f_Az, _ = backtrack_stepsize!(
149149
state.gamma,
150150
iter.f,
151151
iter.A,
@@ -201,10 +201,10 @@ function Base.iterate(iter::PANOCIteration{R,Tx,Tf}, state::PANOCState) where {R
201201
state.y .= state.x .- state.gamma .* state.At_grad_f_Ax
202202
state.g_z = prox!(state.z, iter.g, state.y, state.gamma)
203203
state.res .= state.x .- state.z
204-
FBE_x_new = f_model(iter, state) + state.g_z
204+
FBE_x = f_model(iter, state) + state.g_z
205205

206206
for k = 1:iter.max_backtracks
207-
if FBE_x_new <= threshold
207+
if FBE_x <= threshold
208208
break
209209
end
210210

@@ -248,12 +248,12 @@ function Base.iterate(iter::PANOCIteration{R,Tx,Tf}, state::PANOCState) where {R
248248
state.y .= state.x .- state.gamma .* state.At_grad_f_Ax
249249
state.g_z = prox!(state.z, iter.g, state.y, state.gamma)
250250
state.res .= state.x .- state.z
251-
FBE_x_new = f_model(iter, state) + state.g_z
251+
FBE_x = f_model(iter, state) + state.g_z
252252
end
253253

254254
update_direction_state!(iter, state)
255255
# update merit with averaging rule
256-
state.merit = (1 - iter.monotonicity) * state.merit + iter.monotonicity * FBE_x_new
256+
state.merit = (1 - iter.monotonicity) * state.merit + iter.monotonicity * FBE_x
257257
return state, state
258258
end
259259

src/algorithms/panocplus.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ function Base.iterate(iter::PANOCplusIteration{R}) where {R}
124124
)
125125
else
126126
mul!(state.Az, iter.A, state.z)
127-
f_Az, grad_f_Az = value_and_gradient(iter.f, state.Az)
128-
state.grad_f_Az = grad_f_Az
127+
_, state.grad_f_Az = value_and_gradient(iter.f, state.Az)
129128
end
130129
mul!(state.At_grad_f_Az, adjoint(iter.A), state.grad_f_Az)
131130
# initialize merit
@@ -183,7 +182,6 @@ function Base.iterate(iter::PANOCplusIteration{R}, state::PANOCplusState) where
183182

184183
tau_backtracks = 0
185184
can_update_direction = true
186-
FBE_x_new = R(0)
187185

188186
while true
189187

@@ -229,8 +227,8 @@ function Base.iterate(iter::PANOCplusIteration{R}, state::PANOCplusState) where
229227
end
230228
mul!(state.At_grad_f_Az, adjoint(iter.A), state.grad_f_Az)
231229

232-
FBE_x_new = f_Az_upp + state.g_z
233-
if FBE_x_new <= threshold || tau_backtracks >= iter.max_backtracks
230+
FBE_x = f_Az_upp + state.g_z
231+
if FBE_x <= threshold || tau_backtracks >= iter.max_backtracks
234232
break
235233
end
236234
state.tau = tau_backtracks >= iter.max_backtracks - 1 ? R(0) : state.tau / 2
@@ -241,7 +239,7 @@ function Base.iterate(iter::PANOCplusIteration{R}, state::PANOCplusState) where
241239
update_direction_state!(iter, state)
242240

243241
# update merit with averaging rule
244-
state.merit = (1 - iter.monotonicity) * state.merit + iter.monotonicity * FBE_x_new
242+
state.merit = (1 - iter.monotonicity) * state.merit + iter.monotonicity * FBE_x
245243

246244
return state, state
247245

src/algorithms/zerofpr.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ reset_direction_state!(iter::ZeroFPRIteration, state::ZeroFPRState) =
145145
reset_direction_state!(acceleration_style(typeof(iter.directions)), iter, state)
146146

147147
function Base.iterate(iter::ZeroFPRIteration{R}, state::ZeroFPRState) where {R}
148-
f_Axbar_upp, f_Axbar = if iter.adaptive == true
148+
if iter.adaptive == true
149149
gamma_prev = state.gamma
150-
state.gamma, state.g_xbar, f_Axbar, f_Axbar_upp = backtrack_stepsize!(
150+
state.gamma, state.g_xbar, _, _ = backtrack_stepsize!(
151151
state.gamma,
152152
iter.f,
153153
iter.A,
@@ -167,18 +167,15 @@ function Base.iterate(iter::ZeroFPRIteration{R}, state::ZeroFPRState) where {R}
167167
if state.gamma != gamma_prev
168168
reset_direction_state!(iter, state)
169169
end
170-
f_Axbar_upp, f_Axbar
171170
else
172171
mul!(state.Axbar, iter.A, state.xbar)
173-
f_Axbar, grad_f_Axbar = value_and_gradient(iter.f, state.Axbar)
174-
state.grad_f_Axbar .= grad_f_Axbar
175-
f_model(iter, state), f_Axbar
172+
_, state.grad_f_Axbar = value_and_gradient(iter.f, state.Axbar)
176173
end
177174

178175
# compute residual at xbar
179176
mul!(state.At_grad_f_Axbar, iter.A', state.grad_f_Axbar)
180177
state.y .= state.xbar .- state.gamma .* state.At_grad_f_Axbar
181-
g_xbarbar = prox!(state.xbarbar, iter.g, state.y, state.gamma)
178+
prox!(state.xbarbar, iter.g, state.y, state.gamma)
182179
state.res_xbar .= state.xbar .- state.xbarbar
183180

184181
if state.is_prev_set == true

0 commit comments

Comments
 (0)