test_PCA.praat 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # test_PCA.praat
  2. # djmw 20110525
  3. printline test_PCA
  4. # 5 points,
  5. # p1, p2,p3 on a line throug the origin with an angle of pi/6 with variance 6
  6. # p4, p2, p5 orthogonal with variance 2
  7. #
  8. tol = 1e-12
  9. npoints = 5
  10. t = Create TableOfReal... t npoints 2
  11. Set value... 1 1 -sqrt(2)
  12. Set value... 1 2 -1
  13. Set value... 2 1 0
  14. Set value... 2 2 0
  15. Set value... 3 1 sqrt(2)
  16. Set value... 3 2 1
  17. Set value... 4 1 -1/sqrt(3)
  18. Set value... 4 2 sqrt(2/3)
  19. Set value... 5 1 1/sqrt(3)
  20. Set value... 5 2 -sqrt(2/3)
  21. pca = To PCA
  22. printline ... eigenvalues
  23. ss1 = Get eigenvalue... 1
  24. ss2 = Get eigenvalue... 2
  25. assert abs(ss1 - 6/(npoints-1)) < tol
  26. assert abs(ss2 - 2/(npoints-1)) < tol
  27. printline ... fraction variance accounted for
  28. fvaf = Get fraction variance accounted for... 1 1
  29. assert abs(fvaf - 6/8)< tol
  30. printline ... centroid at (0,)
  31. printline ...eigenvectors othogonal
  32. ev11 = Get eigenvector element... 1 1
  33. ev12 = Get eigenvector element... 1 2
  34. ev21 = Get eigenvector element... 2 1
  35. ev22 = Get eigenvector element... 2 2
  36. inprod = ev11*ev21+ev12*ev22
  37. assert abs(inprod) < tol
  38. plus t
  39. Remove
  40. printline test_PCA OK