Use shortest path to calculate probability of connection

旧巷老猫 提交于 2019-12-06 03:49:48

If a path's links have probabilities p_1, p_2, ..., p_n of succeeding, then (assuming independence of the link success probabilities, which I will do throughout this answer) the probability that the entire path succeeds is p_1 * p_2 * ... * p_n. As you note this is a product, but shortest path minimizes sums; a common trick to convert products to sums is taking the logarithm. The log of the probability that the path succeeds is log(p_1) + log(p_2) + ... + log(p_n). Maximizing that (our goal) is equivalent to minimizing (-log(p_1)) + (-log(p_2)) + ... (-log(p_n)). Since all the probabilities lie between 0 and 1, their logs are non-positive and therefore the negative of their logs are non-negative.

In conclusion, you can set all your weights to -log(p_i), where p_i is the probability that the connection will succeed, and the shortest path between a pair of nodes (as calculated by the shortest.paths function in igraph) will be the path that maximizes the probability of connection. You could build your graph as a one-liner given your vectors ProbConn and downstream by switching to graph.data.frame:

PIgraph <- graph.data.frame(na.omit(cbind(from=seq_along(downstream), to=downstream,
                                          weight=-log(ProbConn))),
                            vertices=seq_along(downstream))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!