From bc7118f41d4465555afb3884536ee579131eed65 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 5 Sep 2018 09:56:04 +0200 Subject: [PATCH] rework OrbitData --- src/Orbit-wise.jl | 111 ++++++++++++++++++++++++++------------ src/OrbitDecomposition.jl | 29 ---------- 2 files changed, 78 insertions(+), 62 deletions(-) diff --git a/src/Orbit-wise.jl b/src/Orbit-wise.jl index fb48ef9..94e2779 100644 --- a/src/Orbit-wise.jl +++ b/src/Orbit-wise.jl @@ -3,54 +3,99 @@ using SCS export Settings, OrbitData +############################################################################### +# +# OrbitData +# +############################################################################### -struct OrbitData{T<:AbstractArray{Float64, 2}} +struct OrbitData{T<:AbstractArray{Float64, 2}, GEl<:GroupElem, P<:perm} orbits::Vector{Vector{Int}} + preps::Dict{GEl, P} Uπs::Vector{T} dims::Vector{Int} end -function OrbitData(sett::Settings) +function OrbitData(RG::GroupRing, autS::Group) + orbs = orbit_decomposition(autS, RG.basis, RG.basis_dict) + @assert sum(length(o) for o in orbs) == length(RG.basis) + + autS_mps = Projections.rankOne_projections(GroupRing(autS)) + + preps = perm_reps(autS, RG.basis[1:size(RG.pm,1)], RG.basis_dict) + mreps = matrix_reps(preps) + + Uπs = [orthSVD(matrix_repr(p, mreps)) for p in autS_mps] + + multiplicities = size.(Uπs,2) + dimensions = [Int(p[autS()]*Int(order(autS))) for p in autS_mps] + @assert dot(multiplicities, dimensions) == size(RG.pm,1) + + nzros = [i for i in 1:length(Uπs) if size(Uπs[i],2) !=0] + + return OrbitData(orbs, preps, Uπs[nzros], dims[nzros]) +end + +function compute_OrbitData(RG::GroupRing, autS::Group) + + info("Decomposing E into orbits of $(autS)") + @time orbs = orbit_decomposition(autS, RG.basis, RG.basis_dict) + @assert sum(length(o) for o in orbs) == length(RG.basis) + info("E consists of $(length(orbs)) orbits!") + + info("Action matrices") + @time preps = perm_reps(autS, RG.basis[1:size(RG.pm,1)], RG.basis_dict) + mreps = matrix_reps(preps) + + info("Projections") + @time autS_mps = Projections.rankOne_projections(GroupRing(autS)); + + info("Uπs...") + @time Uπs = [orthSVD(matrix_repr(p, mreps)) for p in autS_mps] + + multiplicities = size.(Uπs,2) + info("multiplicities = $multiplicities") + dimensions = [Int(p[autS()]*Int(order(autS))) for p in autS_mps]; + info("dimensions = $dimensions") + @assert dot(multiplicities, dimensions) == size(RG.pm,1) + + return OrbitData(orbs, preps, Uπs, dimensions) +end + +function decimate(od::OrbitData) + nzros = [i for i in 1:length(od.Uπs) if size(od.Uπs[i],2) !=0] + + Us = map(x -> PropertyT.sparsify!(x, eps(Float64)*1e3, verbose=true), od.Uπs[nzros]) + #dimensions of the corresponding πs: + dims = od.dims[nzros] + + return OrbitData(od.orbits, od.preps, full.(Us), dims); +end + +function save_OrbitData(sett::Settings, data::OrbitData) + save_preps(filename(prepath(sett), :preps), data.preps) + + save(filename(prepath(sett), :orbits), + "orbits", data.orbits) + + save(filename(prepath(sett), :Uπs), + "Uπs", data.Uπs, + "dims", data.dims) +end + +function load_OrbitData(sett::Settings) info("Loading Uπs, dims, orbits...") Uπs = load(filename(prepath(sett), :Uπs), "Uπs") nzros = [i for i in 1:length(Uπs) if size(Uπs[i],2) !=0] - Uπs = Uπs[nzros] Uπs = map(x -> sparsify!(x, sett.tol/100, verbose=true), Uπs) #dimensions of the corresponding πs: - dims = load(filename(prepath(sett), :Uπs), "dims")[nzros] - - orbits = load(filename(prepath(sett), :orbits), "orbits"); - - return OrbitData(orbits, Uπs, dims) -end - -include("OrbitDecomposition.jl") - - - -end - - - - - - - -end - - - -end - - - -end - - + dims = load(filename(prepath(sett), :Uπs), "dims") + orbits = load(filename(prepath(sett), :orbits), "orbits") preps = load_preps(filename(prepath(sett), :preps), sett.autS) + return OrbitData(orbits, preps, Uπs, dims) end function load_preps(fname::String, G::Group) diff --git a/src/OrbitDecomposition.jl b/src/OrbitDecomposition.jl index d3505da..81ba650 100644 --- a/src/OrbitDecomposition.jl +++ b/src/OrbitDecomposition.jl @@ -108,33 +108,4 @@ function orthSVD(M::AbstractMatrix{T}) where {T<:AbstractFloat} return fact[:U][:,1:M_rank] end -function compute_orbit_data(name::String, RG::GroupRing, autS::Group) - - info("Decomposing E into orbits of $(autS)") - @time orbs = orbit_decomposition(autS, RG.basis, RG.basis_dict) - @assert sum(length(o) for o in orbs) == length(RG.basis) - info("E consists of $(length(orbs)) orbits!") - - info("Action matrices") - @time preps = perm_reps(autS, RG.basis[1:size(RG.pm,1)], RG.basis_dict) - mreps = matrix_reps(preps) - - info("Projections") - @time autS_mps = Projections.rankOne_projections(GroupRing(autS)); - - @time π_E_projections = [Cstar_repr(p, mreps) for p in autS_mps] - - info("Uπs...") - @time Uπs = orthSVD.(π_E_projections) - - multiplicities = size.(Uπs,2) - info("multiplicities = $multiplicities") - dimensions = [Int(p[autS()]*Int(order(autS))) for p in autS_mps]; - info("dimensions = $dimensions") - @assert dot(multiplicities, dimensions) == size(RG.pm,1) - - save(filename(name, :orbits), "orbits", orbs) - save_preps(filename(name, :preps), preps) - save(filename(name, :Uπs), "Uπs", Uπs, "dims", dimensions) - return 0 end