PropertyT.jl/src/PropertyT.jl

152 lines
4.2 KiB
Julia
Raw Normal View History

2018-08-19 20:05:45 +02:00
__precompile__()
2017-03-13 15:56:07 +01:00
module PropertyT
2017-03-13 14:49:55 +01:00
2018-07-31 10:21:54 +02:00
using AbstractAlgebra
2017-06-22 15:15:43 +02:00
using Groups
2017-05-28 20:03:57 +02:00
using GroupRings
2017-03-15 17:48:52 +01:00
2018-07-31 10:21:54 +02:00
import AbstractAlgebra: Group, GroupElem, Ring, perm
2017-06-22 15:15:43 +02:00
using JLD
using JuMP
2018-09-05 08:55:13 +02:00
import MathProgBase.SolverInterface.AbstractMathProgSolver
2018-01-02 02:55:53 +01:00
2018-09-05 08:55:13 +02:00
###############################################################################
#
# Settings and filenames
#
###############################################################################
2017-03-13 14:49:55 +01:00
2018-09-05 09:06:00 +02:00
struct Symmetrize end
struct Naive end
2018-09-05 08:55:13 +02:00
mutable struct Settings{Gr<:Group, GEl<:GroupElem, Sol<:AbstractMathProgSolver}
name::String
G::Gr
S::Vector{GEl}
radius::Int
2017-03-13 14:49:55 +01:00
2018-09-05 08:55:13 +02:00
solver::Sol
upper_bound::Float64
tol::Float64
warmstart::Bool
2018-09-05 08:55:13 +02:00
autS::Group
2018-09-05 08:55:13 +02:00
function Settings(name, G::Gr, S::Vector{GEl}, r::Int,
sol::Sol, ub, tol, ws) where {Gr, GEl, Sol}
return new{Gr, GEl, Sol}(name, G, S, r, sol, ub, tol, ws)
end
2017-04-01 15:21:57 +02:00
2018-09-05 08:55:13 +02:00
function Settings(name, G::Gr, S::Vector{GEl}, r::Int,
sol::Sol, ub, tol, ws, autS) where {Gr, GEl, Sol}
return new{Gr, GEl, Sol}(name, G, S, r, sol, ub, tol, ws, autS)
2017-03-13 14:49:55 +01:00
end
end
2018-09-05 08:55:13 +02:00
prefix(s::Settings) = s.name
suffix(s::Settings) = "$(s.upper_bound)"
prepath(s::Settings) = prefix(s)
fullpath(s::Settings) = joinpath(prefix(s), suffix(s))
2018-09-05 08:55:13 +02:00
exists(fname::String) = isfile(fname) || islink(fname)
2017-03-16 09:35:32 +01:00
2018-09-05 08:56:55 +02:00
filename(prefix, s::Symbol) = filename(prefix, Val{s})
@eval begin
for (s,n) in [
[:fulllog, "full_$(string(now())).log"],
[:solverlog, "solver_$(string(now())).log"],
[:pm, "pm.jld"],
[, "delta.jld"],
[, "lambda.jld"],
[:P, "SDPmatrix.jld"],
[:warm, "warmstart.jld"],
[:Uπs, "U_pis.jld"],
[:orbits, "orbits.jld"],
[:preps, "preps.jld"],
]
filename(prefix::String, ::Type{Val{$:(s)}}) = joinpath(prefix, :($n))
2017-06-05 13:23:10 +02:00
end
2018-09-05 08:56:55 +02:00
end
2018-09-05 09:06:00 +02:00
for T in [:Naive, :Symmetrize]
@eval begin
function check_property_T(::Type{$T}, sett::Settings)
if exists(filename(prepath(sett),:pm)) &&
exists(filename(prepath(sett),))
# cached
Δ = loadLaplacian(prepath(sett), parent(sett.S[1]))
else
# compute
Δ = computeLaplacian(sett.S, sett.radius)
save(filename(prepath(sett), :pm), "pm", parent(Δ).pm)
save(filename(prepath(sett), ), "Δ", Δ.coeffs)
end
files_exist = exists(filename(fullpath(sett), )) &&
exists(filename(fullpath(sett), :P))
if !sett.warmstart && files_exist
λ, P = loadλandP(fullpath(sett))
else
warmfile = filename(fullpath(sett), :warm)
if sett.warmstart && exists(warmfile)
ws = load(warmfile, "warmstart")
else
ws = nothing
end
λ, P, ws = computeλandP($T, Δ, sett,
solverlog=filename(fullpath(sett), :solverlog))
saveλandP(fullpath(sett), λ, P, ws)
if λ < 0
warn("Solver did not produce a valid solution!")
end
end
info("λ = ")
info("sum(P) = $(sum(P))")
info("maximum(P) = $(maximum(P))")
info("minimum(P) = $(minimum(P))")
isapprox(eigvals(P), abs.(eigvals(P)), atol=sett.tol) ||
warn("The solution matrix doesn't seem to be positive definite!")
@time Q = real(sqrtm((P+P')/2))
sgap = distance_to_cone(Δ, λ, Q, wlen=2*sett.radius)
return interpret_results(sett, sgap)
2018-08-19 20:05:45 +02:00
end
2018-01-01 14:06:33 +01:00
end
end
2018-09-05 09:07:05 +02:00
Kazhdan(λ::Number, N::Integer) = sqrt(2*λ/N)
2018-09-05 09:07:05 +02:00
function interpret_results(sett::Settings, sgap::Number)
if sgap > 0
2018-09-05 09:07:05 +02:00
Kazhdan_κ = Kazhdan(sgap, length(sett.S))
if Kazhdan_κ > 0
2018-09-05 09:07:05 +02:00
info("κ($(sett.name), S) ≥ $Kazhdan_κ: Group HAS property (T)!")
return true
end
2018-01-01 14:06:33 +01:00
end
2018-09-05 09:07:05 +02:00
info("λ($(sett.name), S) ≥ $sgap < 0: Tells us nothing about property (T)")
2018-01-01 14:06:33 +01:00
return false
2017-03-13 14:49:55 +01:00
end
2018-09-05 08:58:46 +02:00
include("Laplacians.jl")
2018-09-05 10:35:58 +02:00
include("Orbit-wise.jl")
include("OrbitDecomposition.jl")
2017-06-22 15:15:55 +02:00
include("SDPs.jl")
include("CheckSolution.jl")
2018-09-05 10:35:58 +02:00
2017-06-22 15:15:55 +02:00
2017-03-13 14:49:55 +01:00
end # module Property(T)