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 6106639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:06:05+00:00 2026-05-23T14:06:05+00:00

I’m just coding a program in C++ that calculates the clustering coefficient [ CC

  • 0

I’m just coding a program in C++ that calculates the clustering coefficient [CC] (local and global) of an undirected graph in dot format. My problem is that the result of my program doesn’t match the output from R (with igraph library):

My program:

The cluster coefficient of "0"  is: 0.257 (88/342)
The cluster coefficient of "1"  is: 0.444 (40/90)
The cluster coefficient of "10" is: 1.000 (2/2)
The cluster coefficient of "2"  is: 0.418 (46/110)
The cluster coefficient of "11" is: 1.000 (2/2)
The cluster coefficient of "12" is: 0.667 (8/12)
The cluster coefficient of "3"  is: 0.346 (54/156)
The cluster coefficient of "5"  is: 0.571 (24/42)
The cluster coefficient of "13" is: 1.000 (12/12)
The cluster coefficient of "4"  is: 0.607 (34/56)
The cluster coefficient of "7"  is: 0.679 (38/56)
The cluster coefficient of "14" is: 1.000 (6/6)
The cluster coefficient of "15" is: 0.833 (10/12)
The cluster coefficient of "16" is: 1.000 (6/6)
The cluster coefficient of "17" is: 0.733 (22/30)
The cluster coefficient of "9"  is: 0.833 (10/12)
The cluster coefficient of "18" is: 0.714 (30/42)
The cluster coefficient of "19" is: 1.000 (6/6)
The cluster coefficient of "6"  is: 1.000 (2/2)
The cluster coefficient of "8"  is: 0.733 (22/30)

Where the “”‘s are the Nodes of the graph and the (n/m) numbers are “the links between the vertices within its neighborhood” (n) and “the number of links that could possibly exist between them” (m) respectively (description from Wikipedia)
And the output from R:

0  0.2631579        x (+2 links)
1  0.4666667        x (+2 links)
2  0.4181818
3  0.3461538
4  0.6071429
5  0.6190476        x (+2 links)
6  1.0000000
7  0.6785714
8  0.6666667        x (-2 links)
9  0.8000000
10 1.0000000
11 1.0000000
12 0.6666667
13 1.0000000
14 1.0000000
15 0.8333333
16 1.0000000
17 0.7333333
18 0.7142857
19 1.0000000

Where the first number in each row is the Node, the second is it’s local CC and the third one is my annotation when it doesn’t match my output (specifying the number of links (n) I need to add/remove to match R‘s output).

The second problem I have is that the global CC from R does not match my definition or the Wikipedia’s (unless I have misunderstood the formula). The output from R for this graph is 0.458891 and mine is 0.742


So I did it manually: I calculated the 8’s CC and matches my program’s output. So my question is that “is even possible that igraph library have a bug?” and if the answer is “no”: “what I’m missing?”

The graph file is this one:

graph {
  1 -- 0;
  10 -- 0;
  10 -- 2;
  11 -- 0;
  11 -- 2;
  12 -- 0;
  12 -- 1;
  12 -- 3;
  12 -- 5;
  13 -- 0;
  13 -- 3;
  13 -- 4;
  13 -- 7;
  14 -- 0;
  14 -- 1;
  14 -- 4;
  15 -- 0;
  15 -- 2;
  15 -- 3;
  16 -- 0;
  16 -- 15;
  16 -- 3;
  17 -- 0;
  17 -- 1;
  17 -- 2;
  17 -- 5;
  17 -- 7;
  17 -- 9;
  18 -- 0;
  18 -- 1;
  18 -- 2;
  18 -- 3;
  18 -- 4;
  18 -- 7;
  19 -- 0;
  19 -- 18;
  19 -- 3;
  2 -- 0;
  2 -- 1;
  3 -- 0;
  3 -- 2;
  4 -- 0;
  4 -- 1;
  4 -- 3;
  5 -- 0;
  5 -- 2;
  5 -- 3;
  6 -- 0;
  6 -- 3;
  7 -- 0;
  7 -- 1;
  7 -- 2;
  7 -- 3;
  7 -- 4;
  8 -- 0;
  8 -- 1;
  8 -- 2;
  8 -- 3;
  8 -- 4;
  8 -- 5;
  9 -- 0;
  9 -- 1;
  9 -- 5;
}

The way I calculated the CC with R is loading the graph (or generating a new one, because it can’t read dot files) into a var “f”, for example, and executing transitivity(f) for global CC and transitivity(f, “local”) for local one.

Thanks a lot for reading and sorry for my bad English.

  • 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-23T14:06:06+00:00Added an answer on May 23, 2026 at 2:06 pm

    One of the authors of igraph here.

    I have just loaded your graph into igraph (the Python interface) and its results match yours to the last digit. Which version of igraph you are using?

    As for the “global” clustering coefficient, note that there are at least two conflicting definitions:

    1. Calculating the number of triangles in the entire network and dividing it by the number of possible triangles. This is the “real” global clustering coefficient, and igraph calculates this by default.

    2. Calculating the local clustering coefficients for each node and taking the average. This is the “average local” clustering coefficient, and you are calculating this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.