bioconductor / graph Goto Github PK
View Code? Open in Web Editor NEWgraph: A package to handle graph data structures
Home Page: https://bioconductor.org/packages/graph
graph: A package to handle graph data structures
Home Page: https://bioconductor.org/packages/graph
Hello,
I think I found a bug in the edgeMatrix function. When the input is a graphAM object with an adjacency matrix that has exactly one entry in each row, then 'to' is a vector instead of a list and the next line cannot be executed. Here is a minimal example with a (2x2)-matrix:
library(graph) # version 1.66.0
adjm <- matrix(c(0,1,1,0), nrow=2) # this matrix has exactly one entry in each row
obj <- graphAM(adjMat=adjm, edgemode="directed")
edgeMatrix(obj) # Error
##from the source code of edgeMatrix (I replaced 'object' with 'obj'):
to <- apply(obj@adjMat, 1, function(x) which(x != 0)) # 'to' is a vector
from <- rep(seq_len(numNodes(obj)), graph:::listLen(to)) # Error
If the adjacency matrix has rows without entries, or rows with more than one entry, then the error does not occur, as in this unproblematic example:
adjm_2 <- matrix(c(0,1,1, 1,0,0, 1,0,0), nrow=3)
obj_2 <- graphAM(adjMat=adjm_2, edgemode="directed")
edgeMatrix(obj_2)
##from the source code of edgeMatrix (I replaced 'object' with 'obj_2'):
to <- apply(obj_2@adjMat, 1, function(x) which(x != 0)) # 'to' is a list
from <- rep(seq_len(numNodes(obj_2)), graph:::listLen(to))
This is a verbatim copy of the post I wrote here.
I am writing to ask whether the graphNEL
class of the graph package supports self-loops. If yes, how should self-loops in undirected graphs be represented? Should they appear once or twice in the adjacency list?
As an example, consider the following way to construct a graph:
gn <- graphNEL(nodes=c('A','B'), edgeL=list(A=c('A','B'), B=c('A')), edgemode='undirected')
The undirected graph I intend to represent is the following:
I.e., there are two connected vertices, and one of them has a single-self loop.
B
has degree 1 and A
has degree 3. However, the degree function indicates a degree of 2 for A
:
> degree(gn)
A B
2 1
Is this intentional or is it a bug? If intentional, this would be a highly unusual definition for the idea of "degree" that does not possess many of the usual properties of the more commonly known degree concept. For example, the degrees no longer sum up to twice the number of edges. Such a definition is not invalid, but it is unusual enough that it should be pointed out explicitly in the documentation.
Or is it perhaps the case that self-loops are supposed to be included twice in the adjacency list when creating undirected graphs?
gn <- graphNEL(nodes=c('A','B'), edgeL=list(A=c('A', 'A', 'B'), B=c('A')), edgemode='undirected')
It would be great if these issues could be clarified in the documentation.
This issue came up while investigating a bug report for igraph's as_graphnel()
function: igraph/rigraph#575
The documentation for adj-methods
states that nodes are adjacent to a given node if "they are joined to the given node by an edge". In directed graphs, this includes the children and also the parents of the given node. However, the adj
method only returns the children.
The following code snippet should not fail
g <- graph::graphNEL(nodes = LETTERS[1:2], edgemode = "directed")
g <- graph::addEdge("A", "B", g)
stopifnot(identical(graph::adj(g, "A"), graph::adj(g, "B")))
Add all authors to vignettes that originally were lacking authors
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.