1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-11-13 22:05:27 +01:00

Change names: kappa -> lambda, A -> P

This commit is contained in:
kalmar 2017-04-01 15:21:57 +02:00
parent 028979bfd1
commit 5876998cba
3 changed files with 86 additions and 85 deletions

View File

@ -20,14 +20,14 @@ function pmΔfilenames(name::String)
return pm_filename, Δ_coeff_filename
end
function κSDPfilenames(name::String)
function λSDPfilenames(name::String)
if !isdir(name)
mkdir(name)
end
prefix = name
κ_filename = joinpath(prefix, "kappa.jld")
SDP_filename = joinpath(prefix, "SDPmatrixA.jld")
return κ_filename, SDP_filename
λ_filename = joinpath(prefix, "lambda.jld")
SDP_filename = joinpath(prefix, "SDPmatrix.jld")
return λ_filename, SDP_filename
end
function ΔandSDPconstraints(name::String)
@ -63,18 +63,19 @@ function ΔandSDPconstraints(name::String, generating_set::Function, radius::Int
end
end
function κandA(name::String)
κ_fname, SDP_fname = κSDPfilenames(name)
f₁ = isfile(κ_fname)
function λandP(name::String)
λ_fname, SDP_fname = λSDPfilenames(name)
f₁ = isfile(λ_fname)
f₂ = isfile(SDP_fname)
if f₁ && f₂
info(logger, "Loading precomputed κ, A...")
κ = load(κ_fname, "κ")
A = load(SDP_fname, "A")
info(logger, "Loading precomputed λ, P...")
λ = load(λ_fname, "λ")
P = load(SDP_fname, "P")
else
throw(ArgumentError("You need to precompute κ and SDP matrix A to load it!"))
throw(ArgumentError("You need to precompute λ and SDP matrix P to load it!"))
end
return κ, A
return λ, P
end
function timed_msg(t)
@ -87,32 +88,32 @@ function timed_msg(t)
end
function κandA(name::String, opts...)
function λandP(name::String, opts...)
try
return κandA(name)
return λandP(name)
catch err
if isa(err, ArgumentError)
if isfile("$name/solver.log")
rm("$name/solver.log")
if isfile(joinpath(name, "solver.log"))
rm(joinpath(name, "solver.log"))
end
add_handler(solver_logger, DefaultHandler("./$name/solver.log", DefaultFormatter("{date}| {msg}")), "solver_log")
add_handler(solver_logger, DefaultHandler(joinpath(name, "solver.log"), DefaultFormatter("{date}| {msg}")), "solver_log")
info(logger, "Creating SDP problem...")
κ, A = compute_κandA(opts...)
λ, P = compute_λandP(opts...)
remove_handler(solver_logger, "solver_log")
κ_fname, A_fname = κSDPfilenames(name)
λ_fname, P_fname = λSDPfilenames(name)
if κ > 0
save(κ_fname, "κ", κ)
save(A_fname, "A", A)
if λ > 0
save(λ_fname, "λ", λ)
save(P_fname, "P", P)
else
throw(ErrorException("Solver $solver did not produce a valid solution!: κ = "))
throw(ErrorException("Solver $solver did not produce a valid solution!: λ = "))
end
return κ, A
return λ, P
else
# throw(err)
@ -121,21 +122,21 @@ function κandA(name::String, opts...)
end
end
function compute_κandA(sdp_constraints, Δ::GroupAlgebraElement, solver::AbstractMathProgSolver, upper_bound=Inf)
function compute_λandP(sdp_constraints, Δ::GroupAlgebraElement, solver::AbstractMathProgSolver, upper_bound=Inf)
t = @timed SDP_problem = create_SDP_problem(sdp_constraints, Δ; upper_bound=upper_bound)
info(logger, timed_msg(t))
κ = 0.0
A = nothing
while κ == 0.0
λ = 0.0
P = nothing
while λ == 0.0
try
κ, A = solve_SDP(SDP_problem, solver)
λ, P = solve_SDP(SDP_problem, solver)
catch y
warn(solver_logger, y)
end
end
return κ, A
return λ, P
end
Kazhdan_from_sgap(λ,N) = sqrt(2*λ/N)
@ -160,29 +161,29 @@ function check_property_T(name::String, generating_set::Function,
info(logger, "length(Δ) = $(length(Δ))")
info(logger, "size(Δ.product_matrix) = $(size(Δ.product_matrix))")
κ, A = κandA(name, sdp_constraints, Δ, solver, upper_bound)
λ, P = λandP(name, sdp_constraints, Δ, solver, upper_bound)
info(logger, "κ = ")
info(logger, "sum(A) = $(sum(A))")
info(logger, "maximum(A) = $(maximum(A))")
info(logger, "minimum(A) = $(minimum(A))")
info(logger, "λ = ")
info(logger, "sum(P) = $(sum(P))")
info(logger, "maximum(P) = $(maximum(P))")
info(logger, "minimum(P) = $(minimum(P))")
if κ > 0
spectral_gap = check_distance_to_positive_cone(Δ, κ, A, tol=tol, rational=false)
if λ > 0
spectral_gap = check_distance_to_positive_cone(Δ, λ, P, tol=tol, rational=false)
if isa(spectral_gap, Interval)
spectral_gap = spectral_gap.lo
end
if spectral_gap > 0
@show spectral_gap
Kazhdan_const = Kazhdan_from_sgap(spectral_gap, S)
Kazhdan_const = Float64(trunc(Kazhdan_const, 12))
info(logger, "κ($name, S) ≥ $Kazhdan_const: Group HAS property (T)!")
Kazhdan_κ = Kazhdan_from_sgap(spectral_gap, S)
Kazhdan_κ = Float64(trunc(Kazhdan_κ, 12))
info(logger, "κ($name, S) ≥ $Kazhdan_κ: Group HAS property (T)!")
else
spectral_gap = Float64(trunc(spectral_gap, 12))
info(logger, "λ($name, S) ≥ $spectral_gap: Group may NOT HAVE property (T)!")
end
else
info(logger, "κ($name, S) ≥ $κ < 0: Tells us nothing about property (T)")
info(logger, "κ($name, S) ≥ $λ < 0: Tells us nothing about property (T)")
end
end

View File

@ -6,8 +6,8 @@ ValidatedNumerics.setrounding(Interval, :correct)
ValidatedNumerics.setformat(:standard)
# setprecision(Interval, 53) # slightly faster than 256
function EOI{T<:Number}(Δ::GroupAlgebraElement{T}, κ::T)
return Δ*Δ - κ*Δ
function EOI{T<:Number}(Δ::GroupAlgebraElement{T}, λ::T)
return Δ*Δ - λ*Δ
end
function algebra_square(vector, elt)
@ -62,69 +62,69 @@ end
(x, tol::Real) = rationalize(BigInt, x, tol=tol)
function distance_to_cone{T<:Rational}(κ::T, sqrt_matrix::Array{T,2}, Δ::GroupAlgebraElement{T})
function distance_to_cone{T<:Rational}(λ::T, sqrt_matrix::Array{T,2}, Δ::GroupAlgebraElement{T})
SOS = compute_SOS(sqrt_matrix, Δ)
SOS_diff = EOI(Δ, κ) - SOS
SOS_diff = EOI(Δ, λ) - SOS
eoi_SOS_L₁_dist = norm(SOS_diff,1)
info(logger, "κ = (≈$(@sprintf("%.10f", float(κ)))")
info(logger, "λ = (≈$(@sprintf("%.10f", float(λ)))")
ɛ_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)))")
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
end
function distance_to_cone{T<:Rational, S<:Interval}(κ::T, sqrt_matrix::Array{S,2}, Δ::GroupAlgebraElement{T})
function distance_to_cone{T<:Rational, S<:Interval}(λ::T, sqrt_matrix::Array{S,2}, Δ::GroupAlgebraElement{T})
SOS = compute_SOS(sqrt_matrix, Δ)
info(logger, "ɛ(∑ξᵢ*ξᵢ) ∈ $(GroupAlgebras.ɛ(SOS))")
κⁱⁿᵗ = @interval(κ)
λⁱⁿᵗ = @interval(λ)
Δⁱⁿᵗ = GroupAlgebraElement([@interval(c) for c in Δ.coefficients], Δ.product_matrix)
SOS_diff = EOI(Δⁱⁿᵗ, κⁱⁿᵗ) - SOS
SOS_diff = EOI(Δⁱⁿᵗ, λⁱⁿᵗ) - SOS
eoi_SOS_L₁_dist = norm(SOS_diff,1)
info(logger, "κ = (≈≥$(@sprintf("%.10f",float(κ))))")
info(logger, "λ = (≈≥$(@sprintf("%.10f",float(λ))))")
ɛ_dist = GroupAlgebras.ɛ(SOS_diff)
info(logger, "ɛ(Δ² - κΔ - ∑ξᵢ*ξᵢ) ∈ $(ɛ_dist)")
info(logger, "‖Δ² - κΔ - ∑ξᵢ*ξᵢ‖₁ ∈ $(eoi_SOS_L₁_dist)")
info(logger, "ɛ(Δ² - λΔ - ∑ξᵢ*ξᵢ) ∈ $(ɛ_dist)")
info(logger, "‖Δ² - λΔ - ∑ξᵢ*ξᵢ‖₁ ∈ $(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
end
function distance_to_cone{T<:AbstractFloat}(κ::T, sqrt_matrix::Array{T,2}, Δ::GroupAlgebraElement{T})
function distance_to_cone{T<:AbstractFloat}(λ::T, sqrt_matrix::Array{T,2}, Δ::GroupAlgebraElement{T})
SOS = compute_SOS(sqrt_matrix, Δ)
SOS_diff = EOI(Δ, κ) - SOS
SOS_diff = EOI(Δ, λ) - SOS
eoi_SOS_L₁_dist = norm(SOS_diff,1)
info(logger, "κ = ")
info(logger, "λ = ")
ɛ_dist = GroupAlgebras.ɛ(SOS_diff)
info(logger, "ɛ(Δ² - κΔ - ∑ξᵢ*ξᵢ) ≈ $(@sprintf("%.10f", ɛ_dist))")
info(logger, "‖Δ² - κΔ - ∑ξᵢ*ξᵢ‖₁ ≈ $(@sprintf("%.10f", eoi_SOS_L₁_dist))")
info(logger, "ɛ(Δ² - λΔ - ∑ξᵢ*ξᵢ) ≈ $(@sprintf("%.10f", ɛ_dist))")
info(logger, "‖Δ² - λΔ - ∑ξᵢ*ξᵢ‖₁ ≈ $(@sprintf("%.10f", 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
end
function check_distance_to_positive_cone(Δ::GroupAlgebraElement, κ, A;
function check_distance_to_positive_cone(Δ::GroupAlgebraElement, λ, P;
tol=1e-7, rational=false)
isapprox(eigvals(A), abs(eigvals(A)), atol=tol) ||
isapprox(eigvals(P), abs(eigvals(P)), atol=tol) ||
warn("The solution matrix doesn't seem to be positive definite!")
@assert A == Symmetric(A)
A_sqrt = real(sqrtm(A))
@assert P == Symmetric(P)
Q = real(sqrtm(P))
info(logger, "------------------------------------------------------------")
info(logger, "")
info(logger, "Checking in floating-point arithmetic...")
t = @timed fp_distance = distance_to_cone(κ, A_sqrt, Δ)
t = @timed fp_distance = distance_to_cone(λ, Q, Δ)
info(logger, timed_msg(t))
info(logger, "Floating point distance (to positive cone) ≈ $(@sprintf("%.10f", fp_distance))")
info(logger, "------------------------------------------------------------")
@ -133,17 +133,17 @@ function check_distance_to_positive_cone(Δ::GroupAlgebraElement, κ, A;
# return fpdistance
# end
info(logger, "Projecting columns of rationalized A_sqrt to the augmentation ideal...")
δ = eps(κ)
A_sqrt_ = (A_sqrt, δ)
t = @timed A_sqrt__aug = correct_to_augmentation_ideal(A_sqrt_)
info(logger, "Projecting columns of rationalized Q to the augmentation ideal...")
δ = eps(λ)
Q_ = (Q, δ)
t = @timed Q_ω = correct_to_augmentation_ideal(Q_)
info(logger, timed_msg(t))
κ_ = (κ, δ)
λ_ = (λ, δ)
Δ_ = (Δ, δ)
info(logger, "Checking in interval arithmetic")
A_sqrt__augⁱⁿᵗ = Float64.(A_sqrt__aug) ± δ
t = @timed Interval_dist_to_Σ² = distance_to_cone(κ_, A_sqrt__augⁱⁿᵗ, Δ_)
Q_ωⁱⁿᵗ = Float64.(Q_ω) ± δ
t = @timed Interval_dist_to_Σ² = distance_to_cone(λ_, Q_ωⁱⁿᵗ, Δ_)
info(logger, timed_msg(t))
info(logger, "The Augmentation-projected actual distance (to positive cone) ∈ $(Interval_dist_to_Σ²)")
info(logger, "------------------------------------------------------------")
@ -152,7 +152,7 @@ function check_distance_to_positive_cone(Δ::GroupAlgebraElement, κ, A;
return Interval_dist_to_Σ²
else
info(logger, "Checking Projected SOS decomposition in exact rational arithmetic...")
t = @timed _dist_to_Σ² = distance_to_cone(κ_, A_sqrt__aug, Δ_)
t = @timed _dist_to_Σ² = distance_to_cone(λ_, Q_ω, Δ_)
info(logger, timed_msg(t))
@assert isa(_dist_to_Σ², Rational)
info(logger, "Augmentation-projected rational distance (to positive cone) ≥ $(Float64(trunc(_dist_to_Σ²,8)))")

View File

@ -52,21 +52,21 @@ function create_SDP_problem(matrix_constraints, Δ::GroupAlgebraElement; upper_b
Δ² = Δ*Δ
@assert length(Δ) == length(matrix_constraints)
m = JuMP.Model();
JuMP.@variable(m, A[1:N, 1:N], SDP)
JuMP.@SDconstraint(m, A >= 0)
JuMP.@constraint(m, sum(A[i] for i in eachindex(A)) == 0)
JuMP.@variable(m, P[1:N, 1:N], SDP)
JuMP.@SDconstraint(m, P >= 0)
JuMP.@constraint(m, sum(P[i] for i in eachindex(P)) == 0)
if upper_bound < Inf
JuMP.@variable(m, 0.0 <= κ <= upper_bound)
JuMP.@variable(m, 0.0 <= λ <= upper_bound)
else
JuMP.@variable(m, κ >= 0)
JuMP.@variable(m, λ >= 0)
end
for (pairs, δ², δ) in zip(matrix_constraints, Δ².coefficients, Δ.coefficients)
JuMP.@constraint(m, sum(A[i,j] for (i,j) in pairs) == δ² - κ*δ)
JuMP.@constraint(m, sum(P[i,j] for (i,j) in pairs) == δ² - λ*δ)
end
JuMP.@objective(m, Max, κ)
JuMP.@objective(m, Max, λ)
return m
end
@ -95,7 +95,7 @@ function solve_SDP(SDP_problem, solver)
end
info(logger, solution_status)
κ = JuMP.getvalue(JuMP.getvariable(SDP_problem, :κ))
A = JuMP.getvalue(JuMP.getvariable(SDP_problem, :A))
return κ, A
λ = JuMP.getvalue(JuMP.getvariable(SDP_problem, :λ))
P = JuMP.getvalue(JuMP.getvariable(SDP_problem, :P))
return λ, P
end