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