1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-11-23 08:15:29 +01:00

merge two sparsify functions

This commit is contained in:
kalmar 2017-07-26 10:29:11 +02:00
parent da32893d64
commit 33b45dd518
2 changed files with 14 additions and 22 deletions

View File

@ -53,13 +53,18 @@ end
include("OrbitDecomposition.jl") include("OrbitDecomposition.jl")
function sparsify{T}(U::AbstractArray{T}, eps=eps(T), check=true) dens(M::SparseMatrixCSC) = length(M.nzval)/length(M)
dens(M::AbstractArray) = sum(abs.(M) .!= 0)/length(M)
function sparsify{T}(U::AbstractArray{T}, check=true)
W = deepcopy(U) W = deepcopy(U)
W[abs.(W) .< eps] = zero(T) W[W .< eps(T)] .= zero(T)
if check && rank(W) != rank(U) if check && rank(W) != rank(U)
warn("Sparsification would decrease the rank!") info("Sparsification would decrease the rank!")
W = U W = U
end else
info("Sparsified:", rpad(dens(U), 10), "\t", rpad(dens(W),10))
end
W = sparse(W) W = sparse(W)
dropzeros!(W) dropzeros!(W)
return W return W
@ -79,14 +84,14 @@ function init_orbit_data(logger, sett::Settings; radius=2)
end end
function transform(U::AbstractArray, V::AbstractArray; sparse=false) function transform(U::AbstractArray, V::AbstractArray; sparse=false)
w = U'*V*U
if sparse if sparse
w = sparsify(w) return sparsify(U'*V*U)
else
return U'*V*U
end end
return w
end end
A(data::OrbitData, π, t) = data.dims[π]*transform(data.Us[π], data.cnstr[t], sparse=true) A(data::OrbitData, π, t) = data.dims[π]*transform(data.Us[π], data.cnstr[t])
function constrLHS(m::JuMP.Model, data::OrbitData, t) function constrLHS(m::JuMP.Model, data::OrbitData, t)
l = endof(data.Us) l = endof(data.Us)

View File

@ -140,19 +140,6 @@ function Cstar_repr(x::GroupRingElem, mreps::Dict)
return res return res
end end
dens(M::SparseMatrixCSC) = length(M.nzval)/length(M)
dens(M::AbstractArray) = sum(abs.(M) .!= 0)/length(M)
function sparsify2(M::AbstractArray)
println("Density before sparsification: \t$(dens(M))")
M = deepcopy(M)
M[M .< eps(eltype(M))] .= zero(eltype(M))
M = sparse(M)
dropzeros!(M)
println("Density after sparsification: \t$(dens(M))")
return M
end
function orthSVD(M::AbstractMatrix) function orthSVD(M::AbstractMatrix)
M = full(M) M = full(M)
fact = svdfact(M) fact = svdfact(M)
@ -205,6 +192,6 @@ function compute_orbit_data{T<:GroupElem}(logger, name::String, G::Nemo.Group, S
info(logger, "dimensions = $dimensions") info(logger, "dimensions = $dimensions")
@assert dot(multiplicities, dimensions) == sizes[radius] @assert dot(multiplicities, dimensions) == sizes[radius]
save(joinpath(name, "U_pis.jld"), "Uπs", Uπs, "spUπs", sparsify2.(Uπs), "dims", dimensions) save(joinpath(name, "U_pis.jld"), "Uπs", Uπs, "spUπs", sparsify.(Uπs), "dims", dimensions)
return 0 return 0
end end