Calculate selected eigenvalues and eigenvectors of a (supposedly sparse) graph.
Usage
spectrum(
graph,
algorithm = c("arpack", "auto", "lapack", "comp_auto", "comp_lapack", "comp_arpack"),
which = list(),
options = arpack_defaults()
)
Arguments
- graph
The input graph, can be directed or undirected.
- algorithm
The algorithm to use. Currently only
arpack
is implemented, which uses the ARPACK solver. See alsoarpack()
.- which
A list to specify which eigenvalues and eigenvectors to calculate. By default the leading (i.e. largest magnitude) eigenvalue and the corresponding eigenvector is calculated.
- options
Options for the ARPACK solver. See
arpack_defaults()
.
Value
Depends on the algorithm used.
For arpack
a list with three entries is returned:
- options
See the return value for
arpack()
for a complete description.- values
Numeric vector, the eigenvalues.
- vectors
Numeric matrix, with the eigenvectors as columns.
Details
The which
argument is a list and it specifies which eigenvalues and
corresponding eigenvectors to calculate: There are eight options:
Eigenvalues with the largest magnitude. Set
pos
toLM
, andhowmany
to the number of eigenvalues you want.Eigenvalues with the smallest magnitude. Set
pos
toSM
andhowmany
to the number of eigenvalues you want.Largest eigenvalues. Set
pos
toLA
andhowmany
to the number of eigenvalues you want.Smallest eigenvalues. Set
pos
toSA
andhowmany
to the number of eigenvalues you want.Eigenvalues from both ends of the spectrum. Set
pos
toBE
andhowmany
to the number of eigenvalues you want. Ifhowmany
is odd, then one more eigenvalue is returned from the larger end.Selected eigenvalues. This is not (yet) implemented currently.
Eigenvalues in an interval. This is not (yet) implemented.
All eigenvalues. This is not implemented yet. The standard
eigen
function does a better job at this, anyway.
Note that ARPACK might be unstable for graphs with multiple components, e.g. graphs with isolate vertices.
See also
as_adjacency_matrix()
to create a (sparse) adjacency matrix.
Centrality measures
alpha_centrality()
,
authority_score()
,
betweenness()
,
closeness()
,
diversity()
,
eigen_centrality()
,
harmonic_centrality()
,
hits_scores()
,
page_rank()
,
power_centrality()
,
strength()
,
subgraph_centrality()
Author
Gabor Csardi csardi.gabor@gmail.com
Examples
## Small example graph, leading eigenvector by default
kite <- make_graph("Krackhardt_kite")
spectrum(kite)[c("values", "vectors")]
#> $values
#> [1] 4.306404
#>
#> $vectors
#> [,1]
#> [1,] -0.35220940
#> [2,] -0.35220940
#> [3,] -0.28583499
#> [4,] -0.48102086
#> [5,] -0.28583499
#> [6,] -0.39769064
#> [7,] -0.39769064
#> [8,] -0.19586058
#> [9,] -0.04807349
#> [10,] -0.01116326
#>
## Double check
eigen(as_adjacency_matrix(kite, sparse = FALSE))$vectors[, 1]
#> [1] -0.35220940 -0.35220940 -0.28583499 -0.48102086 -0.28583499 -0.39769064
#> [7] -0.39769064 -0.19586058 -0.04807349 -0.01116326
## Should be the same as 'eigen_centrality' (but rescaled)
cor(eigen_centrality(kite)$vector, spectrum(kite)$vectors)
#> [,1]
#> [1,] -1
## Smallest eigenvalues
spectrum(kite, which = list(pos = "SM", howmany = 2))$values
#> [1] -0.4043420 0.6403647