3

I changed LMNN (Largest Margin Nearest Neighbor) metric learning algorithm matlab code to java, and use Jama library. I got different result, The difference occurred, I think because of the eigenValue decomposition (eigenvalue and eigenvector) in Matlab and Jama. Would you please comment me if you encountered such problem before. In addition, is it must to get similar result under such condition.

In Matlab:

[V, L] = eig(M);

Java ( IdeM is PSD matrix)

Matrix V = ideM.eig().getV();
Matrix L = ideM.eig().getD();

Results

Example results:

A = [2 4 2; 6 8 1; 5 7 5] 

Matlab result:

>> [V,L] = eig(A)
V =
      -0.3486     -0.82756      0.19221
     -0.57978      0.56013     -0.40315
     -0.73643     0.037403      0.89472
L =
       12.878            0            0
            0      -0.7978            0
            0            0         2.92

Java using Jama Library:

[[0.8275575078346545, -0.3493113857121139, 0.24597790205308678],
 [-0.5601335729999509, -0.5809634522691761, -0.5159207870175849],
 [-0.037402561741212, -0.7379374514853343, 1.144995023469712]] 
[[-0.7977988158677061,0.0, 0.0], 
 [0.0, 12.877769427129202, 0.0], 
 [0.0, 0.0,2.9200293887385067]]
Andrew Janke
  • 23,508
  • 5
  • 56
  • 85
saha
  • 93
  • 1
  • 5
  • 11
  • Can you be specific about what's different between the results you're getting with the two languages? – Andrew Janke Mar 27 '14 at 14:08
  • A = [2 4 2; 6 8 1;5 7 5] Matlab result: V = -0.3486 -0.8276 0.1922 -0.5798 0.5601 -0.4032 -0.7364 0.0374 0.8947 L = 12.8778 0 0 0 -0.7978 0 0 0 2.9200 Java using Jama Library [[0.8275575078346545, -0.3493113857121139,0.24597790205308678], [-0.5601335729999509,-0.5809634522691761,-0.5159207870175849], [-0.037402561741212,-0.7379374514853343,1.144995023469712]] [[-0.7977988158677061,0.0, 0.0], [0.0, 12.877769427129202, 0.0], [0.0, 0.0,2.9200293887385067]] – saha Mar 27 '14 at 16:37
  • I took the liberty of incorporating these results in your question and formatting them as code for readability. Can you also show how you're initializing the `ideM` value in the Java code? – Andrew Janke Mar 28 '14 at 16:01
  • For what it's worth, I downloaded JAMA 1.0.3 and can reproduce your exact results with it and Matlab R2014a. But I don't know what's causing them. – Andrew Janke Mar 28 '14 at 16:17

1 Answers1

0

Well, for some reason Jama is incorrect (columns don't have norm of 1). The reordering and change of sign is normal (you're just getting orthogonal vectors that map to eigenval * themselves). You could try normalizing the columns or using jlapack.

user3970006
  • 151
  • 1