mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-09-17 17:32:57 +02:00
59 lines
1.7 KiB
Julia
59 lines
1.7 KiB
Julia
|
###############################################################################
|
||
|
#
|
||
|
# Laplacians
|
||
|
#
|
||
|
###############################################################################
|
||
|
|
||
|
function spLaplacian(RG::GroupRing, S, T::Type=Float64)
|
||
|
result = RG(T)
|
||
|
result[RG.group()] = T(length(S))
|
||
|
for s in S
|
||
|
result[s] -= one(T)
|
||
|
end
|
||
|
return result
|
||
|
end
|
||
|
|
||
|
function spLaplacian(RG::GroupRing{R}, S, T::Type=Float64) where {R<:Ring}
|
||
|
result = RG(T)
|
||
|
result[one(RG.group)] = T(length(S))
|
||
|
for s in S
|
||
|
result[s] -= one(T)
|
||
|
end
|
||
|
return result
|
||
|
end
|
||
|
|
||
|
function computeLaplacian(S::Vector{E}, radius) where E<:AbstractAlgebra.RingElem
|
||
|
R = parent(first(S))
|
||
|
return computeLaplacian(S, one(R), radius)
|
||
|
end
|
||
|
|
||
|
function computeLaplacian(S::Vector{E}, radius) where E<:AbstractAlgebra.GroupElem
|
||
|
G = parent(first(S))
|
||
|
return computeLaplacian(S, G(), radius)
|
||
|
end
|
||
|
|
||
|
function computeLaplacian(S, Id, radius)
|
||
|
info("Generating metric ball of radius $radius...")
|
||
|
@time E_R, sizes = Groups.generate_balls(S, Id, radius=2radius)
|
||
|
info("Generated balls of sizes $sizes.")
|
||
|
|
||
|
info("Creating product matrix...")
|
||
|
@time pm = GroupRings.create_pm(E_R, GroupRings.reverse_dict(E_R), sizes[radius]; twisted=true)
|
||
|
|
||
|
RG = GroupRing(parent(Id), E_R, pm)
|
||
|
Δ = spLaplacian(RG, S)
|
||
|
return Δ
|
||
|
end
|
||
|
|
||
|
function loadLaplacian(name::String, G::Group)
|
||
|
if exists(filename(name, :Δ)) && exists(filename(name, :pm))
|
||
|
info("Loading precomputed Δ...")
|
||
|
RG = GroupRing(G, load(filename(name, :pm), "pm"))
|
||
|
Δ = GroupRingElem(load(filename(name, :Δ), "Δ")[:, 1], RG)
|
||
|
else
|
||
|
throw("You need to precompute $(filename(name, :pm)) and $(filename(name, :Δ)) to load it!")
|
||
|
end
|
||
|
return Δ
|
||
|
end
|
||
|
|