2017-06-25 09:28:44 +02:00
|
|
|
using IntervalArithmetic
|
|
|
|
|
2017-07-26 12:58:39 +02:00
|
|
|
IntervalArithmetic.setrounding(Interval, :tight)
|
2017-10-27 18:25:13 +02:00
|
|
|
IntervalArithmetic.setformat(sigfigs=12)
|
2017-06-25 09:28:44 +02:00
|
|
|
|
2018-08-14 19:18:36 +02:00
|
|
|
function groupring_square(pm, vect::AbstractVector)
|
2018-08-14 18:17:38 +02:00
|
|
|
zzz = zeros(eltype(vect), maximum(pm))
|
2017-11-03 16:54:41 +01:00
|
|
|
return GroupRings.mul!(zzz, vect, vect, pm)
|
2017-03-13 14:49:55 +01:00
|
|
|
end
|
|
|
|
|
2018-08-14 19:18:36 +02:00
|
|
|
function compute_SOS(pm::Array{I,2}, Q::AbstractArray) where I<:Integer
|
2017-03-14 16:40:35 +01:00
|
|
|
|
2018-08-14 18:17:38 +02:00
|
|
|
# result = zeros(eltype(Q), maximum(pm))
|
2018-01-01 14:06:33 +01:00
|
|
|
# r = similar(result)
|
|
|
|
# for i in 1:size(Q,2)
|
|
|
|
# print(" $i")
|
|
|
|
# result += GroupRings.mul!(r, view(Q,:,i), view(Q,:,i), pm)
|
|
|
|
# end
|
2017-08-27 18:30:49 +02:00
|
|
|
|
2018-01-01 14:06:33 +01:00
|
|
|
@everywhere groupring_square = PropertyT.groupring_square
|
2017-10-09 18:08:22 +02:00
|
|
|
|
2018-01-01 14:06:33 +01:00
|
|
|
result = @parallel (+) for i in 1:size(Q,2)
|
2018-08-14 19:18:36 +02:00
|
|
|
groupring_square(pm, Q[:,i])
|
2018-01-01 23:45:49 +01:00
|
|
|
end
|
2017-10-09 18:08:22 +02:00
|
|
|
|
2018-01-01 23:45:49 +01:00
|
|
|
return result
|
2017-03-13 14:49:55 +01:00
|
|
|
end
|
|
|
|
|
2018-08-14 19:18:36 +02:00
|
|
|
function compute_SOS(RG::GroupRing, Q::AbstractArray)
|
|
|
|
result = compute_SOS(RG.pm, Q)
|
2018-08-15 19:08:40 +02:00
|
|
|
return GroupRingElem(result, RG)
|
2017-10-27 18:30:59 +02:00
|
|
|
end
|
2017-03-15 17:51:13 +01:00
|
|
|
|
2018-08-14 18:18:25 +02:00
|
|
|
function augIdproj(Q::AbstractArray{T,2}) where {T<:Real}
|
2018-09-05 10:41:11 +02:00
|
|
|
result = zeros(Interval{T}, size(Q))
|
2018-01-01 14:06:33 +01:00
|
|
|
l = size(Q, 2)
|
|
|
|
Threads.@threads for j in 1:l
|
|
|
|
col = sum(view(Q, :,j))/l
|
2018-08-14 18:18:25 +02:00
|
|
|
for i in 1:size(Q, 1)
|
2018-09-05 10:41:11 +02:00
|
|
|
result[i,j] = @interval(Q[i,j] - col)
|
2018-01-01 14:06:33 +01:00
|
|
|
end
|
|
|
|
end
|
2018-09-05 10:41:11 +02:00
|
|
|
return result
|
2017-03-14 23:35:52 +01:00
|
|
|
end
|
2017-03-13 14:49:55 +01:00
|
|
|
|
2018-08-19 20:05:45 +02:00
|
|
|
function distance_to_cone(Δ::GroupRingElem, λ, Q; wlen::Int=4)
|
|
|
|
info("------------------------------------------------------------")
|
|
|
|
info("Checking in floating-point arithmetic...")
|
|
|
|
info("λ = $λ")
|
|
|
|
@time sos = compute_SOS(parent(Δ), Q)
|
2018-08-14 19:18:36 +02:00
|
|
|
residue = Δ^2-λ*Δ - sos
|
2018-08-19 20:05:45 +02:00
|
|
|
info("ɛ(Δ² - λΔ - ∑ξᵢ*ξᵢ) ≈ $(@sprintf("%.10f", aug(residue)))")
|
2018-08-14 19:18:36 +02:00
|
|
|
L1_norm = norm(residue,1)
|
2018-08-19 20:05:45 +02:00
|
|
|
info("‖Δ² - λΔ - ∑ξᵢ*ξᵢ‖₁ ≈ $(@sprintf("%.10f", L1_norm))")
|
2018-01-01 23:49:27 +01:00
|
|
|
|
2018-08-14 19:18:36 +02:00
|
|
|
distance = λ - 2^(wlen-1)*L1_norm
|
2018-01-01 23:49:27 +01:00
|
|
|
|
2018-08-19 20:05:45 +02:00
|
|
|
info("Floating point distance (to positive cone) ≈")
|
|
|
|
info("$(@sprintf("%.10f", distance))")
|
|
|
|
info("")
|
2018-01-01 23:49:27 +01:00
|
|
|
|
2018-08-14 19:18:36 +02:00
|
|
|
if distance ≤ 0
|
|
|
|
return distance
|
2017-04-17 15:22:33 +02:00
|
|
|
end
|
2017-03-31 22:38:18 +02:00
|
|
|
|
2018-08-19 20:05:45 +02:00
|
|
|
info("------------------------------------------------------------")
|
|
|
|
info("Checking in interval arithmetic...")
|
|
|
|
info("λ ∈ $λ")
|
|
|
|
|
2017-10-27 18:34:07 +02:00
|
|
|
λ = @interval(λ)
|
2018-08-14 19:18:36 +02:00
|
|
|
eoi = Δ^2 - λ*Δ
|
2018-08-19 20:05:45 +02:00
|
|
|
info("Projecting columns of Q to the augmentation ideal...")
|
|
|
|
T = eltype(Q)
|
|
|
|
@time Q = augIdproj(Q)
|
|
|
|
|
|
|
|
info("Checking that sum of every column contains 0.0... ")
|
|
|
|
check = all([zero(T) in sum(view(Q, :, i)) for i in 1:size(Q, 2)])
|
|
|
|
info((check? "They do." : "FAILED!"))
|
|
|
|
|
|
|
|
@assert check
|
2017-08-04 20:36:25 +02:00
|
|
|
|
2018-08-19 20:05:45 +02:00
|
|
|
@time sos = compute_SOS(parent(Δ), Q)
|
2018-08-14 19:18:36 +02:00
|
|
|
residue = Δ^2-λ*Δ - sos
|
2018-08-19 20:05:45 +02:00
|
|
|
info("ɛ(∑ξᵢ*ξᵢ) ∈ $(aug(residue))")
|
2018-08-15 19:09:01 +02:00
|
|
|
L1_norm = norm(residue,1)
|
2018-08-19 20:05:45 +02:00
|
|
|
info("‖Δ² - λΔ - ∑ξᵢ*ξᵢ‖₁ ∈ $(L1_norm)")
|
2018-08-14 19:18:36 +02:00
|
|
|
|
|
|
|
distance = λ - 2^(wlen-1)*L1_norm
|
2018-08-19 20:05:45 +02:00
|
|
|
info("The Augmentation-projected distance (to positive cone) ∈")
|
|
|
|
info("$(distance)")
|
|
|
|
info("")
|
2017-03-13 14:49:55 +01:00
|
|
|
|
2018-08-14 19:18:36 +02:00
|
|
|
return distance.lo
|
2017-03-13 14:49:55 +01:00
|
|
|
end
|