R/similarity_cos_l.R

Defines functions similarity_cos_l

# Cosine similarity  on \eqn{L^+}
#
# Similarity measure based on the pseudoinverse of the Laplacian matrix
#
# This function measures the cosine of the angle between columns of
#   the pseudoinverse of the Laplacian matrix.
#

similarity_cos_l <- function(graph, v1, v2, ...){
  L <- igraph::graph.laplacian(graph)
  n <- igraph::vcount(graph)
  m <- igraph::ecount(graph)

  L_psinv <- solve(L - 1/n) + 1/n
  dL <- diag(L_psinv)
  score <- L_psinv / outer(dL, dL, function(x, y) sqrt(x * y))
  score[v1, v2]
}
mbojan/linkprediction documentation built on Nov. 30, 2020, 5:22 a.m.