| 1 | #cxx . . $ `<file>/dwsys/Eigen.h`/ifndef _Eigen_h_cxx . . $ `dwsys/Eigen.h:2:9`! |
| 2 | #define _Eigen_h_cxx . . $ `dwsys/Eigen.h:2:9`! |
| 3 | /* Eigen.h |
| 4 | * |
| 5 | * Copyright (C) 1993-2020, 2026 David Weenink |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | Eigen represents the eigenvalues and eigenvectors of a square matrix. |
| 23 | If the matrix is symmetric, the eigenvalues and corresponding eigenvectors |
| 24 | are real and sorted in descending order. |
| 25 | If the square matrix is not symmetric than some of the eigenvalues and |
| 26 | eigenvectors are complex. The complex eigenvalues always occur in pairs |
| 27 | a + i b and a - i b, where the eigenvalue with the positive imaginary part always |
| 28 | occurs before the other one in the list. |
| 29 | */ |
| 30 | |
| 31 | #include "Collection.h"cxx . . $ `<file>/sys/Collection.h`/ |
| 32 | |
| 33 | #include "Eigen_def.h"cxx . . $ `<file>/dwsys/Eigen_def.h`/ |
| 34 | #include "Graphics.h"cxx . . $ `<file>/sys/Graphics.h`/ |
| 35 | |
| 36 | #include "MAT_numerics.h"cxx . . $ `<file>/dwsys/MAT_numerics.h`/ |
| 37 | |
| 38 | void Eigen_initcxx . . $ Eigen_init(d09977d678f89afb). (Eigencxx . . $ Eigen# me, integercxx . . $ integer# numberOfEigenvalues, integercxx . . $ integer# dimension); |
| 39 | |
| 40 | void Eigen_initImaginaryPartscxx . . $ Eigen_initImaginaryParts(7aec2e76393e670a). (Eigencxx . . $ Eigen# me); |
| 41 | |
| 42 | autoEigencxx . . $ autoEigen# Eigen_createcxx . . $ Eigen_create(ebc1ac52f95d7b0a). (integercxx . . $ integer# numberOfEigenvalues, integercxx . . $ integer# dimension); |
| 43 | |
| 44 | autoEigencxx . . $ autoEigen# Eigen_createFromSquareRootcxx . . $ Eigen_createFromSquareRoot(fd9b16eabee65c04). (constMATVUcxx . . $ constMATVU# const& mat, integercxx . . $ integer# numberOfEigenvalues, bool sortAscending); |
| 45 | |
| 46 | void Eigen_initFromSquareMATcxx . . $ Eigen_initFromSquareMAT(1293e822cba03a73). (Eigencxx . . $ Eigen# me, constMATVUcxx . . $ constMATVU# const& mat, kMAT_TYPEcxx . . $ kMAT_TYPE# matType, integercxx . . $ integer# numberOfEigenvalues, bool sortAscending); |
| 47 | autoEigencxx . . $ autoEigen# Eigen_createFromSquareMATcxx . . $ Eigen_createFromSquareMAT(4719edc02e5d652b). (constMATVUcxx . . $ constMATVU# const& mat, kMAT_TYPEcxx . . $ kMAT_TYPE# matType, integercxx . . $ integer# numberOfEigenvalues, bool sortAscending); |
| 48 | |
| 49 | |
| 50 | void Eigen_initFromSymmetricMatrixcxx . . $ Eigen_initFromSymmetricMatrix(d25591f125e21262). (Eigencxx . . $ Eigen# me, constMATVUcxx . . $ constMATVU# const& a); |
| 51 | |
| 52 | void Eigen_initFromSymmetricTridiagonalcxx . . $ Eigen_initFromSymmetricTridiagonal(7d9ca54267a99112). (Eigencxx . . $ Eigen# me, constVECcxx . . $ constVEC# const& diagonal, constVECcxx . . $ constVEC# const& offDiagonal, bool sortAscending); |
| 53 | |
| 54 | void Eigen_initFromSquareRootcxx . . $ Eigen_initFromSquareRoot(d25591f125e21262). (Eigencxx . . $ Eigen# me, constMATVUcxx . . $ constMATVU# const& a); |
| 55 | /* |
| 56 | Calculate eigenstructure for symmetric matrix A'A (e.g. covariance matrix), |
| 57 | when only A is given. |
| 58 | Precondition: numberOfRows > 1 |
| 59 | Method: SVD. |
| 60 | */ |
| 61 | |
| 62 | void Eigen_initFromSquareRootPaircxx . . $ Eigen_initFromSquareRootPair(4808493b01839aeb). (Eigencxx . . $ Eigen# me, constMATcxx . . $ constMAT# a, constMATcxx . . $ constMAT# b); |
| 63 | /* |
| 64 | Calculate eigenstructure for A'Ax - lambda B'Bx = 0 |
| 65 | Preconditions: numberOfRows >= numberOfColumns && |
| 66 | numberOfRows_b >= numberOfColumns |
| 67 | Method: Generalized SVD. |
| 68 | */ |
| 69 | |
| 70 | integercxx . . $ integer# Eigen_getNumberOfEigenvectorscxx . . $ Eigen_getNumberOfEigenvectors(4ba876ea4b138ca4). (Eigencxx . . $ Eigen# me); |
| 71 | |
| 72 | integercxx . . $ integer# Eigen_getDimensionOfComponentscxx . . $ Eigen_getDimensionOfComponents(4ba876ea4b138ca4). (Eigencxx . . $ Eigen# me); |
| 73 | |
| 74 | double Eigen_getCumulativeContributionOfComponentscxx . . $ Eigen_getCumulativeContributionOfComponents(5b68a836636b7080). (Eigencxx . . $ Eigen# me, integercxx . . $ integer# from, integercxx . . $ integer# to); |
| 75 | |
| 76 | integercxx . . $ integer# Eigen_getDimensionOfFractioncxx . . $ Eigen_getDimensionOfFraction(2f2a020c08dd81f2). (Eigencxx . . $ Eigen# me, double fraction); |
| 77 | |
| 78 | double Eigen_getEigenvectorElementcxx . . $ Eigen_getEigenvectorElement(5b68a836636b7080). (Eigencxx . . $ Eigen# me, integercxx . . $ integer# ivec, integercxx . . $ integer# element); |
| 79 | |
| 80 | autoVECcxx . . $ autoVEC# Eigen_listEigenvaluescxx . . $ Eigen_listEigenvalues(68f7616e764b779e). (Eigencxx . . $ Eigen# me); |
| 81 | autoVECcxx . . $ autoVEC# Eigen_listEigenvalues_imagcxx . . $ Eigen_listEigenvalues_imag(68f7616e764b779e). (Eigencxx . . $ Eigen# me); |
| 82 | |
| 83 | autoVECcxx . . $ autoVEC# Eigen_getEigenvectorcxx . . $ Eigen_getEigenvector(aa44484401334427). (Eigencxx . . $ Eigen# me, integercxx . . $ integer# ivec); |
| 84 | autoVECcxx . . $ autoVEC# Eigen_getEigenvector_imagcxx . . $ Eigen_getEigenvector_imag(aa44484401334427). (Eigencxx . . $ Eigen# me, integercxx . . $ integer# ivec); |
| 85 | |
| 86 | double Eigen_getSumOfEigenvaluescxx . . $ Eigen_getSumOfEigenvalues(5b68a836636b7080). (Eigencxx . . $ Eigen# me, integercxx . . $ integer# from, integercxx . . $ integer# to); |
| 87 | |
| 88 | inline bool Eigen_areAllEigenvaluesRealcxx . . $ Eigen_areAllEigenvaluesReal(8cec1f7a2ffa6bfe). (Eigencxx . . $ Eigen# me) { |
| 89 | return mycxx . . $ `melder/melder.h:44:9`! onlyRealscxx . . $ structEigen#onlyReals.; |
| 90 | } |
| 91 | |
| 92 | void Eigen_sortcxx . . $ Eigen_sort(9e50836beee83372). (Eigencxx . . $ Eigen# me, bool sortAscending); |
| 93 | /* |
| 94 | Sort eigenvalues and corresponding eigenvectors. |
| 95 | All eigenvalues have to be real! |
| 96 | */ |
| 97 | |
| 98 | void Eigen_sort_specialcxx . . $ Eigen_sort_special(9e50836beee83372). (Eigencxx . . $ Eigen# me, bool sortAscending); |
| 99 | /* |
| 100 | Precondition: eigenvalues are sorted. |
| 101 | Postcondition: eigenvalues are ascending or descending. |
| 102 | */ |
| 103 | |
| 104 | void Eigen_invertEigenvectorcxx . . $ Eigen_invertEigenvector(20f5168ab14c1e7c). (Eigencxx . . $ Eigen# me, integercxx . . $ integer# ivec); // TODO djmw complex? |
| 105 | |
| 106 | void Eigen_drawEigenvaluescxx . . $ Eigen_drawEigenvalues(1038ada8264edd96). (Eigencxx . . $ Eigen# me, Graphicscxx . . $ Graphics# g, integercxx . . $ integer# first, integercxx . . $ integer# last, double ymin, double ymax, |
| 107 | bool fractionOfTotal, bool cumulative, double size_mm, conststring32cxx . . $ conststring32# mark, bool garnish); |
| 108 | |
| 109 | void Eigen_drawEigenvectorcxx . . $ Eigen_drawEigenvector(50d21cc5f57583bf). (Eigencxx . . $ Eigen# me, Graphicscxx . . $ Graphics# g, integercxx . . $ integer# ivec, integercxx . . $ integer# first, integercxx . . $ integer# last, double minimum, double maximum, bool weigh, |
| 110 | double size_mm, conststring32cxx . . $ conststring32# mark, bool connect, char32cxx . . $ char32# **rowLabels, bool garnish); |
| 111 | /* |
| 112 | Draw eigenvector. When rowLabels != nullptr, draw row text labels on bottom axis. |
| 113 | */ |
| 114 | |
| 115 | /** |
| 116 | Adapt the sign of each eigenvector except the first |
| 117 | in such a way that it correlates positively with the first eigenvector. |
| 118 | */ |
| 119 | void Eigens_alignEigenvectorscxx . . $ Eigens_alignEigenvectors(456c3f38c2a515f1). (OrderedOfcxx . . $ OrderedOf#<structEigencxx . . $ structEigen#>* me); |
| 120 | |
| 121 | double Eigens_getAngleBetweenEigenplanes_degreescxx . . $ Eigens_getAngleBetweenEigenplanes_degrees(6a4ff6596c6f8a0). (Eigencxx . . $ Eigen# me, Eigencxx . . $ Eigen# thee); |
| 122 | /* |
| 123 | Get angle between the eigenplanes, spanned by the first two eigenvectors. |
| 124 | */ |
| 125 | |
| 126 | #endif /* _Eigen_h_ */ |
| 127 |