Skip to content

Commit 3057c2f

Browse files
committed
start adding initial central point finding
1 parent bb654f5 commit 3057c2f

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

examples/robustgeomprog/JuMP.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ example_tests(::Type{RobustGeomProgJuMP{Float64}}, ::FastInstances) = begin
2828
options = (tol_feas = 1e-6, tol_rel_opt = 1e-6, tol_abs_opt = 1e-6)
2929
return [
3030
((5, 10), nothing, options),
31-
((5, 10), ClassicConeOptimizer), nothing, options),
31+
((5, 10), ClassicConeOptimizer, options),
3232
((10, 20), nothing, options),
3333
((20, 40), nothing, options),
3434
((40, 80),),

src/Cones/Cones.jl

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function update_hess_fact(cone::Cone{T}; recover::Bool = true) where {T <: Real}
100100
recover || return false
101101
# TODO if Chol, try adding sqrt(eps(T)) to diag and re-factorize
102102
if T <: BlasReal && cone.hess_fact_cache isa DensePosDefCache{T}
103-
@warn("switching Hessian cache from Cholesky to Bunch Kaufman")
103+
# @warn("switching Hessian cache from Cholesky to Bunch Kaufman")
104104
cone.hess_fact_cache = DenseSymCache{T}()
105105
load_matrix(cone.hess_fact_cache, cone.hess)
106106
else
@@ -253,6 +253,50 @@ end
253253
# # return (nbhd < T(0.5))
254254
# end
255255

256+
# newton for central initial point
257+
# TODO don't run if cone has known central initial point
258+
# TODO remove allocs
259+
function set_central_point(cone::Cone{T}) where {T <: Real}
260+
tol = cbrt(eps(T)) # TODO adjust
261+
max_iter = 10 # TODO make it depend on sqrt(nu)?
262+
damp_tol = 0.2 # TODO tune
263+
nu = get_nu(cone)
264+
265+
curr = zeros(T, dimension(cone))
266+
set_initial_point(curr, cone)
267+
curr .*= sqrt(nu / sum(abs2, curr)) # rescale norm as a heuristic
268+
269+
dir = similar(curr)
270+
iter = 0
271+
while iter < max_iter
272+
load_point(cone, curr)
273+
reset_data(cone)
274+
@assert is_feas(cone)
275+
g = grad(cone)
276+
277+
tmp = -curr - g
278+
# @show norm(tmp)
279+
if norm(tmp, Inf) < tol # TODO tune
280+
iter > 0 && println("final iter $iter, $(norm(tmp, Inf))")
281+
break
282+
end
283+
284+
dir .= cholesky!(Symmetric(hess(cone) + I)) \ tmp # TODO make more efficient, maybe add to cone.hess directly and use hess fact
285+
# inv_hess_prod!(dir, tmp, cone) # cannot use
286+
287+
nnorm = dot(tmp, dir)
288+
@assert nnorm > 0
289+
alpha = (abs(nnorm) > damp_tol ? inv(1 + abs(nnorm)) : one(T))
290+
# @show alpha
291+
# @show nnorm
292+
293+
curr = curr + alpha * dir
294+
iter += 1
295+
end
296+
# @show norm(curr + grad(cone))
297+
298+
return curr
299+
end
256300

257301
# utilities for arrays
258302

src/Solvers/initialize.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,28 @@ function initialize_cone_point(cones::Vector{Cones.Cone{T}}, cone_idxs::Vector{U
99
q = isempty(cones) ? 0 : sum(Cones.dimension, cones)
1010
point = Models.Point(T[], T[], zeros(T, q), zeros(T, q), cones, cone_idxs)
1111

12+
# TODO cleanup
13+
use_newton = true
14+
# use_newton = false
15+
1216
for (k, cone_k) in enumerate(cones)
1317
Cones.setup_data(cone_k)
1418
Cones.set_timer(cone_k, timer)
1519
primal_k = point.primal_views[k]
16-
Cones.set_initial_point(primal_k, cone_k)
20+
if use_newton
21+
primal_k .= Cones.set_central_point(cone_k) # TODO pass in arg?
22+
else
23+
Cones.set_initial_point(primal_k, cone_k)
24+
end
1725
Cones.load_point(cone_k, primal_k)
1826
dual_k = point.dual_views[k]
1927
@assert Cones.is_feas(cone_k)
2028
g = Cones.grad(cone_k)
2129
@. dual_k = -g
22-
Cones.load_dual_point(cone_k, dual_k)
30+
# if use_newton
31+
# @show norm(primal_k - dual_k)
32+
# # @assert primal_k ≈ dual_k rtol=eps(T)^0.25 # TODO delete
33+
# end
2334
hasfield(typeof(cone_k), :hess_fact_cache) && @assert Cones.update_hess_fact(cone_k)
2435
end
2536

src/Solvers/stepper.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ function update_rhs_predcorr(stepper::CombinedStepper{T}, solver::Solver{T}) whe
386386
# end
387387
if corr_viol < 0.001
388388
@. stepper.s_rhs_k[k] += H_prim_dir_k + corr_k
389-
else
390-
println("skip pred-corr: $corr_viol")
389+
# else
390+
# println("skip pred-corr: $corr_viol")
391391
end
392392
end
393393

@@ -444,8 +444,8 @@ function update_rhs_centcorr(stepper::CombinedStepper{T}, solver::Solver{T}) whe
444444
# end
445445
if corr_viol < 0.001
446446
stepper.s_rhs_k[k] .+= corr_k
447-
else
448-
println("skip cent-corr: $corr_viol")
447+
# else
448+
# println("skip cent-corr: $corr_viol")
449449
end
450450
end
451451

0 commit comments

Comments
 (0)