我可以使用neo4j gds最短路径算法进行乘法而不是加法吗?

问题描述 投票:0回答:1

我使用neo4j数据库来计算节点之间的最短路径。整个图包含400K个节点。当我用加法运算计算权重时,我可以使用如下最短路径算法,但是如果我想用乘法运算该怎么办计算节点的权重?

MATCH (sourceNode:entity{name: $name}) 
CALL gds.alpha.shortestPath.deltaStepping.stream({
     startNode: sourceNode, 
     nodeProjection: "*", 
     relationshipProjection: {
         all: {
         type: "*", 
         properties: "weight",
         orientation: "UNDIRECTED" 
         } 
     }, 
     relationshipWeightProperty: "weight", 
     delta: 1.0 
     })
YIELD nodeId, distance 
WHERE gds.util.isFinite(distance) 
RETURN sourceNode.name, 
       gds.util.asNode(nodeId).name AS aim_entity,
       distance 
ORDER BY distance;
neo4j cypher neo4j-apoc
1个回答
1
投票

您可以通过取对数将

weight
域映射到
logWeight
域 - 那么在对数空间中的加法就是正则空间中的乘法。

您可以使用的功能:

https://neo4j.com/docs/cypher-manual/current/functions/mathematical-logarithmic/

然后,如果您计算(使用对数权重)到节点

n
的最短路径是
n.ShortestDistance
,您可以通过执行
exp(n.ShortestDistance)
获得所有权重(对数前)的乘积。

© www.soinside.com 2019 - 2024. All rights reserved.