How to verify if a graph obeys a power law?

2019-09-08 14:59发布

问题:

I am using the GraphStream to generate syntethic graphs. What is the formula to verify if the graph obeys the power law? (I have only the number of nodes and edges) Thanks.

回答1:

So we have a graph with an edge collection named relations. We can gather the required data using a full table scan on this edge collection using AQL in ArangoDB. We need to unify _from and _to so we can count them. We use the collect statement to evaluate the diameter for each vertex:

FOR oneEdge IN relations 
  FOR edgeLink IN [ oneEdge._from, oneEdge._to ]
    COLLECT edgesCounterItem = edgeLink WITH COUNT INTO graphDiameter
      RETURN { what: edgesCounterItem, count: graphDiameter }

Now that we know the diameters, we need to group once more by the diameters:

FOR oneEdge IN relations 
  FOR edgeLink IN [ oneEdge._from, oneEdge._to ]
    COLLECT edgesCounterItem = edgeLink WITH COUNT INTO graphDiameter
      COLLECT powerCounts = graphDiameter WITH COUNT INTO powerCounter
        RETURN {numberEdges: powerCounts, vertexCount: powerCounter}

Now we want this nicely sorted so we can easily plot it:

FOR oneEdge IN relations 
  FOR edgeLink IN [ oneEdge._from, oneEdge._to ]
    COLLECT edgesCounterItem = edgeLink WITH COUNT INTO graphDiameter
      COLLECT powerCounts = graphDiameter WITH COUNT INTO powerCounter
        SORT powerCounts
          RETURN {numberEdges: powerCounts, vertexCount: powerCounter}

With this chart you then will be able to determine whether a power law is fullfilled or not.

Note: this definitely will require a lot of system resources to compute.