欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

neo4j社区发现算法(Community detection algorithms)-4.The Triangle Counting / Clustering Coefficient

程序员文章站 2024-02-03 21:17:46
...

一.介绍
    聚集系数算法,在图论中,聚集系数表示一个图形中节点聚集程度的系数,具体来说,是一个点的邻接点之间相互连接的程度。证据显示,在现实网络中,尤其是在特定的网络中,由于相对高密度连接点的关系,节点总是趋向于建立一组严密组织关系。
  聚集系数可分为全局聚集和局部聚集:
    全局聚集:
    全局聚集系数是基于节点三元组的,三元组分为开放的和封闭的,开放的是指三个节点由两条边连接,封闭的是指三个节点由三条边连接。全局聚集系数是所有三元组中封闭三元组的数目。
    全局聚集系数是封闭的三元组数目/所有三元组数目
    局部聚集:
    局部聚集系数针对的是节点,一个节点的局部集聚系数是他的邻居节点也被链接的可能性
二.neo4j算法:

CALL algo.triangle.stream(label:String, relationship:String, {concurrency:4})
YIELD nodeA, nodeB, nodeC
返回的是节点
CALL algo.triangleCount.stream(label:String, relationship:String, {concurrency:4}) 
YIELD nodeId, triangles,coefficient
返回节点的聚集系数

三.实例:

MERGE (alice:Person{id:"Alice"})
MERGE (michael:Person{id:"Michael"})
MERGE (karin:Person{id:"Karin"})
MERGE (chris:Person{id:"Chris"})
MERGE (will:Person{id:"Will"})
MERGE (mark:Person{id:"Mark"})
MERGE (michael)-[:KNOWS]->(karin)
MERGE (michael)-[:KNOWS]->(chris)
MERGE (will)-[:KNOWS]->(michael)
MERGE (mark)-[:KNOWS]->(michael)
MERGE (mark)-[:KNOWS]->(will)
MERGE (alice)-[:KNOWS]->(michael)
MERGE (will)-[:KNOWS]->(chris)
MERGE (chris)-[:KNOWS]->(karin);

neo4j社区发现算法(Community detection algorithms)-4.The Triangle Counting / Clustering Coefficient

CALL algo.triangle.stream('Person','KNOWS')
YIELD nodeA,nodeB,nodeC
RETURN algo.getNodeById(nodeA).id AS nodeA, algo.getNodeById(nodeB).id AS nodeB,algo.getNodeById(nodeC).id AS node

neo4j社区发现算法(Community detection algorithms)-4.The Triangle Counting / Clustering Coefficient

CALL algo.triangleCount.stream('Person', 'KNOWS', {concurrency:4})
YIELD nodeId, triangles, coefficient
RETURN algo.getNodeById(nodeId).id AS name, triangles, coefficient
ORDER BY coefficient DESC

neo4j社区发现算法(Community detection algorithms)-4.The Triangle Counting / Clustering Coefficient

相关标签: neo4j