Computes the similarity between two igraph objects using their adjacency matrices. Supports Frobenius norm-based similarity and cosine similarity.

adjacency_similarity(g1, g2, method = "frobenius")

Arguments

g1

An igraph object representing the first graph.

g2

An igraph object representing the second graph.

method

A character string specifying the similarity method: "frobenius" (default) or "cosine".

Value

A numeric value between 0 (no similarity) and 1 (identical graphs).

Examples

library(igraph)
g1 <- graph_from_edgelist(matrix(c(1, 2, 2, 3), ncol = 2, byrow = TRUE), directed = FALSE)
g2 <- graph_from_edgelist(matrix(c(1, 2, 2, 4), ncol = 2, byrow = TRUE), directed = FALSE)
adjacency_similarity(g1, g2, method = "frobenius") # Output: 0.5
#> [1] 0.5
adjacency_similarity(g1, g2, method = "cosine") # Output: 0.5
#> [1] 0.5