-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a parameter to compose cost fn #64
Comments
Can you give me an example of a problem that benefits from this? One potential concern is if any weights are numbers from 0 to 1, the shortest-path algorithm wouldn't find the shortest path. |
Hello @Engelberg. Thanks for the quick response The use caseI have a graph where each edge has a "probability" and I want to find the path with the highest probability. Where the probabilities are numbers between 0.0-1.0 and the probability of 0.5 with another 0.5 is 0.25. Current solutionI end up fixing it with math: I'm not sure if this solution is totally right, but it is working for our use-case. Final solutionIf we decide to use |
Your probability use-case is interesting, and your solution of doing the additive inverse of the log is a clever way to transform a "find the greatest product" problem into "find the smallest sum" problem. If you had compose-cost-fn of First, the shortest-path algorithm would be trying to find the smallest product, not the greatest. Second, the algorithm wouldn't even succeed at finding the smallest product because each successive edge in the graph is lowering the cost, and this algorithm assumes the total cost of the path stays the same or increases with each edge. (So, for example, with additive costs, negative numbers won't work and currently the library catches that and notifies the user they should be using Bellman-Ford instead, which can handle negative weights). So, even if The negative log solution also has another advantage: multiplying lots of probabilities will quickly tend towards 0, making it difficult to compare two long paths accurately due to limitations of floating point numbers, whereas the logs should put them into a range where addition is more stable. I think your current solution may well be the best solution. |
costs are always composed with
+
i want to compose them with
*
It should be exposed in
ubergraph.alg/shortest-path
by adding an extra attr tosearch-specification
:https://github.com/Engelberg/ubergraph/blob/v0.8.1/src/ubergraph/alg.clj#L232
The text was updated successfully, but these errors were encountered: