33
44export tron
55
6- tron (nlp :: AbstractNLPModel ; variant= :Newton , kwargs... ) = tron (Val (variant), nlp; kwargs... )
6+ tron (nlp:: AbstractNLPModel ; variant = :Newton , kwargs... ) = tron (Val (variant), nlp; kwargs... )
77
88"""
99 tron(nlp)
@@ -18,24 +18,24 @@ TRON is described in
1818Chih-Jen Lin and Jorge J. Moré, *Newton's Method for Large Bound-Constrained
1919Optimization Problems*, SIAM J. Optim., 9(4), 1100–1127, 1999.
2020"""
21- function tron (:: Val{:Newton} ,
22- nlp :: AbstractNLPModel ;
23- subsolver_logger :: AbstractLogger = NullLogger (),
24- x :: AbstractVector = copy (nlp . meta . x0 ),
25- μ₀ :: Real = eltype (x)( 1e-2 ),
26- μ₁ :: Real = one ( eltype (x)),
27- σ :: Real = eltype (x)( 10 ),
28- max_eval :: Int = - 1 ,
29- max_time :: Real = 30.0 ,
30- max_cgiter :: Int = 50 ,
31- use_only_objgrad :: Bool = false ,
32- cgtol :: Real = eltype (x)( 0.1 ) ,
33- atol :: Real = √ eps ( eltype (x)),
34- rtol :: Real = √ eps (eltype (x)),
35- fatol :: Real = zero (eltype (x)),
36- frtol :: Real = eps (eltype (x))^ eltype (x)( 2 / 3 )
37- )
38-
21+ function tron (
22+ :: Val{:Newton} ,
23+ nlp :: AbstractNLPModel ;
24+ subsolver_logger :: AbstractLogger = NullLogger ( ),
25+ x :: AbstractVector = copy (nlp . meta . x0 ),
26+ μ₀ :: Real = eltype (x)( 1e-2 ),
27+ μ₁ :: Real = one ( eltype (x)),
28+ σ :: Real = eltype (x)( 10 ) ,
29+ max_eval :: Int = - 1 ,
30+ max_time :: Real = 30.0 ,
31+ max_cgiter :: Int = 50 ,
32+ use_only_objgrad :: Bool = false ,
33+ cgtol :: Real = eltype (x)( 0.1 ),
34+ atol :: Real = √ eps (eltype (x)),
35+ rtol :: Real = √ eps (eltype (x)),
36+ fatol :: Real = zero (eltype (x)),
37+ frtol :: Real = eps ( eltype (x)) ^ eltype (x)( 2 / 3 ),
38+ )
3939 if ! (unconstrained (nlp) || bound_constrained (nlp))
4040 error (" tron should only be called for unconstrained or bound-constrained problems" )
4141 end
@@ -79,16 +79,19 @@ function tron(::Val{:Newton},
7979
8080 αC = one (T)
8181 tr = TRONTrustRegion (min (max (one (T), πx / 10 ), 100 ))
82- @info log_header ([:iter , :f , :dual , :radius , :ratio , :cgstatus ], [Int, T, T, T, T, String],
83- hdr_override= Dict (:f => " f(x)" , :dual => " π" , :radius => " Δ" ))
82+ @info log_header (
83+ [:iter , :f , :dual , :radius , :ratio , :cgstatus ],
84+ [Int, T, T, T, T, String],
85+ hdr_override = Dict (:f => " f(x)" , :dual => " π" , :radius => " Δ" ),
86+ )
8487 while ! (optimal || tired || stalled || unbounded)
8588 # Current iteration
8689 xc .= x
8790 fc = fx
8891 Δ = get_property (tr, :radius )
8992 H = hess_op! (nlp, xc, temp)
9093
91- αC, s, cauchy_status = cauchy (x, H, gx, Δ, αC, ℓ, u, μ₀= μ₀, μ₁= μ₁, σ= σ)
94+ αC, s, cauchy_status = cauchy (x, H, gx, Δ, αC, ℓ, u, μ₀ = μ₀, μ₁ = μ₁, σ = σ)
9295
9396 if cauchy_status != :success
9497 @error " Cauchy step returned: $cauchy_status "
@@ -97,7 +100,7 @@ function tron(::Val{:Newton},
97100 continue
98101 end
99102 s, Hs, cgits, cginfo = with_logger (subsolver_logger) do
100- projected_newton! (x, H, gx, Δ, cgtol, s, ℓ, u, max_cgiter= max_cgiter)
103+ projected_newton! (x, H, gx, Δ, cgtol, s, ℓ, u, max_cgiter = max_cgiter)
101104 end
102105 slope = dot (n, gx, s)
103106 qs = dot (n, s, Hs) / 2 + slope
@@ -153,7 +156,6 @@ function tron(::Val{:Newton},
153156 tired = el_time > max_time || neval_obj (nlp) > max_eval ≥ 0
154157 optimal = πx <= ϵ
155158 unbounded = fx < fmin
156-
157159 end
158160 @info log_row (Any[iter, fx, πx, get_property (tr, :radius )])
159161
@@ -169,8 +171,16 @@ function tron(::Val{:Newton},
169171 status = :unbounded
170172 end
171173
172- return GenericExecutionStats (status, nlp, solution= x, objective= fx, dual_feas= πx,
173- primal_feas= zero (eltype (x)), iter= iter, elapsed_time= el_time)
174+ return GenericExecutionStats (
175+ status,
176+ nlp,
177+ solution = x,
178+ objective = fx,
179+ dual_feas = πx,
180+ primal_feas = zero (eltype (x)),
181+ iter = iter,
182+ elapsed_time = el_time,
183+ )
174184end
175185
176186""" `s = projected_line_search!(x, H, g, d, ℓ, u; μ₀ = 1e-2)`
@@ -182,12 +192,15 @@ Performs a projected line search, searching for a step size `t` such that
182192where `s = P(x + t * d) - x`, while remaining on the same face as `x + d`.
183193Backtracking is performed from t = 1.0. `x` is updated in place.
184194"""
185- function projected_line_search! (x:: AbstractVector{T} ,
186- H:: Union{AbstractMatrix,AbstractLinearOperator} ,
187- g:: AbstractVector{T} ,
188- d:: AbstractVector{T} ,
189- ℓ:: AbstractVector{T} ,
190- u:: AbstractVector{T} ; μ₀:: Real = T (1e-2 )) where T <: Real
195+ function projected_line_search! (
196+ x:: AbstractVector{T} ,
197+ H:: Union{AbstractMatrix, AbstractLinearOperator} ,
198+ g:: AbstractVector{T} ,
199+ d:: AbstractVector{T} ,
200+ ℓ:: AbstractVector{T} ,
201+ u:: AbstractVector{T} ;
202+ μ₀:: Real = T (1e-2 ),
203+ ) where {T <: Real }
191204 α = one (T)
192205 _, brkmin, _ = breakpoints (x, d, ℓ, u)
193206 nsteps = 0
@@ -229,11 +242,18 @@ with the sufficient decrease condition
229242
230243 q(s) ≦ μ₀sᵀg.
231244"""
232- function cauchy (x:: AbstractVector{T} ,
233- H:: Union{AbstractMatrix,AbstractLinearOperator} ,
234- g:: AbstractVector{T} ,
235- Δ:: Real , α:: Real , ℓ:: AbstractVector{T} , u:: AbstractVector{T} ;
236- μ₀:: Real = T (1e-2 ), μ₁:: Real = one (T), σ:: Real = T (10 )) where T <: Real
245+ function cauchy (
246+ x:: AbstractVector{T} ,
247+ H:: Union{AbstractMatrix, AbstractLinearOperator} ,
248+ g:: AbstractVector{T} ,
249+ Δ:: Real ,
250+ α:: Real ,
251+ ℓ:: AbstractVector{T} ,
252+ u:: AbstractVector{T} ;
253+ μ₀:: Real = T (1e-2 ),
254+ μ₁:: Real = one (T),
255+ σ:: Real = T (10 ),
256+ ) where {T <: Real }
237257 # TODO : Use brkmin to care for g direction
238258 _, _, brkmax = breakpoints (x, - g, ℓ, u)
239259 n = length (x)
@@ -302,10 +322,17 @@ min q(d) = ¹/₂dᵀHs + dᵀg s.t. ℓ ≦ x + d ≦ u, ‖d‖ ≦ Δ
302322starting from `s`. The steps are computed using the conjugate gradient method
303323projected on the active bounds.
304324"""
305- function projected_newton! (x:: AbstractVector{T} , H:: Union{AbstractMatrix,AbstractLinearOperator} ,
306- g:: AbstractVector{T} , Δ:: Real , cgtol:: Real , s:: AbstractVector{T} ,
307- ℓ:: AbstractVector{T} , u:: AbstractVector{T} ;
308- max_cgiter:: Int = 50 ) where T <: Real
325+ function projected_newton! (
326+ x:: AbstractVector{T} ,
327+ H:: Union{AbstractMatrix, AbstractLinearOperator} ,
328+ g:: AbstractVector{T} ,
329+ Δ:: Real ,
330+ cgtol:: Real ,
331+ s:: AbstractVector{T} ,
332+ ℓ:: AbstractVector{T} ,
333+ u:: AbstractVector{T} ;
334+ max_cgiter:: Int = 50 ,
335+ ) where {T <: Real }
309336 n = length (x)
310337 status = " "
311338
@@ -330,7 +357,7 @@ function projected_newton!(x::AbstractVector{T}, H::Union{AbstractMatrix,Abstrac
330357 gfnorm = norm (wa)
331358
332359 ZHZ = Z' * H * Z
333- st, stats = Krylov. cg (ZHZ, - gfree, radius= Δ, rtol= cgtol, atol= zero (T))
360+ st, stats = Krylov. cg (ZHZ, - gfree, radius = Δ, rtol = cgtol, atol = zero (T))
334361 iters += 1
335362 status = stats. status
336363
0 commit comments