1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-11-23 00:10:28 +01:00

single definition o check_property_T

This commit is contained in:
kalmarek 2018-09-05 09:06:00 +02:00
parent 19e52909ac
commit d73f041c3c
2 changed files with 50 additions and 78 deletions

View File

@ -149,54 +149,15 @@ function save_preps(fname::String, preps)
save(fname, "perms_d", [preps[elt].d for elt in elements(autS)]) save(fname, "perms_d", [preps[elt].d for elt in elements(autS)])
end end
function check_property_T(sett::Settings)
ex(s::Symbol) = exists(filename(prepath(sett), s))
if ex(:pm) && ex()
# 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 end
files_exist = ex.([:Uπs, :orbits, :preps])
if !all(files_exist)
compute_orbit_data(prepath(sett), parent(Δ), sett.autS)
end 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(Δ, sett, ws,
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!")
return interpret_results(sett.name, Δ, sett.radius, length(sett.S), λ, P)
end end

View File

@ -18,6 +18,8 @@ import MathProgBase.SolverInterface.AbstractMathProgSolver
# #
############################################################################### ###############################################################################
struct Symmetrize end
struct Naive end
mutable struct Settings{Gr<:Group, GEl<:GroupElem, Sol<:AbstractMathProgSolver} mutable struct Settings{Gr<:Group, GEl<:GroupElem, Sol<:AbstractMathProgSolver}
name::String name::String
@ -78,16 +80,6 @@ exists(fname::String) = isfile(fname) || islink(fname)
Kazhdan(λ::Number,N::Integer) = sqrt(2*λ/N) Kazhdan(λ::Number,N::Integer) = sqrt(2*λ/N)
function check_property_T(name::String, S, solver, upper_bound, tol, radius, warm::Bool=false)
if exists(filename(name, :pm)) && exists(filename(name, ))
# cached
Δ = loadLaplacian(name, parent(S[1]))
else
# compute
Δ = computeLaplacian(S, radius)
save(filename(name, :pm), "pm", parent(Δ).pm)
save(filename(name, ), "Δ", Δ.coeffs)
filename(prefix, s::Symbol) = filename(prefix, Val{s}) filename(prefix, s::Symbol) = filename(prefix, Val{s})
@eval begin @eval begin
@ -108,24 +100,38 @@ filename(prefix, s::Symbol) = filename(prefix, Val{s})
end end
end end
fullpath = joinpath(name, string(upper_bound)) for T in [:Naive, :Symmetrize]
isdir(fullpath) || mkdir(fullpath) @eval begin
function check_property_T(::Type{$T}, sett::Settings)
files_exist = exists(filename(fullpath, )) && exists(filename(fullpath, :P)) if exists(filename(prepath(sett),:pm)) &&
exists(filename(prepath(sett),))
if !(warm) && files_exist # cached
λ, P = loadλandP(fullpath) Δ = loadLaplacian(prepath(sett), parent(sett.S[1]))
else else
warmfile = filename(fullpath, :warm) # compute
if warm && isfile(warmfile) Δ = 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") ws = load(warmfile, "warmstart")
else else
ws = nothing ws = nothing
end end
λ, P, ws = computeλandP(Δ, upper_bound, solver, ws, λ, P, ws = computeλandP($T, Δ, sett,
solverlog=filename(fullpath, :solverlog)) solverlog=filename(fullpath(sett), :solverlog))
saveλandP(fullpath, λ, P, ws) saveλandP(fullpath(sett), λ, P, ws)
if λ < 0 if λ < 0
warn("Solver did not produce a valid solution!") warn("Solver did not produce a valid solution!")
end end
@ -136,10 +142,15 @@ end
info("maximum(P) = $(maximum(P))") info("maximum(P) = $(maximum(P))")
info("minimum(P) = $(minimum(P))") info("minimum(P) = $(minimum(P))")
isapprox(eigvals(P), abs.(eigvals(P)), atol=tol) || isapprox(eigvals(P), abs.(eigvals(P)), atol=sett.tol) ||
warn("The solution matrix doesn't seem to be positive definite!") warn("The solution matrix doesn't seem to be positive definite!")
return interpret_results(name, Δ, radius,length(S), λ, P) @time Q = real(sqrtm((P+P')/2))
sgap = distance_to_cone(Δ, λ, Q, wlen=2*sett.radius)
return interpret_results(sett, sgap)
end
end
end end
function interpret_results(name::String, Δ::GroupRingElem, radius::Integer, length_S::Integer, λ::AbstractFloat, P) function interpret_results(name::String, Δ::GroupRingElem, radius::Integer, length_S::Integer, λ::AbstractFloat, P)