MAT_numerics.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. /* MAT_numerics.h
  3. *
  4. * Copyright (C) 2018 David Weenink
  5. *
  6. * This code is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This code is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. * See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "melder.h"
  20. void MAT_getEigenSystemFromSymmetricMatrix (constMAT a, autoMAT *out_eigenvectors, autoVEC *out_eigenvalues, bool sortAscending);
  21. /*
  22. Calculates the eigenvectors and eigenvalues of a symmetric matrix;
  23. Input:
  24. a, a symmetric matrix of size nrow x nrow (a.ncol == a.nrow)
  25. only the upper-half of the matrix is used in the calculation
  26. sortAscending if true eigenvalues (and corresponding eigenvectors) are sorted ascending
  27. Output:
  28. if(out_eigenvalues) eigenvalues sorted
  29. if(out_eigenvectors) eigenvectors corresponding to the eigenvalues, stored as row-wise vectors.
  30. */
  31. void MAT_getEigenSystemFromSymmetricMatrix_inplace (MAT inout_a, bool wantEigenvectors, VEC inout_eigenvalues, bool sortAscending);
  32. /*
  33. Input:
  34. inout_a, a symmetric a.ncol x a.ncol matrix
  35. only the upper-half of the matrix is used in the calculation
  36. inout_eigenvalues, a vector of size ncol
  37. wantEigenvectors, true if you want eigenvectors calculated
  38. sortAscending if true eigenvalues (and corresponding eigenvectors) are sorted ascending
  39. Output:
  40. inout_a, if (wantEigenvectors) eigenvectors, stored row-wise
  41. inout_eigenvalues, eigenvalues sorted from large to small
  42. */
  43. void MAT_getPrincipalComponentsOfSymmetricMatrix_preallocated (MAT pc, constMAT a, integer nComponents);
  44. /*
  45. Input:
  46. a, a symmetric nrow x nrow matrix
  47. only the upper-half of the matrix is used in the calculation
  48. nComponents, the number of components to determine (1 <= nComponents <= a.nrow)
  49. inout_pc, a a.nrow x nComponents matrix
  50. Output:
  51. inout_pc, the principal components stored column-wise
  52. */
  53. void MAT_getEigenSystemFromGeneralMatrix (constMAT a, autoMAT *out_lefteigenvectors, autoMAT *out_righteigenvectors, autoVEC *out_eigenvalues_re, autoVEC *out_eigenvalues_im);
  54. /* no standard sorting with complex numbers.
  55. Compute eigenvalues of general nxn matrix with optionally the left/right eigenvectors.
  56. There is no standard sorting with complex numbers.
  57. Input:
  58. Output:
  59. out_eigenvalues_re, out_eigenvalues_im
  60. the real and imaginary parts of the eigenvalues.
  61. Complex conjugate pairs of eigenvalues appear consecutively
  62. with the eigenvalue having the positive imaginary part first.
  63. out_righteigenvectors, out_lefteigenvectors:
  64. the left and right eigenvectors (stored row-wise!, compressed)
  65. if the j-th eigenvalue is real the eigenvector is real and in row j.
  66. if j and j+1 form a complex conjugate pair, the two eigenvectors are
  67. complex conjugates, whose real part is in j and its imaginary part in j+1.
  68. */
  69. void MAT_eigenvectors_decompress (constMAT eigenvectors, constVEC eigenvalues_re, constVEC eigenvalues_im, autoMAT *out_eigenvectors_reim);
  70. /*
  71. Decompresses each eigenvector row into two consecutive columns (real and imaginary part)
  72. */
  73. /* End of file MAT_numerics.h */