Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
#' @title Spectral gap of a graph
|
|
2 |
#' @description The spectral (or eigen) gap of a graph is the absolute
|
|
3 |
#' difference between the biggest and second biggest eigenvalue
|
|
4 |
#' of the adjacency matrix. To compare spectral gaps across networks, the fraction can be used.
|
|
5 |
#'
|
|
6 |
#' @param g igraph object
|
|
7 |
#' @param method A string, either "frac" or "abs"
|
|
8 |
#' @return Numeric value
|
|
9 |
#' @details The spectral gap is bounded between 0 and 1 if `method="frac"`. The closer
|
|
10 |
#' the value to one, the bigger the gap.
|
|
11 |
#' @author David Schoch
|
|
12 |
#' @examples
|
|
13 |
#' #The fractional spectral gap of a threshold graph is usually close to 1
|
|
14 |
#' g <- threshold_graph(50,0.3)
|
|
15 |
#' spectral_gap(g,method = "frac")
|
|
16 |
#'
|
|
17 |
#' @export
|
|
18 |
#'
|
|
19 |
spectral_gap <- function(g, method = "frac") { |
|
20 | 1 |
spec_decomp <- eigen(igraph::get.adjacency(g, "both"))$values[c(1, 2)] |
21 | 1 |
if (method == "frac") { |
22 | 1 |
return(1 - spec_decomp[2]/spec_decomp[1]) |
23 | 1 |
} else if (method == "abs") { |
24 | 1 |
return(spec_decomp[1] - spec_decomp[2]) |
25 |
} else { |
|
26 | 1 |
stop("method must be one of 'frac' or 'abs'") |
27 |
}
|
|
28 |
}
|
Read our documentation on viewing source code .