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

adaptation to changes in GroupRings (not tested, not working)

This commit is contained in:
kalmar 2017-05-16 18:53:25 +02:00
parent e93ec0c422
commit 70b98ece5f
3 changed files with 21 additions and 24 deletions

View File

@ -42,7 +42,7 @@ function pmΔfilenames(name::String)
end
prefix = name
pm_filename = joinpath(prefix, "product_matrix.jld")
Δ_coeff_filename = joinpath(prefix, "delta.coefficients.jld")
Δ_coeff_filename = joinpath(prefix, "delta.coeffs.jld")
return pm_filename, Δ_coeff_filename
end
@ -64,7 +64,7 @@ function ΔandSDPconstraints(name::String)
info(logger, "Loading precomputed pm, Δ, sdp_constraints...")
product_matrix = load(pm_fname, "pm")
L = load(Δ_fname, "Δ")[:, 1]
Δ = GroupAlgebraElement(L, Array{Int,2}(product_matrix))
Δ = GroupRingElem(L, Array{Int,2}(product_matrix))
sdp_constraints = constraints_from_pm(product_matrix)
else
throw(ArgumentError("You need to precompute pm and Δ to load it!"))
@ -84,7 +84,7 @@ function ΔandSDPconstraints(name::String, generating_set::Function, radius::Int
info(logger, timed_msg(t))
save(pm_fname, "pm", Δ.product_matrix)
save(Δ_fname, "Δ", Δ.coefficients)
save(Δ_fname, "Δ", Δ.coeffs)
return Δ, sdp_constraints
else
error(logger, err)
@ -151,7 +151,7 @@ function λandP(name::String, opts...)
end
end
function compute_λandP(sdp_constraints, Δ::GroupAlgebraElement, solver::AbstractMathProgSolver, upper_bound=Inf)
function compute_λandP(sdp_constraints, Δ::GroupRingElem, solver::AbstractMathProgSolver, upper_bound=Inf)
t = @timed SDP_problem = create_SDP_problem(sdp_constraints, Δ; upper_bound=upper_bound)
info(logger, timed_msg(t))
@ -185,7 +185,7 @@ function check_property_T(name::String, generating_set::Function,
Δ, sdp_constraints = ΔandSDPconstraints(name, generating_set, radius)
S = countnz(Δ.coefficients) - 1
S = countnz(Δ.coeffs) - 1
info(logger, "|S| = $S")
info(logger, "length(Δ) = $(length(Δ))")
info(logger, "size(Δ.product_matrix) = $(size(Δ.product_matrix))")

View File

@ -6,23 +6,21 @@ ValidatedNumerics.setrounding(Interval, :correct)
ValidatedNumerics.setformat(:standard)
# setprecision(Interval, 53) # slightly faster than 256
function EOI{T<:Number}(Δ::GroupAlgebraElement{T}, λ::T)
function EOI{T<:Number}(Δ::GroupRingElem{T}, λ::T)
return Δ*Δ - λ*Δ
end
function algebra_square(vector, elt)
zzz = zeros(eltype(vector), elt.coefficients)
zzz[1:length(vector)] = vector
# new_base_elt = GroupAlgebraElement(zzz, elt.product_matrix)
# return (new_base_elt*new_base_elt).coefficients
return GroupAlgebras.algebra_multiplication(zzz, zzz, elt.product_matrix)
function algebra_square(vect, elt)
zzz = zeros(eltype(vect), elt.coeffs)
zzz[1:length(vect)] = vect
return GroupAlgebras.algebra_multiplication(zzz, zzz, parent(elt).pm)
end
function compute_SOS(sqrt_matrix, elt)
n = size(sqrt_matrix,2)
T = eltype(sqrt_matrix)
# result = zeros(T, length(elt.coefficients))
# result = zeros(T, length(elt.coeffs))
# for i in 1:n
# result += algebra_square(sqrt_matrix[:,i], elt)
# end
@ -30,8 +28,7 @@ function compute_SOS(sqrt_matrix, elt)
result = @parallel (+) for i in 1:n
PropertyT.algebra_square(sqrt_matrix[:,i], elt)
end
return GroupAlgebraElement(result, elt.product_matrix)
return GroupRingElem(result, parent(elt))
end
function correct_to_augmentation_ideal{T<:Rational}(sqrt_matrix::Array{T,2})
@ -52,7 +49,7 @@ function (±){T<:Number}(X::AbstractArray{T}, tol::Real)
return r.(X)
end
(±)(X::GroupAlgebraElement, tol::Real) = GroupAlgebraElement(X.coefficients ± tol, X.product_matrix)
(±)(X::GroupRingElem, tol::Real) = GroupRingElem(X.coeffs ± tol, parent(X))
function Base.rationalize{T<:Integer, S<:Real}(::Type{T},
X::AbstractArray{S}; tol::Real=eps(eltype(X)))
@ -62,7 +59,7 @@ 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}, Δ::GroupRingElem{T})
SOS = compute_SOS(sqrt_matrix, Δ)
SOS_diff = EOI(Δ, λ) - SOS
@ -80,11 +77,11 @@ function distance_to_cone{T<:Rational}(λ::T, sqrt_matrix::Array{T,2}, Δ::Group
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}, Δ::GroupRingElem{T})
SOS = compute_SOS(sqrt_matrix, Δ)
info(logger, "ɛ(∑ξᵢ*ξᵢ) ∈ $(GroupAlgebras.ɛ(SOS))")
λⁱⁿᵗ = @interval(λ)
Δⁱⁿᵗ = GroupAlgebraElement([@interval(c) for c in Δ.coefficients], Δ.product_matrix)
Δⁱⁿᵗ = GroupRingElem([@interval(c) for c in Δ.coeffs], parent(Δ).pm)
SOS_diff = EOI(Δⁱⁿᵗ, λⁱⁿᵗ) - SOS
eoi_SOS_L₁_dist = norm(SOS_diff,1)
@ -98,7 +95,7 @@ function distance_to_cone{T<:Rational, S<:Interval}(λ::T, sqrt_matrix::Array{S,
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}, Δ::GroupRingElem{T})
SOS = compute_SOS(sqrt_matrix, Δ)
SOS_diff = EOI(Δ, λ) - SOS
@ -113,7 +110,7 @@ function distance_to_cone{T<:AbstractFloat}(λ::T, sqrt_matrix::Array{T,2}, Δ::
return distance_to_cone
end
function check_distance_to_positive_cone(Δ::GroupAlgebraElement, λ, P;
function check_distance_to_positive_cone(Δ::GroupRingElem, λ, P;
tol=1e-7, rational=false)
isapprox(eigvals(P), abs(eigvals(P)), atol=tol) ||

View File

@ -53,8 +53,8 @@ function laplacian_coeff(S, basis)
end
function create_SDP_problem(matrix_constraints, Δ::GroupAlgebraElement; upper_bound=Inf)
N = size(Δ.product_matrix,1)
function create_SDP_problem(matrix_constraints, Δ::GroupRingElem; upper_bound=Inf)
N = size(parent(Δ).pm, 1)
Δ² = Δ*Δ
@assert length(Δ) == length(matrix_constraints)
m = JuMP.Model();
@ -68,7 +68,7 @@ function create_SDP_problem(matrix_constraints, Δ::GroupAlgebraElement; upper_b
JuMP.@variable(m, λ >= 0)
end
for (pairs, δ², δ) in zip(matrix_constraints, Δ².coefficients, Δ.coefficients)
for (pairs, δ², δ) in zip(matrix_constraints, Δ².coeffs, Δ.coeffs)
JuMP.@constraint(m, sum(P[i,j] for (i,j) in pairs) == δ² - λ*δ)
end