2019-01-11 06:32:09 +01:00
|
|
|
using Printf
|
|
|
|
|
2019-01-08 04:59:23 +01:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Settings and filenames
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
abstract type Settings end
|
2019-01-08 04:59:23 +01:00
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
struct Naive{El} <: Settings
|
2019-01-08 04:59:23 +01:00
|
|
|
name::String
|
|
|
|
G::Group
|
2019-01-11 04:33:56 +01:00
|
|
|
S::Vector{El}
|
2019-01-08 04:59:23 +01:00
|
|
|
radius::Int
|
2019-01-11 04:33:56 +01:00
|
|
|
upper_bound::Float64
|
2019-01-08 04:59:23 +01:00
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
solver::AbstractMathProgSolver
|
|
|
|
warmstart::Bool
|
2019-01-08 04:59:23 +01:00
|
|
|
end
|
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
struct Symmetrized{El} <: Settings
|
2019-01-08 04:59:23 +01:00
|
|
|
name::String
|
|
|
|
G::Group
|
2019-01-11 04:33:56 +01:00
|
|
|
S::Vector{El}
|
2019-01-08 04:59:23 +01:00
|
|
|
autS::Group
|
|
|
|
radius::Int
|
2019-01-11 04:33:56 +01:00
|
|
|
upper_bound::Float64
|
|
|
|
|
|
|
|
solver::AbstractMathProgSolver
|
|
|
|
warmstart::Bool
|
2019-01-08 04:59:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Settings(name::String,
|
2019-01-14 17:44:13 +01:00
|
|
|
G::Group, S::Vector{<:GroupElem},solver::Solver;
|
|
|
|
radius::Integer=2, upper_bound::Float64=1.0, warmstart=true) where {Solver<:AbstractMathProgSolver}
|
2019-01-11 04:33:56 +01:00
|
|
|
return Naive(name, G, S, radius, upper_bound, solver, warmstart)
|
2019-01-08 04:59:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Settings(name::String,
|
2019-01-14 17:44:13 +01:00
|
|
|
G::Group, S::Vector{<:GroupElem}, autS::Group, solver::Solver;
|
|
|
|
radius::Integer=2, upper_bound::Float64=1.0, warmstart=true) where {Solver<:AbstractMathProgSolver}
|
2019-01-11 04:33:56 +01:00
|
|
|
return Symmetrized(name, G, S, autS, radius, upper_bound, solver, warmstart)
|
2019-01-08 04:59:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
prefix(s::Naive) = s.name
|
|
|
|
prefix(s::Symmetrized) = "o"*s.name
|
2019-01-11 04:33:56 +01:00
|
|
|
suffix(s::Settings) = "$(s.upper_bound)"
|
|
|
|
prepath(s::Settings) = prefix(s)
|
|
|
|
fullpath(s::Settings) = joinpath(prefix(s), suffix(s))
|
2019-01-08 04:59:23 +01:00
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
filename(sett::Settings, s::Symbol) = filename(sett, Val{s})
|
2019-01-08 04:59:23 +01:00
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
filename(sett::Settings, ::Type{Val{:fulllog}}) =
|
2019-01-08 04:59:23 +01:00
|
|
|
joinpath(fullpath(sett), "full_$(string(now())).log")
|
2019-01-11 04:33:56 +01:00
|
|
|
filename(sett::Settings, ::Type{Val{:solverlog}}) =
|
2019-01-08 04:59:23 +01:00
|
|
|
joinpath(fullpath(sett), "solver_$(string(now())).log")
|
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
filename(sett::Settings, ::Type{Val{:Δ}}) =
|
2019-01-08 04:59:23 +01:00
|
|
|
joinpath(prepath(sett), "delta.jld")
|
2019-01-11 04:33:56 +01:00
|
|
|
filename(sett::Settings, ::Type{Val{:OrbitData}}) =
|
2019-01-08 04:59:23 +01:00
|
|
|
joinpath(prepath(sett), "OrbitData.jld")
|
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
filename(sett::Settings, ::Type{Val{:warmstart}}) =
|
2019-01-08 04:59:23 +01:00
|
|
|
joinpath(fullpath(sett), "warmstart.jld")
|
2019-01-11 04:33:56 +01:00
|
|
|
filename(sett::Settings, ::Type{Val{:solution}}) =
|
2019-01-08 04:59:23 +01:00
|
|
|
joinpath(fullpath(sett), "solution.jld")
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# λandP
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
function warmstart(sett::Settings)
|
|
|
|
if sett.warmstart && isfile(filename(sett, :warmstart))
|
2019-01-08 04:59:23 +01:00
|
|
|
ws = load(filename(sett, :warmstart), "warmstart")
|
|
|
|
else
|
|
|
|
ws = nothing
|
|
|
|
end
|
|
|
|
return ws
|
|
|
|
end
|
|
|
|
|
|
|
|
function computeλandP(sett::Naive, Δ::GroupRingElem;
|
|
|
|
solverlog=tempname()*".log")
|
|
|
|
|
2019-01-11 06:32:09 +01:00
|
|
|
@info("Creating SDP problem...")
|
2019-01-11 04:33:56 +01:00
|
|
|
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, upper_bound=sett.upper_bound)
|
|
|
|
JuMP.setsolver(SDP_problem, sett.solver)
|
2019-01-11 06:32:09 +01:00
|
|
|
@info(Base.repr(SDP_problem))
|
2019-01-08 04:59:23 +01:00
|
|
|
|
|
|
|
ws = warmstart(sett)
|
|
|
|
@time status, (λ, P, ws) = PropertyT.solve(solverlog, SDP_problem, varλ, varP, ws)
|
2019-01-11 06:32:09 +01:00
|
|
|
@info("Solver's status: $status")
|
|
|
|
|
2019-01-08 04:59:23 +01:00
|
|
|
save(filename(sett, :warmstart), "warmstart", ws, "P", P, "λ", λ)
|
|
|
|
|
|
|
|
return λ, P
|
|
|
|
end
|
|
|
|
|
|
|
|
function computeλandP(sett::Symmetrized, Δ::GroupRingElem;
|
|
|
|
solverlog=tempname()*".log")
|
|
|
|
|
|
|
|
if !isfile(filename(sett, :OrbitData))
|
|
|
|
isdefined(parent(Δ), :basis) || throw("You need to define basis of Group Ring to compute orbit decomposition!")
|
|
|
|
orbit_data = OrbitData(parent(Δ), sett.autS)
|
|
|
|
save(filename(sett, :OrbitData), "OrbitData", orbit_data)
|
|
|
|
end
|
|
|
|
orbit_data = load(filename(sett, :OrbitData), "OrbitData")
|
|
|
|
orbit_data = decimate(orbit_data)
|
|
|
|
|
2019-01-11 06:32:09 +01:00
|
|
|
@info("Creating SDP problem...")
|
2019-01-08 04:59:23 +01:00
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, orbit_data, upper_bound=sett.upper_bound)
|
|
|
|
JuMP.setsolver(SDP_problem, sett.solver)
|
2019-01-11 06:32:09 +01:00
|
|
|
@info(Base.repr(SDP_problem))
|
2019-01-08 04:59:23 +01:00
|
|
|
|
|
|
|
ws = warmstart(sett)
|
|
|
|
@time status, (λ, Ps, ws) = PropertyT.solve(solverlog, SDP_problem, varλ, varP, ws)
|
2019-01-11 06:32:09 +01:00
|
|
|
@info("Solver's status: $status")
|
|
|
|
|
2019-01-08 04:59:23 +01:00
|
|
|
save(filename(sett, :warmstart), "warmstart", ws, "Ps", Ps, "λ", λ)
|
2019-01-28 17:03:24 +01:00
|
|
|
@info("Reconstructing P...")
|
2019-01-08 04:59:23 +01:00
|
|
|
@time P = reconstruct(Ps, orbit_data)
|
|
|
|
|
|
|
|
return λ, P
|
|
|
|
end
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Checking solution
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
function distance_to_positive_cone(Δ::GroupRingElem, λ, Q; R::Int=2)
|
|
|
|
@info("------------------------------------------------------------")
|
|
|
|
@info("Checking in floating-point arithmetic...")
|
|
|
|
@info("λ = $λ")
|
|
|
|
eoi = Δ^2-λ*Δ
|
|
|
|
|
2019-01-14 17:46:13 +01:00
|
|
|
@info("Computing sum of squares decomposition...")
|
2019-01-08 04:59:23 +01:00
|
|
|
@time residual = eoi - compute_SOS(parent(eoi), augIdproj(Q))
|
|
|
|
@info("ɛ(Δ² - λΔ - ∑ξᵢ*ξᵢ) ≈ $(@sprintf("%.10f", aug(residual)))")
|
|
|
|
L1_norm = norm(residual,1)
|
|
|
|
@info("‖Δ² - λΔ - ∑ξᵢ*ξᵢ‖₁ ≈ $(@sprintf("%.10f", L1_norm))")
|
|
|
|
|
|
|
|
distance = λ - 2.0^(2ceil(log2(R)))*L1_norm
|
|
|
|
|
|
|
|
@info("Floating point distance (to positive cone) ≈")
|
|
|
|
@info("$(@sprintf("%.10f", distance))")
|
|
|
|
|
|
|
|
if distance ≤ 0
|
|
|
|
return distance
|
|
|
|
end
|
|
|
|
|
2019-01-28 17:03:24 +01:00
|
|
|
@info("-"^76)
|
2019-01-08 04:59:23 +01:00
|
|
|
@info("Checking in interval arithmetic...")
|
|
|
|
λ = @interval(λ)
|
2019-01-11 06:32:09 +01:00
|
|
|
@info("λ ∈ $λ")
|
2019-01-08 04:59:23 +01:00
|
|
|
eoi = Δ^2 - λ*Δ
|
|
|
|
|
|
|
|
@info("Projecting columns of Q to the augmentation ideal...")
|
|
|
|
@time Q, check = augIdproj(Interval, Q)
|
|
|
|
@info("Checking that sum of every column contains 0.0... ")
|
2019-01-11 06:32:09 +01:00
|
|
|
@info((check ? "They do." : "FAILED!"))
|
2019-01-08 04:59:23 +01:00
|
|
|
check || @warn("The following numbers are meaningless!")
|
2019-01-14 17:46:13 +01:00
|
|
|
|
|
|
|
@info("Computing sum of squares decomposition...")
|
2019-01-08 04:59:23 +01:00
|
|
|
@time residual = eoi - compute_SOS(parent(eoi), Q)
|
|
|
|
@info("ɛ(Δ² - λΔ - ∑ξᵢ*ξᵢ) ∈ $(aug(residual))")
|
|
|
|
L1_norm = norm(residual,1)
|
|
|
|
@info("‖Δ² - λΔ - ∑ξᵢ*ξᵢ‖₁ ∈ $(L1_norm)")
|
|
|
|
|
|
|
|
distance = λ - 2.0^(2ceil(log2(R)))*L1_norm
|
|
|
|
|
|
|
|
@info("Interval distance (to positive cone) ∈")
|
|
|
|
@info("$(distance)")
|
2019-01-28 17:03:24 +01:00
|
|
|
@info("-"^76)
|
2019-01-08 04:59:23 +01:00
|
|
|
|
|
|
|
return distance.lo
|
|
|
|
end
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Interpreting the numerical results
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
Kazhdan(λ::Number, N::Integer) = sqrt(2*λ/N)
|
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
function interpret_results(sett::Settings, sgap::Number)
|
2019-01-08 04:59:23 +01:00
|
|
|
|
|
|
|
if sgap > 0
|
|
|
|
Kazhdan_κ = Kazhdan(sgap, length(sett.S))
|
|
|
|
if Kazhdan_κ > 0
|
2019-01-11 06:32:09 +01:00
|
|
|
@info("κ($(sett.name), S) ≥ $Kazhdan_κ: Group HAS property (T)!")
|
2019-01-08 04:59:23 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2019-01-11 06:32:09 +01:00
|
|
|
@info("λ($(sett.name), S) ≥ $sgap < 0: Tells us nothing about property (T)")
|
2019-01-08 04:59:23 +01:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
function check_property_T(sett::Settings)
|
2019-01-08 04:59:23 +01:00
|
|
|
fp = PropertyT.fullpath(sett)
|
|
|
|
isdir(fp) || mkpath(fp)
|
2019-01-28 17:03:24 +01:00
|
|
|
@info("="^76)
|
|
|
|
@info("Running tests for $(sett.name):")
|
2019-01-28 08:42:40 +01:00
|
|
|
@info("Upper bound for λ: $(sett.upper_bound), on radius $(sett.radius).")
|
|
|
|
@info("Solver is $(sett.solver)")
|
|
|
|
@info("Warmstart: $(sett.warmstart)")
|
2019-01-28 17:03:24 +01:00
|
|
|
@info("="^76)
|
2019-01-08 04:59:23 +01:00
|
|
|
|
|
|
|
if isfile(filename(sett,:Δ))
|
|
|
|
# cached
|
2019-01-11 06:33:14 +01:00
|
|
|
@info("Loading precomputed Δ...")
|
|
|
|
Δ = loadGRElem(filename(sett,:Δ), sett.G)
|
2019-01-08 04:59:23 +01:00
|
|
|
else
|
|
|
|
# compute
|
|
|
|
Δ = Laplacian(sett.S, sett.radius)
|
2019-01-11 06:33:14 +01:00
|
|
|
saveGRElem(filename(sett, :Δ), Δ)
|
2019-01-08 04:59:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if !sett.warmstart && isfile(filename(sett, :solution))
|
|
|
|
λ, P = load(filename(sett, :solution), "λ", "P")
|
|
|
|
else
|
|
|
|
λ, P = computeλandP(sett, Δ,
|
|
|
|
solverlog=filename(sett, :solverlog))
|
|
|
|
|
|
|
|
save(filename(sett, :solution), "λ", λ, "P", P)
|
|
|
|
|
|
|
|
if λ < 0
|
2019-01-11 06:32:09 +01:00
|
|
|
@warn("Solver did not produce a valid solution!")
|
2019-01-08 04:59:23 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-11 06:32:09 +01:00
|
|
|
@info("λ = $λ")
|
|
|
|
@info("sum(P) = $(sum(P))")
|
|
|
|
@info("maximum(P) = $(maximum(P))")
|
|
|
|
@info("minimum(P) = $(minimum(P))")
|
2019-01-08 04:59:23 +01:00
|
|
|
|
2019-01-11 04:33:56 +01:00
|
|
|
isapprox(eigvals(P), abs.(eigvals(P))) ||
|
|
|
|
@warn("The solution matrix doesn't seem to be positive definite!")
|
2019-01-08 04:59:23 +01:00
|
|
|
|
2019-01-11 06:32:09 +01:00
|
|
|
@time Q = real(sqrt( (P.+ P')./2 ))
|
2019-01-14 17:45:23 +01:00
|
|
|
sgap = distance_to_positive_cone(Δ, λ, Q, R=sett.radius)
|
2019-01-08 04:59:23 +01:00
|
|
|
|
|
|
|
return interpret_results(sett, sgap)
|
|
|
|
end
|