Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-20-2023 07:57 AM
I want to calculate the total probability of graph by multiplying probabilities of nodes. but the multiplication changes according to connection of nodes. For example, the calculation for above graph should be like: The probability of that the end-to-end system will work from startnode2 (node a) to endnode2 (node e) following the relationship :TO will be: 1*(1-(1-0.999)*(1-0.999)*(1-0.999))*1)= 0.999999999
01-20-2023 08:22 AM
I posted a comment for a similar problem:
As I stated in the comment, I believe you will need to write a custom procedure if you are looking for an algorithm that will calculate the probability for any graph between the start and finish nodes.
What are you looking for?
01-20-2023 08:32 AM
I've tried this, but it only handles nodes connected in series, not in loop.
MATCH path = (start:Node {name: "start"})-[:TO*]->(end:Node {name: "end"})
WITH nodes(path) as nodes_in_path
RETURN reduce(probability = 1.0, node in nodes_in_path | probability *
(CASE
WHEN size([(node)-[:TO]->(:Node) | 1]) > 1 THEN (1-node.probability)*node.probability
ELSE node.probability END)) as probability
01-20-2023 10:33 AM
I think you can handle in cypher the scenario where you have multiple simple paths between start and end. In simple, I mean they don't branch. I sketched it out on paper.
The result of your match statement will be a set of rows, each row corresponding to a path in the diagram. You can calculate each path's probability of success using the 'reduce' operation as you suggested. You can collect these values and use an overall 'reduce' method to calculate the overall probability of failure, then calculate the overall probability of success from the 'reduce' operations result and return it.
Cypher would not be the tool if you want to be able to calculate the probability for a random network that can have branching and such.
01-28-2023 01:31 AM
Can somone please correct this qury;
Invalid input '[': expected "+" or "-" (line 5, column 26 (offset: 179)) "CASE WHEN (pathNodes[i])-[:DIRECT]->(pathNodes[i+1]) THEN prob * pathNodes[i].probability"
01-28-2023 04:55 AM
You can’t use an expression when referencing a node or relationship in a pattern. To fix it, assign pathNode[i] and pathNodes[i+1] in a WTH statement to variables and use those variables in the pattern. Also, wrap your pattern in an ‘exits’ method to make it a predicate. I think your use is being deprecated.
All the sessions of the conference are now available online