Git Product home page Git Product logo

graph's People

Contributors

alatiku avatar chisomgold avatar dtenenba avatar hpages avatar jwokaty avatar mmaechler avatar mtmorgan avatar nturaga avatar pshannon-bioc avatar sonali-bioc avatar villafup avatar vjcitn avatar vobencha avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

graph's Issues

Bug in edgeMatrix

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))

Representation of self-loops and the calculation of degrees

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:

image

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

Adjacency on directed graphs ignores parents

Description of problem

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.

Steps to reproduce

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")))

Setup

  • R version: 4.3.0 (2023-04-21)
  • platform: aarch64-apple-darwin20
  • graph package version: 1.78.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.