Skip to content

Commit efbf53d

Browse files
Merge pull request #7 from haotian127/master
update HL's dissertation figures and a couple of small fixes
2 parents a5c8ad9 + f85ec9c commit efbf53d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+188
-67
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MultiscaleGraphSignalTransforms"
22
uuid = "cc44fc10-d0fb-5545-af72-ba1cb661a341"
33
authors = ["Naoki Saito <saito@math.ucdavis.edu>", "Yiqun Shao <shaoyiqun1992@gmail.com>", "Haotian Li <htsli@ucdavis.edu>"]
4-
version = "1.5.1"
4+
version = "1.5.2"
55

66
[deps]
77
Arpack = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"

src/LP-NGWP.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,49 @@ function const_meyer_wavelets(𝚽, Uf; idx = 1:size(Uf, 1))
247247
Wavelets = varimax(B)
248248
return Wavelets
249249
end
250+
251+
"""
252+
lp_ngwp_analysis(G::GraphSig, 𝚽::Matrix{Float64}, W_dual::SparseMatrixCSC{Float64, Int64},
253+
GP_dual::GraphPart; ϵ::Float64 = 0.3)
254+
255+
perform the LP-NGWP transform of the graph signal(s) `G.f`.
256+
257+
# Input Arguments
258+
- `G::GraphSig`: a GraphSig object
259+
- `𝚽::Matrix{Float64}`: graph Laplacian eigenvectors
260+
- `W_dual::SparseMatrixCSC{Float64, Int64}`: weight matrix of the dual graph
261+
- `GP_dual::GraphPart`: GraphPart object of the dual graph
262+
263+
# Output Argument
264+
- `wavelet_packet::Array{Float64,3}`: the lapped NGWP dictionary. The first
265+
index is for selecting wavelets at a fixed level; the second index is for
266+
selecting the level `j`; the third index is for selecting elements in the
267+
wavelet vector.
268+
269+
"""
270+
function lp_ngwp_analysis(G::GraphSig, 𝚽::Matrix{Float64}, W_dual::SparseMatrixCSC{Float64, Int64},
271+
GP_dual::GraphPart; ϵ::Float64 = 0.3)
272+
rs = GP_dual.rs
273+
inds = GP_dual.inds
274+
(N, jmax) = Base.size(inds)
275+
fcols = size(G.f, 2)
276+
277+
GP_dual.tag = zeros(Int, N, jmax)
278+
GP_dual.tag[:, 1] = Vector{Int}(0:(N - 1))
279+
280+
Uf = Matrix{Float64}(I, N, N)
281+
used_node = Set()
282+
283+
dmatrix = zeros(N, jmax, fcols)
284+
dmatrix[:, 1, :] = G.f
285+
for j = 2:jmax
286+
regioncount = count(!iszero, rs[:, j]) - 1
287+
keep_folding!(Uf, used_node, W_dual, GP_dual; ϵ = ϵ, j = j - 1)
288+
for r = 1:regioncount
289+
indr = rs[r, j]:(rs[r + 1, j] - 1)
290+
GP_dual.tag[indr, j] = Vector{Int}(0:(length(indr) - 1))
291+
dmatrix[indr, j, :] = const_meyer_wavelets(𝚽, Uf; idx = inds[indr, j])' * G.f
292+
end
293+
end
294+
return dmatrix
295+
end

src/MultiscaleGraphSignalTransforms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export natural_eigdist
5252
export SunFlowerGraph, dualgraph
5353
export pc_ngwp, pairclustering
5454
export vm_ngwp, varimax
55-
export lp_ngwp, rising_cutoff, find_pairinds, pair_inds_shadding
55+
export lp_ngwp, rising_cutoff, find_pairinds, pair_inds_shadding, lp_ngwp_analysis
5656
export LPHGLET_Synthesis, LPHGLET_Analysis_All, HGLET_dictionary, LPHGLET_dictionary
5757
export unitary_folding_operator, keep_folding!
5858
export ngwp_analysis, ngwp_bestbasis, NGWP_jkl

