Can obliquefactory.m's logarithm be simplified?

16 views
Skip to first unread message

pzpz...@gmail.com

unread,
Aug 31, 2020, 4:37:22 PM8/31/20
to Manopt
The current logarithm uses arcsin, sqrt, square, and sum.
I'm wondering if this can be simplified into just arccos and dot.
The reason for this is more than just readability. It's also faster. In my local timing tests, you can cut a second off on 10000 logarithms of 34000 values each. Might seem trivial but this adds up quite a bit in our application. Was there a reason such a complex form was needed?

Nicolas Boumal

unread,
Sep 1, 2020, 4:01:49 AM9/1/20
to Manopt
Thank you for your question.

Yes, you can replace this with the arccos form: it's mathematically equivalent, and indeed faster. What I'd suggest is that you create your M with a call to the factory (not modified), then replace M.log with a function handle to separate code of your own. This way, your code keeps working if you update Manopt later on. Alternatively, you can send a pull request for modifications to the factory where you implement M.log_acos (for example), and after your call to the factory you set M.log = M.log_acos;

Yes, there is a reason for using the arcsin form: this is explained in the code for the distance on the sphere, see https://github.com/NicolasBoumal/manopt/blob/master/manopt/manifolds/sphere/spherefactory.m#L87 -- in the code to compute distances, there is an explanation for why arcsin is more accurate when computing the distance between two points that are very close to each other (think: less than sqrt(machine precision)); in fact, the arccos form loses all precision below that threshold. If in your application it is not relevant to favor accuracy for such close points, then it is indeed better to favor compute time.

Best,
Nicolas

Nicolas Boumal

unread,
Sep 1, 2020, 4:06:20 AM9/1/20
to Manopt
Ah, actually there isn't much of an explanation in the code of spherefactory.

The basics are: we need to compute acos(x'*y); when x and y are very close, then x'*y is almost 1; but the derivative of acos at 1 is infinite, so: the sensitivity to round-off error is terrible. In particular, consider this:

>> acos(1)
ans =
     0
>> acos(1-eps)
ans =
   2.1073e-08

There are no representable numbers between 1-eps and 1. This shows that it is impossible accurately to compute the distance between two points that are separated by a distance between 0 and 10^-8: there just aren't any numbers in between.

Paul zhang

unread,
Sep 1, 2020, 12:32:12 PM9/1/20
to Nicolas Boumal, Manopt
Ah I see. Thanks for the detailed explanation!

--
http://www.manopt.org
---
You received this message because you are subscribed to a topic in the Google Groups "Manopt" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/manopttoolbox/dO_CEzUydkw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to manopttoolbo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/manopttoolbox/bde06918-5be7-43ed-bce9-91c1aa895e83n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages