mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-11-19 07:20:28 +01:00
replace all shows and printlns by info(logger,...
This commit is contained in:
parent
94389b887a
commit
02a89908db
@ -36,7 +36,7 @@ function ΔandSDPconstraints(name::String)
|
||||
f₁ = isfile(pm_fname)
|
||||
f₂ = isfile(Δ_fname)
|
||||
if f₁ && f₂
|
||||
println("Loading precomputed pm, Δ, sdp_constraints...")
|
||||
info(logger, "Loading precomputed pm, Δ, sdp_constraints...")
|
||||
product_matrix = load(pm_fname, "pm")
|
||||
L = load(Δ_fname, "Δ")[:, 1]
|
||||
Δ = GroupAlgebraElement(L, Array{Int,2}(product_matrix))
|
||||
@ -60,7 +60,7 @@ function κandA(name::String)
|
||||
f₁ = isfile(κ_fname)
|
||||
f₂ = isfile(SDP_fname)
|
||||
if f₁ && f₂
|
||||
println("Loading precomputed κ, A...")
|
||||
info(logger, "Loading precomputed κ, A...")
|
||||
κ = load(κ_fname, "κ")
|
||||
A = load(SDP_fname, "A")
|
||||
else
|
||||
@ -79,9 +79,11 @@ function timed_msg(t)
|
||||
end
|
||||
|
||||
function κandA(name::String, sdp_constraints, Δ::GroupAlgebraElement, solver::AbstractMathProgSolver; upper_bound=Inf)
|
||||
println("Creating SDP problem...")
|
||||
@time SDP_problem = create_SDP_problem(sdp_constraints, Δ; upper_bound=upper_bound)
|
||||
println("Solving SDP problem maximizing κ...")
|
||||
info(logger, "Creating SDP problem...")
|
||||
t = @timed SDP_problem = create_SDP_problem(sdp_constraints, Δ; upper_bound=upper_bound)
|
||||
info(logger, timed_msg(t))
|
||||
|
||||
info(logger, "Solving SDP problem maximizing κ...")
|
||||
κ, A = solve_SDP(SDP_problem, solver)
|
||||
κ_fname, A_fname = κSDPfilenames(name)
|
||||
if κ > 0
|
||||
@ -94,15 +96,19 @@ function κandA(name::String, sdp_constraints, Δ::GroupAlgebraElement, solver::
|
||||
end
|
||||
|
||||
function check_property_T(name::String, ID, generate_B₄::Function;
|
||||
verbose=true, tol=1e-6, upper_bound=Inf)
|
||||
tol=1e-6, upper_bound=Inf)
|
||||
|
||||
# solver = MosekSolver(INTPNT_CO_TOL_REL_GAP=tol, QUIET=!verbose)
|
||||
solver = SCSSolver(eps=tol, max_iters=100000, verbose=verbose)
|
||||
if !isdir(name)
|
||||
mkdir(name)
|
||||
end
|
||||
|
||||
@show name
|
||||
@show verbose
|
||||
@show tol
|
||||
add_handler(logger, DefaultHandler("./$name/full.log"), "full")
|
||||
add_handler(solver_logger, DefaultHandler("./$name/solver.log"), "solver")
|
||||
info(logger, "Group: $name")
|
||||
info(logger, "Precision: $tol")
|
||||
|
||||
# solver = MosekSolver(INTPNT_CO_TOL_REL_GAP=tol, QUIET=false)
|
||||
solver = SCSSolver(eps=tol, max_iters=1000000, verbose=true)
|
||||
|
||||
Δ, sdp_constraints = try
|
||||
ΔandSDPconstraints(name)
|
||||
@ -110,12 +116,13 @@ function check_property_T(name::String, ID, generate_B₄::Function;
|
||||
if isa(err, ArgumentError)
|
||||
ΔandSDPconstraints(name, ID, generate_B₄)
|
||||
else
|
||||
throw(err)
|
||||
error(logger, err)
|
||||
end
|
||||
end
|
||||
println("|S| = $(countnz(Δ.coefficients) -1)")
|
||||
@show length(Δ)
|
||||
@show size(Δ.product_matrix)
|
||||
|
||||
info(logger, "|S| = $(countnz(Δ.coefficients) - 1)")
|
||||
info(logger, "length(Δ) = $(length(Δ))")
|
||||
info(logger, "size(Δ.product_matrix) = $(size(Δ.product_matrix))")
|
||||
|
||||
κ, A = try
|
||||
κandA(name)
|
||||
@ -123,26 +130,26 @@ function check_property_T(name::String, ID, generate_B₄::Function;
|
||||
if isa(err, ArgumentError)
|
||||
κandA(name, sdp_constraints, Δ, solver; upper_bound=upper_bound)
|
||||
else
|
||||
throw(err)
|
||||
# throw(err)
|
||||
error(logger, err)
|
||||
end
|
||||
end
|
||||
|
||||
@show κ
|
||||
@show sum(A)
|
||||
@show maximum(A)
|
||||
@show minimum(A)
|
||||
info(logger, "κ = $κ")
|
||||
info(logger, "sum(A) = $(sum(A))")
|
||||
info(logger, "maximum(A) = $(maximum(A))")
|
||||
info(logger, "minimum(A) = $(minimum(A))")
|
||||
|
||||
if κ > 0
|
||||
|
||||
true_kappa = check_distance_to_positive_cone(Δ, κ, A, tol=tol, verbose=verbose, rational=false)
|
||||
true_kappa = check_distance_to_positive_cone(Δ, κ, A, tol=tol, rational=false)
|
||||
true_kappa = Float64(trunc(true_kappa,12))
|
||||
if true_kappa > 0
|
||||
println("κ($name, S) ≥ $true_kappa: Group HAS property (T)!")
|
||||
info(logger, "κ($name, S) ≥ $true_kappa: Group HAS property (T)!")
|
||||
else
|
||||
println("κ($name, S) ≥ $true_kappa: Group may NOT HAVE property (T)!")
|
||||
info(logger, "κ($name, S) ≥ $true_kappa: Group may NOT HAVE property (T)!")
|
||||
end
|
||||
else
|
||||
println("κ($name, S) ≥ $κ < 0: Tells us nothing about property (T)")
|
||||
info(logger, "κ($name, S) ≥ $κ < 0: Tells us nothing about property (T)")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -61,99 +61,94 @@ end
|
||||
|
||||
ℚ(x, tol::Real) = rationalize(BigInt, x, tol=tol)
|
||||
|
||||
function distance_to_cone{T<:Rational}(κ::T, sqrt_matrix::Array{T,2}, Δ::GroupAlgebraElement{T}; verbose=true, augmented=false)
|
||||
function distance_to_cone{T<:Rational}(κ::T, sqrt_matrix::Array{T,2}, Δ::GroupAlgebraElement{T})
|
||||
SOS = compute_SOS(sqrt_matrix, Δ)
|
||||
if augmented
|
||||
epsilon = GroupAlgebras.ɛ(SOS)
|
||||
@show epsilon
|
||||
end
|
||||
|
||||
SOS_diff = EOI(Δ, κ) - SOS
|
||||
eoi_SOS_L₁_dist = norm(SOS_diff,1)
|
||||
|
||||
if verbose
|
||||
@show κ
|
||||
ɛ_dist = GroupAlgebras.ɛ(SOS_diff)
|
||||
L₁_dist = eoi_SOS_L₁_dist
|
||||
@printf("ɛ(Δ² - κΔ - ∑ξᵢ*ξᵢ) = %.10f\n", float(ɛ_dist))
|
||||
@printf("‖Δ² - κΔ - ∑ξᵢ*ξᵢ‖₁ = %.10f\n", float(L₁_dist))
|
||||
info(logger, "κ = $κ")
|
||||
ɛ_dist = GroupAlgebras.ɛ(SOS_diff)
|
||||
if ɛ_dist ≠ 0//1
|
||||
warn(logger, "The SOS is not in the augmentation ideal, number below are meaningless!")
|
||||
end
|
||||
info(logger, "ɛ(Δ² - κΔ - ∑ξᵢ*ξᵢ) = $ɛ_dist")
|
||||
info(logger, "‖Δ² - κΔ - ∑ξᵢ*ξᵢ‖₁ = $(@sprintf("%.10f", float(eoi_SOS_L₁_dist)))")
|
||||
|
||||
distance_to_cone = κ - 2^3*eoi_SOS_L₁_dist
|
||||
return distance_to_cone
|
||||
end
|
||||
|
||||
function distance_to_cone{T<:Rational, S<:Interval}(κ::T, sqrt_matrix::Array{S,2}, Δ::GroupAlgebraElement{T}; verbose=true)
|
||||
function distance_to_cone{T<:Rational, S<:Interval}(κ::T, sqrt_matrix::Array{S,2}, Δ::GroupAlgebraElement{T})
|
||||
SOS = compute_SOS(sqrt_matrix, Δ)
|
||||
verbose && println("ɛ(∑ξᵢ*ξᵢ) ∈ $(GroupAlgebras.ɛ(SOS))")
|
||||
info(logger, "ɛ(∑ξᵢ*ξᵢ) ∈ $(GroupAlgebras.ɛ(SOS))")
|
||||
|
||||
SOS_diff = EOI(Δ, κ) - SOS
|
||||
eoi_SOS_L₁_dist = norm(SOS_diff,1)
|
||||
|
||||
if verbose
|
||||
@show κ
|
||||
ɛ_dist = GroupAlgebras.ɛ(SOS_diff)
|
||||
info(logger, "κ = $κ")
|
||||
ɛ_dist = GroupAlgebras.ɛ(SOS_diff)
|
||||
|
||||
info(logger, "ɛ(Δ² - κΔ - ∑ξᵢ*ξᵢ) ∈ $(ɛ_dist)")
|
||||
info(logger, "‖Δ² - κΔ - ∑ξᵢ*ξᵢ‖₁ ∈ $(eoi_SOS_L₁_dist)")
|
||||
|
||||
println("ɛ(Δ² - κΔ - ∑ξᵢ*ξᵢ) ∈ $(ɛ_dist)")
|
||||
println("‖Δ² - κΔ - ∑ξᵢ*ξᵢ‖₁ ∈ $(eoi_SOS_L₁_dist)")
|
||||
end
|
||||
distance_to_cone = κ - 2^3*eoi_SOS_L₁_dist
|
||||
return distance_to_cone
|
||||
end
|
||||
|
||||
function distance_to_cone{T<:AbstractFloat}(κ::T, sqrt_matrix::Array{T,2}, Δ::GroupAlgebraElement{T}; verbose=true)
|
||||
function distance_to_cone{T<:AbstractFloat}(κ::T, sqrt_matrix::Array{T,2}, Δ::GroupAlgebraElement{T})
|
||||
SOS = compute_SOS(sqrt_matrix, Δ)
|
||||
|
||||
SOS_diff = EOI(Δ, κ) - SOS
|
||||
eoi_SOS_L₁_dist = norm(SOS_diff,1)
|
||||
|
||||
if verbose
|
||||
println("κ = $κ (≈$(float(κ)))")
|
||||
ɛ_dist = GroupAlgebras.ɛ(SOS_diff)
|
||||
@printf("ɛ(Δ² - κΔ - ∑ξᵢ*ξᵢ) ≈ %.10f\n", ɛ_dist)
|
||||
@printf("‖Δ² - κΔ - ∑ξᵢ*ξᵢ‖₁ ≈ %.10f\n", eoi_SOS_L₁_dist)
|
||||
end
|
||||
info(logger, "κ = $κ (≈$(float(κ)))")
|
||||
ɛ_dist = GroupAlgebras.ɛ(SOS_diff)
|
||||
info(logger, "ɛ(Δ² - κΔ - ∑ξᵢ*ξᵢ) ≈ $(@sprintf("%.10f\n", ɛ_dist))")
|
||||
info(logger, "‖Δ² - κΔ - ∑ξᵢ*ξᵢ‖₁ ≈ $(@sprintf("%.10f\n", eoi_SOS_L₁_dist))")
|
||||
|
||||
distance_to_cone = κ - 2^3*eoi_SOS_L₁_dist
|
||||
return distance_to_cone
|
||||
end
|
||||
|
||||
function check_distance_to_positive_cone(Δ::GroupAlgebraElement, κ, A;
|
||||
tol=1e-7, verbose=true, rational=false)
|
||||
tol=1e-7, rational=false)
|
||||
|
||||
isapprox(eigvals(A), abs(eigvals(A)), atol=tol) ||
|
||||
warn("The solution matrix doesn't seem to be positive definite!")
|
||||
@assert A == Symmetric(A)
|
||||
A_sqrt = real(sqrtm(A))
|
||||
|
||||
println("-------------------------------------------------------------")
|
||||
println("")
|
||||
println("Checking in floating-point arithmetic...")
|
||||
@time fp_distance = distance_to_cone(κ, A_sqrt, Δ, verbose=verbose)
|
||||
println("Floating point distance (to positive cone)\n ≈ $(Float64(trunc(fp_distance,10)))")
|
||||
println("-------------------------------------------------------------")
|
||||
println("")
|
||||
info(logger, "-------------------------------------------------------------")
|
||||
info(logger, "")
|
||||
info(logger, "Checking in floating-point arithmetic...")
|
||||
@time fp_distance = distance_to_cone(κ, A_sqrt, Δ)
|
||||
info(logger, "Floating point distance (to positive cone)\n ≈ $(Float64(trunc(fp_distance,10)))")
|
||||
info(logger, "-------------------------------------------------------------")
|
||||
info(logger, "")
|
||||
|
||||
println("Projecting columns of rationalized A_sqrt to the augmentation ideal...")
|
||||
info(logger, "Projecting columns of rationalized A_sqrt to the augmentation ideal...")
|
||||
δ = eps(κ)
|
||||
A_sqrt_ℚ = ℚ(A_sqrt, δ)
|
||||
A_sqrt_ℚ_aug = correct_to_augmentation_ideal(A_sqrt_ℚ)
|
||||
κ_ℚ = ℚ(κ, δ)
|
||||
Δ_ℚ = ℚ(Δ, δ)
|
||||
|
||||
println("Checking in interval arithmetic")
|
||||
info(logger, "Checking in interval arithmetic")
|
||||
A_sqrt_ℚ_augᴵ = A_sqrt_ℚ_aug ± δ
|
||||
@time Interval_dist_to_Σ² = distance_to_cone(κ_ℚ, A_sqrt_ℚ_augᴵ, Δ_ℚ, verbose=verbose)
|
||||
println("The Augmentation-projected actual distance (to positive cone) belongs to \n$Interval_dist_to_Σ²")
|
||||
println("-------------------------------------------------------------")
|
||||
println("")
|
||||
@time Interval_dist_to_Σ² = distance_to_cone(κ_ℚ, A_sqrt_ℚ_augᴵ, Δ_ℚ)
|
||||
info(logger, "The Augmentation-projected actual distance (to positive cone) belongs to \n$Interval_dist_to_Σ²")
|
||||
info(logger, "-------------------------------------------------------------")
|
||||
info(logger, "")
|
||||
|
||||
if Interval_dist_to_Σ².lo ≤ 0
|
||||
return Interval_dist_to_Σ².lo
|
||||
else
|
||||
println("Checking Projected SOS decomposition in exact rational arithmetic...")
|
||||
@time ℚ_dist_to_Σ² = distance_to_cone(κ_ℚ, A_sqrt_ℚ_aug, Δ_ℚ, verbose=verbose, augmented=true)
|
||||
info(logger, "Checking Projected SOS decomposition in exact rational arithmetic...")
|
||||
@time ℚ_dist_to_Σ² = distance_to_cone(κ_ℚ, A_sqrt_ℚ_aug, Δ_ℚ, augmented=true)
|
||||
@assert isa(ℚ_dist_to_Σ², Rational)
|
||||
println("Augmentation-projected rational distance (to positive cone)\n ≥ $(Float64(trunc(ℚ_dist_to_Σ²,8)))")
|
||||
println("-------------------------------------------------------------")
|
||||
info(logger, "Augmentation-projected rational distance (to positive cone)\n ≥ $(Float64(trunc(ℚ_dist_to_Σ²,8)))")
|
||||
info(logger, "-------------------------------------------------------------")
|
||||
return ℚ_dist_to_Σ²
|
||||
end
|
||||
end
|
||||
|
@ -68,8 +68,8 @@ function create_SDP_problem(matrix_constraints, Δ::GroupAlgebraElement; upper_b
|
||||
end
|
||||
|
||||
function solve_SDP(SDP_problem, solver)
|
||||
@show SDP_problem
|
||||
@show solver
|
||||
info(logger, Base.repr(m))
|
||||
info(logger, solver)
|
||||
|
||||
JuMP.setsolver(SDP_problem, solver);
|
||||
# @time MathProgBase.writeproblem(SDP_problem, "/tmp/SDP_problem")
|
||||
@ -78,7 +78,7 @@ function solve_SDP(SDP_problem, solver)
|
||||
if solution_status != :Optimal
|
||||
warn("The solver did not solve the problem successfully!")
|
||||
end
|
||||
@show solution_status
|
||||
info(logger, solution_status)
|
||||
|
||||
κ = JuMP.getvalue(JuMP.getvariable(SDP_problem, :κ))
|
||||
A = JuMP.getvalue(JuMP.getvariable(SDP_problem, :A))
|
||||
|
Loading…
Reference in New Issue
Block a user