src/helpers.jl

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,52 +121,74 @@ SCATTER\\_GPLOT!(X; ...) adds a plot to `current` one.
121121
122122
"""
123123
function scatter_gplot(X; marker = nothing, ms = 4, plotOrder = :normal, c = :viridis)
124-
dim = size(X,2)
125-
if marker != nothing && plotOrder != :normal
126-
if plotOrder == :s2l
124+
N, dim = size(X)
125+
if marker != nothing
126+
if size(marker) == (N,) || size(marker) == (N, 1)
127+
marker = marker[:] # reshape N x 1 matrix to a vector of length N
128+
else
129+
error("marker only accepts a vector of length $(N) or a matrix of size $(N) x 1.")
130+
end
131+
if plotOrder == :normal
132+
idx = 1:N
133+
elseif plotOrder == :s2l
127134
idx = sortperm(marker)
128135
elseif plotOrder == :l2s
129-
idx = sortperm(marker, rev=true)
136+
idx = sortperm(marker, rev = true)
130137
else
131-
print("Error: plotOrder only supports for :normal, :s2l, or :l2s.")
138+
error("plotOrder only supports for :normal, :s2l, or :l2s.")
132139
end
133-
X = X[idx,:]
140+
X = X[idx, :]
134141
marker = marker[idx]
135142
if length(ms) > 1
136143
ms = ms[idx]
137144
end
138145
end
139146
if dim == 2
140-
scatter(X[:,1],X[:,2], marker_z = marker, ms = ms, c = c, legend = false, mswidth = 0, cbar = true, aspect_ratio = 1, grid = false)
147+
scatter(X[:, 1], X[:, 2], marker_z = marker, ms = ms, c = c,
148+
legend = false, mswidth = 0, cbar = true, aspect_ratio = 1,
149+
grid = false)
141150
elseif dim == 3
142-
scatter(X[:,1],X[:,2],X[:,3], marker_z = marker, ms = ms, c = c, legend = false, mswidth = 0, cbar = true, aspect_ratio = 1, grid = false)
151+
scatter(X[:, 1], X[:, 2], X[:, 3], marker_z = marker, ms = ms, c = c,
152+
legend = false, mswidth = 0, cbar = true, aspect_ratio = 1,
153+
grid = false)
143154
else
144-
print("Dimension Error: scatter_gplot only supports for 2-dim or 3-dim scatter plots.")
155+
error("Dimension Error: scatter_gplot only supports for 2-dim or 3-dim scatter plots.")
145156
end
146157
end
147158

148159
function scatter_gplot!(X; marker = nothing, ms = 4, plotOrder = :normal, c = :viridis)
149-
dim = size(X,2)
150-
if marker != nothing && plotOrder != :normal
151-
if plotOrder == :s2l
160+
N, dim = size(X)
161+
if marker != nothing
162+
if size(marker) == (N,) || size(marker) == (N, 1)
163+
marker = marker[:] # reshape N x 1 matrix to a vector of length N
164+
else
165+
error("marker only accepts a vector of length $(N) or a matrix of size $(N) x 1.")
166+
end
167+
if plotOrder == :normal
168+
idx = 1:N
169+
elseif plotOrder == :s2l
152170
idx = sortperm(marker)
153171
elseif plotOrder == :l2s
154-
idx = sortperm(marker, rev=true)
172+
idx = sortperm(marker, rev = true)
155173
else
156-
print("Error: plotOrder only supports for :normal, :s2l, or :l2s.")
174+
error("plotOrder only supports for :normal, :s2l, or :l2s.")
157175
end
158-
X = X[idx,:]
176+
X = X[idx, :]
159177
marker = marker[idx]
160178
if length(ms) > 1
161179
ms = ms[idx]
162180
end
163181
end
164182
if dim == 2
165-
scatter!(X[:,1],X[:,2], marker_z = marker, ms = ms, c = c, legend = false, mswidth = 0, cbar = true, aspect_ratio = 1, grid = false)
183+
scatter!(X[:, 1], X[:, 2], marker_z = marker, ms = ms, c = c,
184+
legend = false, mswidth = 0, cbar = true, aspect_ratio = 1,
185+
grid = false)
166186
elseif dim == 3
167-
scatter!(X[:,1],X[:,2],X[:,3], marker_z = marker, ms = ms, c = c, legend = false, mswidth = 0, cbar = true, aspect_ratio = 1, grid = false)
187+
scatter!(X[:, 1], X[:, 2], X[:, 3], marker_z = marker, ms = ms, c = c,
188+
legend = false, mswidth = 0, cbar = true, aspect_ratio = 1,
189+
grid = false)
168190
else
169-
print("Dimension Error: scatter_gplot! only supports for 2-dim or 3-dim scatter plots.")
191+
error("Dimension Error: scatter_gplot! only supports for 2-dim or 3-dim scatter plots.")
170192
end
171193
end
172194

22.8 KB
20.4 KB
33.8 KB
37.9 KB
-18.1 KB
-26.7 KB

0 commit comments

Comments
 (0)