rigraph icon indicating copy to clipboard operation
rigraph copied to clipboard

Treat self-loops in igraph functions consistently.

Open clpippel opened this issue 2 years ago • 3 comments

What is the feature or improvement you would like to see?

# Let gu be an undirected, unweighted graph, with self loops.
library(igraph)
gu <- graph(c(1,1,1,2), directed=FALSE );
IGRAPH d10b9d9 U--- 2 2 -- 
+ edges from d10b9d9:
# [1] 1--1 1--2

degree(gu)
# [1] 3 1

as_adjacency_matrix(gu)
# [1,] 1 1
# [2,] 1 .

laplacian_matrix(gu)
# [1,]  1 -1
# [2,] -1  1

# This example violates the condition that the diagonal of the Laplacian matrix must be equal to the degree of the vertices.

Function degree() adds 2 to the degree of vertex 1. Function as_adjacency_matrix() adds 1 to the degree of vertex 1. This seems inconsistent to me.

Note that the function 10.1.1. igraph_adjlist_init - Constructs an adjacent list of vertices of a given graph allows arguments mode, loops and multiple.

Will this issue be addressed in version 10 of rigraph?

References Gábor Csárdi et al., igraph Reference Manual, https://igraph.org/c/pdf/latest/igraph-docs.pdf.

clpippel avatar Jan 21 '24 11:01 clpippel

@szhorvat is this different in other igraph interfaces?

maelle avatar Feb 26 '24 15:02 maelle

The long term plan was to treat undirected self-loops as being present twice in the adjacency matrix. This is already how all functions behave that implicitly use an adjacency matrix, such as eigenvector centrality, assortativity, Laplacian matrix, etc.

Functions that deal with the adjacency matrix explicitly should give users the option to treat undirected loops once, twice or ignore them. Support is 90% there in the C core but not at all exposed in R yet.

szhorvat avatar Feb 26 '24 15:02 szhorvat

Ok, thanks. so putting this in the "future" milestone for now.

maelle avatar Mar 04 '24 16:03 maelle

see also https://github.com/igraph/rigraph/issues/1102

schochastics avatar Jul 16 '25 12:07 schochastics