Message Boards Message Boards

1
|
4661 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Different results with VertexEccentricity from those with std. functions?

Posted 2 years ago

Attached is a notebook that loads Graph data and calculates the GraphPeriphery and GraphCenter with standard functions and in addition with VertexEccentricity equations.

In my opinion, the results among standard functions and VertexEccentricity equations should be identical, but they are not. Is my assumption wrong? Do we face a bug?

Please, let me know your opinion.

POSTED BY: Jürgen Kanz
3 Replies
  1. Jason, Thank you so much for your valuable feedback.
  2. I have to admit, that some of my assumptions were wrong and misleading. I am sorry.
  3. I could not correctly distinguish between the name of an edge and the position of a vertex in a list. Just by adding the prefix “node” to each edge, the entire problem disappeared. Attached notebook show what I have done.
  4. Therefore, I have to withdraw my statement that the functions GraphPeriphery[] and GraphCenter[] deliver wrong results.
Attachments:
POSTED BY: Jürgen Kanz

Before answering the question about GraphPeriphery I would make one suggestion for speeding up your code. The SemanticImport call that you make returns a Dataset object, which is nice for visualizing the data but very slow here. Using Normal will convert it into a usable form. So instead of doing

LaunchKernels[];
edges = ParallelTable[
   data[[i, 1]] \[UndirectedEdge] data[[i, 2]], {i, 1, 
    Length[data]}];
CloseKernels[];

just do

edges = UndirectedEdge @@@ Normal[data]

it is orders of magnitude faster. Secondly, don't create a graph with one edge and then add the remaining edges like this

g = Graph[edges[[1]]];
f = EdgeAdd[g, Take[edges, -(Length[edges] - 1)]];

instead just use

f = Graph[edges]

Now to the reason you see a difference between GraphPeriphery and Position[ecc, Max[ecc]] is because the position of the vertex in the list is not the same as the vertex. In general you might expect that the VertexList will be just {1, 2, 3, 4, ...} but really the vertices can be in any order. When you create a graph from a list of edges, you don't control the order of the vertices like you do when creating a graph via Graph[verts, edges].

So for your graph you can see

In[30]:= VertexList[f] // Shallow

Out[30]//Shallow= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...}

which is why periphery found by Position is wrong - an off-by-one error in this case. If you always want to work with a graph whose vertices are {1, 2, 3, ...} then use IndexGraph like

f = IndexGraph[UndirectedEdge @@@ Normal[data]]

You can check the results visually with

GraphPlot@HighlightGraph[f, GraphPeriphery[f]]

enter image description here

compare this to the periphery you were computing before when you had the off-by-one error: enter image description here

POSTED BY: Jason Biggs

Today, I have found the time to look at the differences in more detail.

In general, we can say, that the standard functions GraphPeriphery[] and GraphCenter[] can deliver wrong results. So, we face some software bugs here. As a workaround, we can apply the following code:

ecc = VertexEccentricity[f, #] & /@ VertexList[f];
graphperiphery = Flatten[Position[ecc, Max[ecc]]] 
graphcenter = Flatten[Position[ecc, Min[ecc]]]

For more details, please have a look at the updated notebook.

Attachments:
POSTED BY: Jürgen Kanz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract