mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-12-25 02:15:29 +01:00
Parallel compute_SOS
This commit is contained in:
parent
2508dba1e4
commit
b80e32f3a8
38
SL(3,Z).jl
38
SL(3,Z).jl
@ -2,11 +2,11 @@ using JuMP
|
|||||||
import SCS: SCSSolver
|
import SCS: SCSSolver
|
||||||
import Mosek: MosekSolver
|
import Mosek: MosekSolver
|
||||||
|
|
||||||
push!(LOAD_PATH, "./")
|
workers_processes = addprocs()
|
||||||
|
|
||||||
|
@everywhere push!(LOAD_PATH, "./")
|
||||||
using GroupAlgebras
|
using GroupAlgebras
|
||||||
include("property(T).jl")
|
@everywhere include("property(T).jl")
|
||||||
|
|
||||||
|
|
||||||
function E(i::Int, j::Int, N::Int=3)
|
function E(i::Int, j::Int, N::Int=3)
|
||||||
@assert i≠j
|
@assert i≠j
|
||||||
@ -39,33 +39,41 @@ const TOL=10.0^-7
|
|||||||
# κ, A = solve_for_property_T(S₁, solver, verbose=VERBOSE)
|
# κ, A = solve_for_property_T(S₁, solver, verbose=VERBOSE)
|
||||||
|
|
||||||
|
|
||||||
product_matrix = readdlm("SL3Z.product_matrix", Int)
|
const product_matrix = readdlm("SL3Z.product_matrix", Int)
|
||||||
L = readdlm("SL3Z.delta.coefficients")[:, 1]
|
const L = readdlm("SL3Z.delta.coefficients")[:, 1]
|
||||||
Δ = GroupAlgebraElement(L, product_matrix)
|
const Δ = GroupAlgebraElement(L, product_matrix)
|
||||||
|
|
||||||
A = readdlm("SL3Z.SDPmatrixA.Mosek")
|
const A = readdlm("SL3Z.SDPmatrixA.Mosek")
|
||||||
κ = readdlm("SL3Z.kappa.Mosek")[1]
|
const κ = readdlm("SL3Z.kappa.Mosek")[1]
|
||||||
|
|
||||||
@assert isapprox(eigvals(A), abs(eigvals(A)), atol=TOL)
|
@assert isapprox(eigvals(A), abs(eigvals(A)), atol=TOL)
|
||||||
@assert A == Symmetric(A)
|
@assert A == Symmetric(A)
|
||||||
|
|
||||||
const A_sqrt = real(sqrtm(A))
|
const A_sqrt = real(sqrtm(A))
|
||||||
|
|
||||||
SOS_fp_diff, SOS_fp_L₁_distance = check_solution(κ, A_sqrt, Δ)
|
const SOS_fp_diff, SOS_fp_L₁_distance = check_solution(κ, A_sqrt, Δ)
|
||||||
|
|
||||||
@show SOS_fp_L₁_distance
|
@show SOS_fp_L₁_distance
|
||||||
@show GroupAlgebras.ɛ(SOS_fp_diff)
|
@show GroupAlgebras.ɛ(SOS_fp_diff)
|
||||||
|
|
||||||
κ_rational = rationalize(BigInt, κ;)
|
const κ_rational = rationalize(BigInt, κ, tol=TOL)
|
||||||
A_sqrt_rational = rationalize(BigInt, A_sqrt)
|
const A_sqrt_rational = rationalize(BigInt, A_sqrt, tol=TOL)
|
||||||
Δ_rational = rationalize(BigInt, Δ)
|
const Δ_rational = rationalize(BigInt, Δ, tol=TOL)
|
||||||
|
|
||||||
SOS_rational_diff, SOS_rat_L₁_distance = check_solution(κ_rational, A_sqrt_rational, Δ_rational)
|
const SOS_rational_diff, SOS_rat_L₁_distance = check_solution(κ_rational, A_sqrt_rational, Δ_rational)
|
||||||
|
|
||||||
@assert isa(SOS_rat_L₁_distance, Rational{BigInt})
|
@assert isa(SOS_rat_L₁_distance, Rational{BigInt})
|
||||||
@show float(SOS_rat_L₁_distance)
|
@show float(SOS_rat_L₁_distance)
|
||||||
@show float(GroupAlgebras.ɛ(SOS_rational_diff))
|
@show float(GroupAlgebras.ɛ(SOS_rational_diff))
|
||||||
|
|
||||||
A_sqrt_augmented = correct_to_augmentation_ideal(A_sqrt_rational)
|
const A_sqrt_augmented = correct_to_augmentation_ideal(A_sqrt_rational)
|
||||||
|
|
||||||
SOS_rational_diff_aug, SOS_rat_L₁_distance_aug = check_solution(κ_rational, A_sqrt_augmented, Δ_rational)
|
const SOS_rational_aug_diff, SOS_aug_rat_L₁_distance = check_solution(κ_rational, A_sqrt_augmented, Δ_rational)
|
||||||
|
|
||||||
|
@assert isa(SOS_aug_rat_L₁_distance, Rational{BigInt})
|
||||||
|
@assert GroupAlgebras.ɛ(SOS_rational_aug_diff) == 0//1
|
||||||
|
|
||||||
|
@show float(SOS_aug_rat_L₁_distance)
|
||||||
|
@show float(κ_rational - 2^3*SOS_aug_rat_L₁_distance)
|
||||||
|
|
||||||
|
rmprocs(workers_processes)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using JuMP
|
using JuMP
|
||||||
import Base: rationalize
|
import Base: rationalize
|
||||||
|
using GroupAlgebras
|
||||||
|
|
||||||
function products{T<:Real}(S1::Array{Array{T,2},1}, S2::Array{Array{T,2},1})
|
function products{T<:Real}(S1::Array{Array{T,2},1}, S2::Array{Array{T,2},1})
|
||||||
result = [0*similar(S1[1])]
|
result = [0*similar(S1[1])]
|
||||||
@ -132,16 +133,19 @@ function EOI{T<:Number}(Δ::GroupAlgebraElement{T}, κ::T)
|
|||||||
return Δ*Δ - κ*Δ
|
return Δ*Δ - κ*Δ
|
||||||
end
|
end
|
||||||
|
|
||||||
function resulting_SOS{T<:Number}(sqrt_matrix::Array{T,2},
|
@everywhere function square(vector, elt)
|
||||||
elt::GroupAlgebraElement{T})
|
|
||||||
result = zeros(elt.coefficients)
|
|
||||||
zzz = zeros(elt.coefficients)
|
zzz = zeros(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)
|
||||||
|
end
|
||||||
|
|
||||||
|
function compute_SOS{T<:Number}(sqrt_matrix::Array{T,2},
|
||||||
|
elt::GroupAlgebraElement{T})
|
||||||
L = size(sqrt_matrix,2)
|
L = size(sqrt_matrix,2)
|
||||||
for i in 1:L
|
result = @parallel (+) for i in 1:L
|
||||||
info("$i of $L")
|
square(sqrt_matrix[:,i], elt)
|
||||||
zzz[1:L] = view(sqrt_matrix, :,i)
|
|
||||||
new_base = GroupAlgebraElement(zzz, elt.product_matrix)
|
|
||||||
result += (new_base*new_base).coefficients
|
|
||||||
end
|
end
|
||||||
return GroupAlgebraElement{T}(result, elt.product_matrix)
|
return GroupAlgebraElement{T}(result, elt.product_matrix)
|
||||||
end
|
end
|
||||||
@ -161,14 +165,13 @@ function check_solution{T<:Number}(κ::T,
|
|||||||
sqrt_matrix::Array{T,2},
|
sqrt_matrix::Array{T,2},
|
||||||
Δ::GroupAlgebraElement{T})
|
Δ::GroupAlgebraElement{T})
|
||||||
eoi = EOI(Δ, κ)
|
eoi = EOI(Δ, κ)
|
||||||
result = resulting_SOS(sqrt_matrix, Δ)
|
result = compute_SOS(sqrt_matrix, Δ)
|
||||||
L₁_dist = norm(result - eoi,1)
|
L₁_dist = norm(result - eoi,1)
|
||||||
return eoi - result, L₁_dist
|
return eoi - result, L₁_dist
|
||||||
end
|
end
|
||||||
|
|
||||||
function rationalize{T<:Integer, S<:Real}(::Type{T},
|
function rationalize{T<:Integer, S<:Real}(::Type{T},
|
||||||
X::AbstractArray{S}; tol::Real=eps(eltype(X)))
|
X::AbstractArray{S}; tol::Real=eps(eltype(X)))
|
||||||
|
|
||||||
r(x) = rationalize(T, x, tol=tol)
|
r(x) = rationalize(T, x, tol=tol)
|
||||||
return r.(X)
|
return r.(X)
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user