meat: compute distance to positive cone

This commit is contained in:
kalmar 2017-02-11 13:48:10 +01:00
parent bebf5dad75
commit 9612dd7b66
1 changed files with 43 additions and 0 deletions

View File

@ -153,3 +153,46 @@ end;
(x, tol::Real) = rationalize(BigInt, x, tol=tol)
function _distance_to_positive_cone(Δ::GroupAlgebraElement,
κ::Float64,
A::Array{Float64,2};
tol=10.0^-7,
verbose=true)
@show maximum(A)
if maximum(A) < 1e-2
warn("Solver might not solved the problem successfully and what You're seeing is due to floating-point error, proceeding anyway...")
end
@assert isapprox(eigvals(A), abs(eigvals(A)), atol=TOL)
@assert A == Symmetric(A)
println("")
A_sqrt = real(sqrtm(A))
println("Checking in floating-point arithmetic...")
@show κ
fp_distance = check_solution(κ, A_sqrt, Δ, verbose=VERBOSE)
println("Distance to positive cone ≈ $(Float64(trunc(fp_distance,8)))")
println("-------------------------------------------------------------")
println("")
println("Checking in rational arithmetic...")
κ_ = (trunc(κ,Int(abs(log10(tol)))), TOL)
@show κ_
@assert κ - κ_ 0
A_sqrt_, Δ_ = (A_sqrt, TOL), (Δ, TOL)
_distance = check_solution(κ_, A_sqrt_, Δ_, verbose=VERBOSE)
@assert isa(_distance, Rational)
println("Distance to positive cone ≈ $(Float64(trunc(_distance,8)))")
println("-------------------------------------------------------------")
println("")
println("Projecting columns of A_sqrt to the augmentation ideal...")
A_sqrt__aug = correct_to_augmentation_ideal(A_sqrt_)
_dist_to_Σ² = check_solution(κ_, A_sqrt__aug, Δ_, verbose=VERBOSE, augmented=true)
@assert isa(_dist_to_Σ², Rational)
s = (_dist_to_Σ² < 0? "": "")
println("Distance to positive cone $s $(Float64(trunc(_dist_to_Σ²,8)))")
return _dist_to_Σ²
end