使用 SQL Server/C 的聚类系数#

Clustering Coefficient using SQL Server/C#

我在 SQL 服务器中有两个 table,即
一个 table 是 GraphNodes 作为:

---------------------------------------------------------
id | Node_ID | Node            |  Node_Label | Node_Type
---------------------------------------------------------
1    677       Nuno Vasconcelos   Author       1
2    1359      Peng Shi           Author       1
3    6242      Z. Q. Shi          Author       1
4    8318      Kiyoung Choi       Author       1
5    12405     Johan A. K.        Author       1
6    26615     Tzung-Pei Hong     Author       1
7    30559     Luca Benini        Author       1  
...  
...  

和其他 table 是 GraphEdges 作为:

-----------------------------------------------------------------------------------------
id | Source_Node | Source_Node_Type | Target_Node | Target_Node_Type | Year |  Edge_Type
-----------------------------------------------------------------------------------------
1    1             1                  10965         2                  2005    1
2    1             1                  10179         2                  2007    1
3    1             1                  10965         2                  2007    1
4    1             1                  19741         2                  2007    1
5    1             1                  10965         2                  2009    1
6    1             1                  4816          2                  2011    1
7    1             1                  5155          2                  2011    1  
...  
...

我也有两个 table,即 GraphNodeTypes 作为:

-------------------------
id | Node    | Node_Type
-------------------------
1    Author    1
2    CoAuthor  2
3    Venue     3
4    Paper     4  

GraphEdgeTypes为:

-------------------------------
id | Edge          | Edge_Type
-------------------------------
1    AuthorCoAuthor  1
2    CoAuthorVenue   2
3    AuthorVenue     3
4    PaperVenue      4
5    AuthorPaper     5
6    CoAuthorPaper   6  

现在,我想计算此图的聚类系数,即两种类型:
如果 N(V) 是链接数 b/w 节点 V 的邻居并且 K(V) 是节点 V 的度数,那么,

Local Clustering Coefficient(V) = 2 * N(V)/K(V) [K(V) - 1]  

Global Clustering Coefficient = 3 * # of Triangles / # of connected Triplets of V  

问题是,如何计算节点的度数?在 SQL 中是否可能需要服务器或 C# 编程。并且还请提出计算本地和全局 CC 的提示。

谢谢!

节点的度数不是"calculated"。它只是该节点具有的边数。

虽然您可以在 SQL 中尝试这样做,但性能可能会很一般。这种类型的分析通常在专门的数据库中完成,如果可能的话,在内存中完成。

将每个顶点的度数计算为与其相连的边数。在这种情况下,使用 COUNT(source_node) 和 GROUP BY(source_node) 会有所帮助。

要找到 N(V),您可以将边 table 与其自身连接起来,然后取所得到的 table 和边 table 之间的交集。根据结果​​,对于每个顶点取 COUNT().