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

  • SEARCH
  • Home
  • 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 6235701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:42:56+00:00 2026-05-24T10:42:56+00:00

I have a set of randomly generated formal graphs, and I would like to

  • 0

I have a set of randomly generated formal graphs, and I would like to calculate the entropy of each one. The same question in different words: I have several networks, and want to calculate the information content of each one.

Here are two sources containing formal definitions of graph entropy:
http://www.cs.washington.edu/homes/anuprao/pubs/CSE533Autumn2010/lecture4.pdf (PDF)
http://arxiv.org/abs/0711.4175v1

The code I am looking for takes a graph as input (as either an edge list or an adjacency matrix) and outputs a number of bits or some other measure of information content.

Because I can’t find an implementation of this anywhere, I am setting out to code this from scratch based on the formal definitions. If anyone has already solved this problem and is willing to share the code, it would be wildly appreciated.

  • 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-24T10:42:56+00:00Added an answer on May 24, 2026 at 10:42 am

    I ended up using different papers for definitions of graph entropy:
    Information Theory of Complex Networks: On Evolution and Architectural Constraints
    R.V. Sole and S. Valverde (2004)
    and
    Network Entropy Based on Topology Configuration and Its Computation to Random Networks
    B.H. Wang, W.X. Wang and T. Zhou

    The code to calculate each is below. The code assumes you have an undirected, unweighted graph with no self-loops. It takes an adjacency matrix as input and returns the amount of entropy in bits. It is implemented in R and makes use of the sna package.

    graphEntropy <- function(adj, type="SoleValverde") {
      if (type == "SoleValverde") {
        return(graphEntropySoleValverde(adj))
      }
      else {
        return(graphEntropyWang(adj))
      }
    }
    
    graphEntropySoleValverde <- function(adj) {
      # Calculate Sole & Valverde, 2004 graph entropy
      # Uses Equations 1 and 4
      # First we need the denominator of q(k)
      # To get it we need the probability of each degree
      # First get the number of nodes with each degree
      existingDegrees = degree(adj)/2
      maxDegree = nrow(adj) - 1
      allDegrees = 0:maxDegree
      degreeDist = matrix(0, 3, length(allDegrees)+1) # Need an extra zero prob degree for later calculations
      degreeDist[1,] = 0:(maxDegree+1)
      for(aDegree in allDegrees) {
        degreeDist[2,aDegree+1] = sum(existingDegrees == aDegree)
      }
      # Calculate probability of each degree
      for(aDegree in allDegrees) {
        degreeDist[3,aDegree+1] = degreeDist[2,aDegree+1]/sum(degreeDist[2,])
      }
      # Sum of all degrees mult by their probability
      sumkPk = 0
      for(aDegree in allDegrees) {
        sumkPk = sumkPk + degreeDist[2,aDegree+1] * degreeDist[3,aDegree+1]
      }
      # Equivalent is sum(degreeDist[2,] * degreeDist[3,])
      # Now we have all the pieces we need to calculate graph entropy
      graphEntropy = 0
      for(aDegree in 1:maxDegree) {
        q.of.k = ((aDegree + 1)*degreeDist[3,aDegree+2])/sumkPk
        # 0 log2(0) is defined as zero
        if (q.of.k != 0) {
          graphEntropy = graphEntropy + -1 * q.of.k * log2(q.of.k)
        }
      }
      return(graphEntropy)
    }
    
    graphEntropyWang <- function(adj) {
      # Calculate Wang, 2008 graph entropy
      # Uses Equation 14
      # bigN is simply the number of nodes
      # littleP is the link probability.  That is the same as graph density calculated by sna with gden().
      bigN = nrow(adj)
      littleP = gden(adj)
      graphEntropy = 0
      if (littleP != 1 && littleP != 0) {
        graphEntropy = -1 * .5 * bigN * (bigN - 1) * (littleP * log2(littleP) + (1-littleP) * log2(1-littleP))
      }
      return(graphEntropy)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of numbers like so (randomly generated, numbers sorted within each
If i have a set of randomly generated numbers (integers), how do I find
I have a set of visible divs/or images. by clicking one item, I'd like
I have set a background on the data-role=page element like so <div data-role=page style=background:
I have set of flat files (114 files) each file is named with database
A newbie question. (ADDED NEW INFO) I have a set of time stamped data
Let's say I have a table of users set up like this: CREATE TABLE
I have a much longer string of numbers randomly generated. I am displaying it
I have already posted another question about this, but no one seemed to know
Scenario I am developing an application that intensively use randomly generated values. I have

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.