@@ -7,27 +7,23 @@ export Spectral, spectral
7
7
spectral(adj_matrix; kwargs...)
8
8
9
9
This algorithm uses the technique of Spectral Graph Drawing, which is an
10
- under-appreciated method of graph layouts; easier, simpler, and faster
11
- than the more common spring-based methods. For reference see
12
-
13
- - <http://www.research.att.com/export/sites/att_labs/groups/infovis/res/legacy_papers/DBLP-journals-camwa-Koren05.pdf>
14
- - <http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.3.2055&rep=rep1&type=pdf>
10
+ under-appreciated method of graph layouts; easier, simpler, and faster than the
11
+ more common spring-based methods. For reference see [Yehuda Koren,
12
+ 2002](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.3.2055&rep=rep1&type=pdf).
15
13
16
14
Takes adjacency matrix representation of a network and returns coordinates of
17
15
the nodes.
18
16
19
17
## Keyword Arguments
20
- - `Ptype=Float64`: Determines the output type `Point{3,Ptype}`.
21
- - `nodeweights=Float64[]`
22
-
23
- Vector of weights. If network size does not match the length of `nodesize` use
24
- `ones` instead.
18
+ - `dim=3`, `Ptype=Float64`: Determines dimension and output type `Point{dim,Ptype}`.
19
+ - `nodeweights=Float64[]`: Vector of weights. If network size does not match the
20
+ length of `nodesize` use `ones` instead.
25
21
"""
26
- @addcall struct Spectral{Ptype,FT<: AbstractFloat } <: AbstractLayout{3 ,Ptype}
22
+ @addcall struct Spectral{Dim, Ptype,FT<: AbstractFloat } <: AbstractLayout{Dim ,Ptype}
27
23
nodeweights:: Vector{FT}
28
24
end
29
25
30
- Spectral (; Ptype= Float64, nodeweights= Float64[]) = Spectral {Ptype,eltype(nodeweights)} (nodeweights)
26
+ Spectral (; dim = 3 , Ptype= Float64, nodeweights= Float64[]) = Spectral {dim, Ptype,eltype(nodeweights)} (nodeweights)
31
27
32
28
function make_symmetric (adj_matrix:: AbstractMatrix )
33
29
adj_matrix = copy (adj_matrix)
@@ -55,7 +51,7 @@ function compute_laplacian(adj_matrix, node_weights)
55
51
return L, D
56
52
end
57
53
58
- function layout (algo:: Spectral{Ptype,FT} , adj_matrix:: AbstractMatrix ) where {Ptype,FT}
54
+ function layout (algo:: Spectral{Dim, Ptype,FT} , adj_matrix:: AbstractMatrix ) where {Dim, Ptype,FT}
59
55
N = assertsquare (adj_matrix)
60
56
# try to use user provided nodeweights
61
57
nodeweights = if length (algo. nodeweights) == N
@@ -70,5 +66,5 @@ function layout(algo::Spectral{Ptype,FT}, adj_matrix::AbstractMatrix) where {Pty
70
66
v = eigen (L, D). vectors
71
67
# x, y, and z are the 2nd through 4th eigenvectors of the solution to the
72
68
# generalized eigenvalue problem Lv = λDv
73
- return [ Point {3 ,Ptype} (v[ 2 , i], v[ 3 , i], v[ 4 , i]) for i in 1 : size (v, 2 )]
69
+ return map (x -> Point {Dim ,Ptype} (x[ 2 : (Dim + 1 )] . .. ), eachrow (v))
74
70
end
0 commit comments