From bb5ed331d3f165c801c730c2fffcdff34b2e4149 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sun, 9 Sep 2018 11:37:11 +0200 Subject: [PATCH] redistribute content of OrbitDecomposition into new files --- src/OrbitDecomposition.jl | 82 --------------------------------------- src/PropertyT.jl | 1 - src/orbitdata.jl | 64 ++++++++++++++++++++++++++++++ src/sos_sdps.jl | 13 +++++++ 4 files changed, 77 insertions(+), 83 deletions(-) delete mode 100644 src/OrbitDecomposition.jl diff --git a/src/OrbitDecomposition.jl b/src/OrbitDecomposition.jl deleted file mode 100644 index 114ae91..0000000 --- a/src/OrbitDecomposition.jl +++ /dev/null @@ -1,82 +0,0 @@ -############################################################################### -# -# Orbits and orbit_spvector -# -############################################################################### - -function orbit_decomposition(G::Group, E::Vector, rdict=GroupRings.reverse_dict(E)) - - elts = collect(elements(G)) - - tovisit = trues(E); - orbits = Vector{Vector{Int}}() - - orbit = zeros(Int, length(elts)) - - for i in 1:endof(E) - if tovisit[i] - g = E[i] - Threads.@threads for j in 1:length(elts) - orbit[j] = rdict[elts[j](g)] - end - tovisit[orbit] = false - push!(orbits, unique(orbit)) - end - end - return orbits -end - -function orbit_spvector(vect::AbstractVector, orbits) - orb_vector = spzeros(length(orbits)) - - for (i,o) in enumerate(orbits) - k = vect[collect(o)] - val = k[1] - @assert all(k .== val) - orb_vector[i] = val - end - - return orb_vector -end - -############################################################################### -# -# perm-, matrix-, representations -# -############################################################################### - -function perm_repr(g::GroupElem, E::Vector, E_dict) - p = Vector{Int}(length(E)) - for (i,elt) in enumerate(E) - p[i] = E_dict[g(elt)] - end - return p -end - -function perm_reps(G::Group, E::Vector, E_rdict=GroupRings.reverse_dict(E)) - elts = collect(elements(G)) - l = length(elts) - preps = Vector{perm}(l) - - permG = PermutationGroup(length(E)) - - Threads.@threads for i in 1:l - preps[i] = permG(PropertyT.perm_repr(elts[i], E, E_rdict), false) - end - - return Dict(elts[i]=>preps[i] for i in 1:l) -end - -function matrix_repr(x::GroupRingElem, mreps::Dict) - nzeros = findn(x.coeffs) - return sum(x[i].*mreps[parent(x).basis[i]] for i in nzeros) -end - -function matrix_reps(preps::Dict{T,perm{I}}) where {T<:GroupElem, I<:Integer} - kk = collect(keys(preps)) - mreps = Vector{SparseMatrixCSC{Float64, Int}}(length(kk)) - Threads.@threads for i in 1:length(kk) - mreps[i] = AbstractAlgebra.matrix_repr(preps[kk[i]]) - end - return Dict(kk[i] => mreps[i] for i in 1:length(kk)) -end diff --git a/src/PropertyT.jl b/src/PropertyT.jl index e52b55e..c219c23 100644 --- a/src/PropertyT.jl +++ b/src/PropertyT.jl @@ -142,7 +142,6 @@ end include("Laplacians.jl") -include("OrbitDecomposition.jl") include("orbitdata.jl") include("sos_sdps.jl") include("CheckSolution.jl") diff --git a/src/orbitdata.jl b/src/orbitdata.jl index f36cf95..d2c5ead 100644 --- a/src/orbitdata.jl +++ b/src/orbitdata.jl @@ -114,6 +114,28 @@ function orthSVD(M::AbstractMatrix{T}) where {T<:AbstractFloat} return fact[:U][:,1:M_rank] end +function orbit_decomposition(G::Group, E::Vector, rdict=GroupRings.reverse_dict(E)) + + elts = collect(elements(G)) + + tovisit = trues(E); + orbits = Vector{Vector{Int}}() + + orbit = zeros(Int, length(elts)) + + for i in 1:endof(E) + if tovisit[i] + g = E[i] + Threads.@threads for j in 1:length(elts) + orbit[j] = rdict[elts[j](g)] + end + tovisit[orbit] = false + push!(orbits, unique(orbit)) + end + end + return orbits +end + ############################################################################### # # Sparsification @@ -160,3 +182,45 @@ function sparsify!{T}(M::AbstractArray{T}, eps=eps(T); verbose=false) end sparsify{T}(U::AbstractArray{T}, tol=eps(T); verbose=false) = sparsify!(deepcopy(U), tol, verbose=verbose) + +############################################################################### +# +# perm-, matrix-, representations +# +############################################################################### + +function perm_repr(g::GroupElem, E::Vector, E_dict) + p = Vector{Int}(length(E)) + for (i,elt) in enumerate(E) + p[i] = E_dict[g(elt)] + end + return p +end + +function perm_reps(G::Group, E::Vector, E_rdict=GroupRings.reverse_dict(E)) + elts = collect(elements(G)) + l = length(elts) + preps = Vector{perm}(l) + + permG = PermutationGroup(length(E)) + + Threads.@threads for i in 1:l + preps[i] = permG(PropertyT.perm_repr(elts[i], E, E_rdict), false) + end + + return Dict(elts[i]=>preps[i] for i in 1:l) +end + +function matrix_repr(x::GroupRingElem, mreps::Dict) + nzeros = findn(x.coeffs) + return sum(x[i].*mreps[parent(x).basis[i]] for i in nzeros) +end + +function matrix_reps(preps::Dict{T,perm{I}}) where {T<:GroupElem, I<:Integer} + kk = collect(keys(preps)) + mreps = Vector{SparseMatrixCSC{Float64, Int}}(length(kk)) + Threads.@threads for i in 1:length(kk) + mreps[i] = AbstractAlgebra.matrix_repr(preps[kk[i]]) + end + return Dict(kk[i] => mreps[i] for i in 1:length(kk)) +end diff --git a/src/sos_sdps.jl b/src/sos_sdps.jl index 474d38f..71e06b3 100644 --- a/src/sos_sdps.jl +++ b/src/sos_sdps.jl @@ -23,6 +23,19 @@ function orbit_constraint!(result::SparseMatrixCSC, cnstrs, orbit; val=1.0/lengt return result end +function orbit_spvector(vect::AbstractVector, orbits) + orb_vector = spzeros(length(orbits)) + + for (i,o) in enumerate(orbits) + k = vect[collect(o)] + val = k[1] + @assert all(k .== val) + orb_vector[i] = val + end + + return orb_vector +end + ############################################################################### # # Naive SDP