1
#' @title Hyperbolic (centrality) index
2
#' @description The hyperbolic index is an index that considers all closed 
3
#' walks of even or odd length on induced neighborhoods of a vertex.
4
#' @param g igraph object. 
5
#' @param type string. 'even' if only even length walks should be considered. 'odd' (Default)
6
#' if only odd length walks should be used.
7
#' @details The hyperbolic index is an illustrative index that should 
8
#' not be used for any serious analysis. Its purpose is to show that with enough mathematical 
9
#' trickery, any desired result can be obtained when centrality indices are used. 
10
#' @return A vector containing centrality scores.
11
#' @author David Schoch
12
#' @examples
13
#' 
14
#' library(igraph)
15
#' 
16
#' g <- graph.empty(n=11,directed = FALSE)
17
#' g <- add_edges(g,c(1,11,2,4,3,5,3,11,4,8,5,9,5,11,6,7,6,8,
18
#'                    6,10,6,11,7,9,7,10,7,11,8,9,8,10,9,10))
19
#' hyperbolic_index(g,type = "odd")
20
#' hyperbolic_index(g,type = "even")
21
#' @export
22
hyperbolic_index <- function(g, type = "odd") {
23 0
    n <- igraph::vcount(g)
24 0
    if (type == "even") {
25 0
        ENW <- rep(0, n)
26 0
        for (v in 1:n) {
27 0
            Nv <- igraph::neighborhood(g, 1, v)[[1]]
28 0
            g1 <- igraph::induced.subgraph(g, Nv)
29 0
            C <- igraph::get.adjacency(g1, type = "both")
30 0
            eig.decomp <- eigen(C, symmetric = TRUE)
31 0
            V <- (eig.decomp$vectors)^2
32 0
            lambda <- eig.decomp$values
33 0
            ENW[v] <- sum(V %*% cosh(lambda)) * igraph::graph.density(g1)  #cosh(x)
34
        }
35 0
    } else if (type == "odd") {
36 0
        ENW <- rep(0, n)
37 0
        for (v in 1:n) {
38 0
            Nv <- igraph::neighborhood(g, 1, v)[[1]]
39 0
            g1 <- igraph::induced.subgraph(g, Nv)
40 0
            C <- igraph::get.adjacency(g1, type = "both")
41 0
            eig.decomp <- eigen(C, symmetric = TRUE)
42 0
            V <- (eig.decomp$vectors)^2
43 0
            lambda <- eig.decomp$values
44 0
            ENW[v] <- sum(V %*% sinh(lambda)) * igraph::graph.density(g1)  #sinh(x)
45
        }
46
    } else {
47 0
        stop("type must be even or odd")
48
    }
49 0
    return(ENW)
50
}

Read our documentation on viewing source code .

Loading