LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

eigenvalues and vectors

plots.vi and maha_dist.vi are still missing,

also lots of broken wires in pca.vi

 

one thing i saw immediately .. it's mostly cosmetic, but if you want to have an array [0,1,2,...,n] you just use the 'i' in the for loop, that does exactly what you try to do with  +1 and shift register. to have your array start with 1 instead of 0, either have the +1 in the for loop, or use a "Array Subset" or "Split Array" starting at index 1.

 


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 11 of 27
(1,016 Views)

Please find the updated attachment. 

0 Kudos
Message 12 of 27
(1,011 Views)

Please reply...

0 Kudos
Message 13 of 27
(999 Views)

I ran your code "pca.vi".  I assume you know you didn't wire any of the outputs, so you might not know that the first computation (for "Normal") gives Error -20068, "Input parameters has at least one element that is Inf, NaN, DBL_MAX, or DBL_MIN".  The other two computations do give numbers, don't know what to make of them ...

 

Since you seem to be worried about whether or not you are able to compute Eigenvalues and Eigenvectors from your data, why don't you create a small (10 x 10?  3 x 3?) set of data whose EigenThings you know and see if LabVIEW (and/or Matlab) gives you the expected results.

 

Bob Schor

0 Kudos
Message 14 of 27
(984 Views)

Hmm.  I decided to try what I suggested (take known data and see if LabVIEW computes correctly) myself.  I've not played with these kinds of data analysis functions in LabVIEW (I've not done much with LabVIEW's Matrix types), so it was a "learning experience".

 

Here's what I did:

  • Generated 5000 points with X, Y normally distributed, N(0, 1).
  • Scaled X by 4.  Rotated the sample by 30°.
  • The largest Eigenvalue should be the variance along the direction of maximum spread, and the corresponding Eigenvector should point in this direction.  This suggests that the Eigenvalues should be 16 (variance of N(0, 4)) and 1, with the Eigenvectors pointing at 30° and 120°.
  • Computed Covariance Matrix had main diagonals of 11.8 and 4.6, with off-diagonals of 6.25.
  • The computed Eigenvalues were 15.4 and 0.99.  The larger Eigenvector had components of 0.865 and 0.502, reasonably close to cos(30°) and sin(30°).

My conclusion is that LabVIEW's computation is likely to be mathematically correct.  Whether or not you are doing "the math correctly" or not, I'm not sure.  I will tell you that my code has no explicit square-root function in it.  If I had to guess, I'd guess you are not correctly computing the covariance matrix.  [Could you have gotten "correlation" and "covariance" mixed up?  Is that where the square root comes in?].

 

Bob Schor

0 Kudos
Message 15 of 27
(976 Views)

Actually, I have named it cov_mat.vi, but it is actually a correlation matrix. 

0 Kudos
Message 16 of 27
(983 Views)