R/similarity_cos_l.R

# 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]
}

Try the linkprediction package in your browser

Any scripts or data that you put into this service are public.

linkprediction documentation built on May 1, 2019, 9:58 p.m.