Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3458898
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:02:27+00:00 2026-05-18T10:02:27+00:00

I am trying to generate a random graph that has small-world properties (exhibits a

  • 0

I am trying to generate a random graph that has small-world properties (exhibits a power law distribution). I just started using the networkx package and discovered that it offers a variety of random graph generation. Can someone tell me if it possible to generate a graph where a given node’s degree follows a gamma distribution (either in R or using python’s networkx package)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:02:28+00:00Added an answer on May 18, 2026 at 10:02 am

    If you want to use the configuration model something like this should work in NetworkX:

    import random 
    import networkx as nx
    z=[int(random.gammavariate(alpha=9.0,beta=2.0)) for i in range(100)]
    G=nx.configuration_model(z)
    

    You might need to adjust the mean of the sequence z depending on parameters in the gamma distribution. Also z doesn’t need to be graphical (you’ll get a multigraph), but it does need an even sum so you might have to try a few random sequences (or add 1)…

    The NetworkX documentation notes for configuration_model give another example, a reference and how to remove parallel edges and self loops:

    Notes
    -----
    As described by Newman [1]_.
    
    A non-graphical degree sequence (not realizable by some simple
    graph) is allowed since this function returns graphs with self
    loops and parallel edges.  An exception is raised if the degree
    sequence does not have an even sum.
    
    This configuration model construction process can lead to
    duplicate edges and loops.  You can remove the self-loops and
    parallel edges (see below) which will likely result in a graph
    that doesn't have the exact degree sequence specified.  This
    "finite-size effect" decreases as the size of the graph increases.
    
    References
    ----------
    .. [1] M.E.J. Newman, "The structure and function
           of complex networks", SIAM REVIEW 45-2, pp 167-256, 2003.
    
    Examples
    --------
    >>> from networkx.utils import powerlaw_sequence
    >>> z=nx.create_degree_sequence(100,powerlaw_sequence)
    >>> G=nx.configuration_model(z)
    
    To remove parallel edges:
    
    >>> G=nx.Graph(G)
    
    To remove self loops:
    
    >>> G.remove_edges_from(G.selfloop_edges())
    

    Here is an example similar to the one at http://networkx.lanl.gov/examples/drawing/degree_histogram.html that makes a drawing including a graph layout of the largest connected component:

    #!/usr/bin/env python
    import random
    import matplotlib.pyplot as plt
    import networkx as nx
    
    def seq(n):
        return [random.gammavariate(alpha=2.0,beta=1.0) for i in range(100)]    
    z=nx.create_degree_sequence(100,seq)
    nx.is_valid_degree_sequence(z)
    G=nx.configuration_model(z)  # configuration model
    
    degree_sequence=sorted(nx.degree(G).values(),reverse=True) # degree sequence
    print "Degree sequence", degree_sequence
    dmax=max(degree_sequence)
    
    plt.hist(degree_sequence,bins=dmax)
    plt.title("Degree histogram")
    plt.ylabel("count")
    plt.xlabel("degree")
    
    # draw graph in inset 
    plt.axes([0.45,0.45,0.45,0.45])
    Gcc=nx.connected_component_subgraphs(G)[0]
    pos=nx.spring_layout(Gcc)
    plt.axis('off')
    nx.draw_networkx_nodes(Gcc,pos,node_size=20)
    nx.draw_networkx_edges(Gcc,pos,alpha=0.4)
    
    plt.savefig("degree_histogram.png")
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.