Eigen_and_Procrustes.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Eigen_and_Procrustes.cpp
  2. * Copyright (C) 2004-2018 David Weenink
  3. *
  4. * This code is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or (at
  7. * your option) any later version.
  8. *
  9. * This code is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /* djmw 2004 Initial version */
  18. #include "Eigen_and_Procrustes.h"
  19. #include "Configuration_and_Procrustes.h"
  20. #include "NUM2.h"
  21. autoProcrustes Eigens_to_Procrustes (Eigen me, Eigen thee, integer evec_from, integer evec_to) {
  22. try {
  23. integer nvectors = evec_to - evec_from + 1;
  24. integer nmin = my numberOfEigenvalues < thy numberOfEigenvalues ? my numberOfEigenvalues : thy numberOfEigenvalues;
  25. Melder_require (my dimension == thy dimension, U"The eigenvectors should have the same dimension.");
  26. Melder_require (evec_from <= evec_to && evec_from > 0 && evec_to <= nmin, U"Eigenvector range is too large.");
  27. autoMAT x = MATraw (my dimension, nvectors);
  28. autoMAT y = MATraw (my dimension, nvectors);
  29. for (integer j = 1; j <= nvectors; j ++) {
  30. for (integer i = 1; i <= my dimension; i ++) {
  31. x[i] [j] = my eigenvectors [evec_from + j - 1] [i];
  32. y[i] [j] = thy eigenvectors [evec_from + j - 1] [i];
  33. }
  34. }
  35. autoProcrustes him = Procrustes_create (nvectors);
  36. autoMAT rotation;
  37. NUMprocrustes (x.get(), y.get(), & rotation, nullptr, nullptr);
  38. matrixcopy_preallocated (his r.get(), rotation.get());
  39. return him;
  40. } catch (MelderError) {
  41. Melder_throw (U"Procrustes not created from Eigens.");
  42. }
  43. }
  44. /* End of file Eigen_and_Procrustes.cpp */