4 ms·
I am not thinking this through but since cos is monotonous between 0 and pi/2, you can avoid the square root by squaring the numerator and still have a good sim
by sound_of_basker 11y ago
I am not thinking this through but since cos is monotonous between 0 and pi/2, you can avoid the square root by squaring the numerator and still have a good similarity indicator. This is going to eke out some performance with a short tweak.
- contravariant 11y agoIt might not be a good idea to just square the numerator. Doing so would give an advantage to words with a small norm, i.e. a small number of letters. Unless you actually want that to happen of course. You could alternatively square the thing in it's entirety, this causes problems if a.b is negative but if you're only using positive coefficients (as in this case) then that can't happen, but even if it could then it's pretty easy to check if it is positive or not.
- sound_of_basker 11y agoThat is what I meant. I wanted to point out that sqrt is more expensive compared to squared and you could just square the whole thing without affecting the results too much. cos(theta) and cos^2(theta) are pretty close and monotonous between 0 and pi/2: http://www.wolframalpha.com/input/?i=cos%28theta%29+vs+cos%28theta%29*cos%28theta%29 http://www.wolframalpha.com/input/?i=cos%28theta%29+vs+cos%2...