我只是用 C++ 编写一个程序,它计算点格式的无向图的聚类系数 [ CC ](局部和全局)。我的问题是我的程序的结果与R的输出不匹配(使用igraph库):
我的程序:
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)
其中“”是图的节点,(n / m)数字是“其邻域内顶点之间的链接”(n)和“它们之间可能存在的链接数”(m)分别(来自维基百科的描述)和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
每行中的第一个数字是Node,第二个是本地CC,第三个是我的注释,当它与我的输出不匹配时(指定我需要添加/删除以匹配R的链接数(n)的输出)。
我遇到的第二个问题是R中的全局CC与我的定义或维基百科的定义不匹配(除非我误解了公式)。此图的R输出为0.458891,我的输出为0.742
所以我手动完成了:我计算了 8 的CC并匹配我的程序的输出。所以我的问题是“igraph 库甚至可能有错误吗?” 如果答案是“不”:“我错过了什么?”
图形文件是这个:
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;
}
例如,我用R计算CC的方式是将图形(或生成一个新的,因为它无法读取点文件)加载到 var“f”中,并为全局CC和传递性执行传递性(f)( f,“本地”)为本地之一。
非常感谢您的阅读,并为我糟糕的英语感到抱歉。