How to generate and study regular graph for a non-integer average degree?

834 Views Asked by At

I have an undirected graph with the following attributes and I need to do some analysis on a fully random graph and a regular graph with the same attributes.

Attributes:

Number of Nodes = 37764
Number of Edges = 518151
Average Degree = 27.44153161741341

To study the properties of random graphs, I create them using networkx.gnm_random_graph(37764,518151) and performed my analysis. But I am very much confused about how to generate regular graphs using the same attributes.

I found two methods to generate regular graphs here using networkx.random_regular_graph(k, n) (documentation) and igraph.Graph().K_Regular(n, k) (documentation), but noticed that they need the degree k to be an integer value.

But in my original graph, the value is a float value 27.44153161741341. Now I cannot understand how to create a regular graph (or many graphs to give the same above-mentioned attributes when averaged) for my analysis.

In rephrasing my question: How to deal with the decimal part of the average degree in my case?

Language/library no bound for the solution.

1

There are 1 best solutions below

12
On

A regular graph is a graph where each vertex has the same degree.

It's not possible to have a regular graph with an average decimal degree because all nodes in the graph would need to have a decimal degree.

The best you can do is:

>>> G = nx.random_regular_graph(27, 37764)
>>> len(G.edges())
509814

# OR

>>> G = nx.random_regular_graph(28, 37764)
>>> len(G.edges())
528696

I guess you could try something like:

def perfect_avg(v_27, v_28):
    return v_27 * (1-0.44153161741341) + v_28 * (0.44153161741341)

where v_27 is the value for the graph with degree = 27
(and v_28 the value for the graph with degree = 28)

For example:

>>> nr_edges27 = len(G27.edges())
>>> nr_edges28 = len(G28.edges())
>>> perfect_avg(nr_edges27, nr_edges28)
518151.0