neo4j-contrib / neo4j-graph-algorithms

Efficient Graph Algorithms for Neo4j
https://github.com/neo4j/graph-data-science/
GNU General Public License v3.0
767 stars 196 forks source link

how to use cypher projection and seedProperty in labelPropagation? #934

Open xiexiexxs opened 4 years ago

xiexiexxs commented 4 years ago

hi all, when using labelPropagation (in neo4j-graph-algorithms-3.5.14.0-standalone),i met a problem . how to use cypher projection and seedProperty in labelPropagation. here is the example network.

QQ图片20200311135236 i tried 3 methods to do label propagation. the second the third used cypher projection and seedProperty seperately and got right answer.the first used both but get wrong answer,which partition all nodes into one community,showed as following. QQ图片20200311135230 AAA all codes are here:

MERGE (nAlice:node {id:'Alice'}) SET nAlice.seed_label=52
MERGE (nBridget:node {id:'Bridget'}) SET nBridget.seed_label=21
MERGE (nDoug:node {id:'Doug'}) SET nDoug.seed_label=21
MERGE (nMark:node {id:'Mark'}) SET nMark.seed_label=19
MERGE (nMichael:node {id:'Michael'}) SET nMichael.seed_label=52
MERGE (nAlice)-[:FOLLOW]->(nBridget)
MERGE (nMark)-[:FOLLOW]->(nDoug)
MERGE (nBridget)-[:FOLLOW]->(nMichael)
MERGE (nDoug)-[:FOLLOW]->(nMark)
MERGE (nMichael)-[:FOLLOW]->(nAlice)
MERGE (nAlice)-[:FOLLOW]->(nMichael)
MERGE (nBridget)-[:FOLLOW]->(nAlice)
MERGE (nMichael)-[:FOLLOW]->(nBridget)

CALL algo.labelPropagation(
    'MATCH (a:node) RETURN id(a) as id',
    'MATCH (a:node)-[r:FOLLOW]-(b:node) RETURN id(a) as source ,id(b) as target',
    {graph:'cypher',iterations:50,partitionProperty:'seed_label',write:true,writeProperty:'s1'}
    )

CALL algo.labelPropagation(
    'MATCH (a:node) RETURN id(a) as id',
    'MATCH (a:node)-[r:FOLLOW]-(b:node) RETURN id(a) as source ,id(b) as target',
    {graph:'cypher',iterations:50,write:true,writeProperty:'s2'}
    )

CALL algo.labelPropagation('node','FOLLOW',
{iterations:50,partitionProperty:'seed_label',write:true,writeProperty:'s3'}
)