SciProgCentre/kmath

Bug in SVD?

michael-bauer-horsch opened this issue · 3 comments

I have some doubts about the correctness of the implementation of Singular Value Decomposition.

Take f.e. this input matrix/tensor:
{{6,3,-3},{-3,3,6},{-3,-6,-3}}

WolframAlpha and numpy will calculate the following singular values: 9, 9, 0,
whereas kmath will differ in the last singular value by giving 8.2206 with default epsilon.

Also, values in U and V are different - WolframAlpha is able to come up with the exact values it seems.

I don't understand the math. From what I've researched, my input matrix might not be the best example by allowing for some freedom in U, S, V.

Still, kmath's result differs from the results numpy and Wolfram are giving which makes me think that something is suboptimal on kmath side.
Also, the rigid pose estimation I'm using SVD for is failing with kmath while it is working fine with Python/numpy
(while using the exact same afore-mentioned input matrix).

Let me know if I should prepare a MWE.

@grinisrit Could you check that?

r6wy2 commented

commons-math3 gives the correct solution.
As it is included as dependency why not also use it for solving svd?

@r6wy2 @michael-bauer-horsch sorry for the late reply. Commons math is a dependency only form KMath-commons it works only on JVM while KMath. You can use it as well as KMath-ejml if you need only JVM support. Both variants are compatible with the rest of KMath algebras.

@grinisrit could you please check if there is a bug in the algorithm?