1 | /// \ingroup newmat |
---|
2 | ///@{ |
---|
3 | |
---|
4 | /// \file newmatap.h |
---|
5 | /// Definition file for advanced matrix functions. |
---|
6 | |
---|
7 | // Copyright (C) 1991,2,3,4,8: R B Davies |
---|
8 | |
---|
9 | #ifndef NEWMATAP_LIB |
---|
10 | #define NEWMATAP_LIB 0 |
---|
11 | |
---|
12 | #include "newmat.h" |
---|
13 | |
---|
14 | #ifdef use_namespace |
---|
15 | namespace NEWMAT { |
---|
16 | #endif |
---|
17 | |
---|
18 | |
---|
19 | // ************************** applications *****************************/ |
---|
20 | |
---|
21 | |
---|
22 | void QRZT(Matrix&, LowerTriangularMatrix&); |
---|
23 | |
---|
24 | void QRZT(const Matrix&, Matrix&, Matrix&); |
---|
25 | |
---|
26 | void QRZ(Matrix&, UpperTriangularMatrix&); |
---|
27 | |
---|
28 | void QRZ(const Matrix&, Matrix&, Matrix&); |
---|
29 | |
---|
30 | inline void HHDecompose(Matrix& X, LowerTriangularMatrix& L) |
---|
31 | { QRZT(X,L); } |
---|
32 | |
---|
33 | inline void HHDecompose(const Matrix& X, Matrix& Y, Matrix& M) |
---|
34 | { QRZT(X, Y, M); } |
---|
35 | |
---|
36 | void updateQRZT(Matrix& X, LowerTriangularMatrix& L); |
---|
37 | |
---|
38 | void updateQRZ(Matrix& X, UpperTriangularMatrix& U); |
---|
39 | |
---|
40 | inline void UpdateQRZT(Matrix& X, LowerTriangularMatrix& L) |
---|
41 | { updateQRZT(X, L); } |
---|
42 | |
---|
43 | inline void UpdateQRZ(Matrix& X, UpperTriangularMatrix& U) |
---|
44 | { updateQRZ(X, U); } |
---|
45 | |
---|
46 | // Matrix A's first n columns are orthonormal |
---|
47 | // so A.Columns(1,n).t() * A.Columns(1,n) is the identity matrix. |
---|
48 | // Fill out the remaining columns of A to make them orthonormal |
---|
49 | // so A.t() * A is the identity matrix |
---|
50 | void extend_orthonormal(Matrix& A, int n); |
---|
51 | |
---|
52 | |
---|
53 | ReturnMatrix Cholesky(const SymmetricMatrix&); |
---|
54 | |
---|
55 | ReturnMatrix Cholesky(const SymmetricBandMatrix&); |
---|
56 | |
---|
57 | |
---|
58 | // produces the Cholesky decomposition of A + x.t() * x where A = chol.t() * chol |
---|
59 | // and x is a RowVector |
---|
60 | void update_Cholesky(UpperTriangularMatrix& chol, RowVector x); |
---|
61 | inline void UpdateCholesky(UpperTriangularMatrix& chol, const RowVector& x) |
---|
62 | { update_Cholesky(chol, x); } |
---|
63 | |
---|
64 | // produces the Cholesky decomposition of A - x.t() * x where A = chol.t() * chol |
---|
65 | // and x is a RowVector |
---|
66 | void downdate_Cholesky(UpperTriangularMatrix &chol, RowVector x); |
---|
67 | inline void DowndateCholesky(UpperTriangularMatrix &chol, const RowVector& x) |
---|
68 | { downdate_Cholesky(chol, x); } |
---|
69 | |
---|
70 | // a RIGHT circular shift of the rows and columns from |
---|
71 | // 1,...,k-1,k,k+1,...l,l+1,...,p to |
---|
72 | // 1,...,k-1,l,k,k+1,...l-1,l+1,...p |
---|
73 | void right_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l); |
---|
74 | inline void RightCircularUpdateCholesky(UpperTriangularMatrix &chol, |
---|
75 | int k, int l) { right_circular_update_Cholesky(chol, k, l); } |
---|
76 | |
---|
77 | // a LEFT circular shift of the rows and columns from |
---|
78 | // 1,...,k-1,k,k+1,...l,l+1,...,p to |
---|
79 | // 1,...,k-1,k+1,...l,k,l+1,...,p to |
---|
80 | void left_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l); |
---|
81 | inline void LeftCircularUpdateCholesky(UpperTriangularMatrix &chol, |
---|
82 | int k, int l) { left_circular_update_Cholesky(chol, k, l); } |
---|
83 | |
---|
84 | |
---|
85 | void SVD(const Matrix&, DiagonalMatrix&, Matrix&, Matrix&, |
---|
86 | bool=true, bool=true); |
---|
87 | |
---|
88 | void SVD(const Matrix&, DiagonalMatrix&); |
---|
89 | |
---|
90 | inline void SVD(const Matrix& A, DiagonalMatrix& D, Matrix& U, |
---|
91 | bool withU = true) { SVD(A, D, U, U, withU, false); } |
---|
92 | |
---|
93 | void SortSV(DiagonalMatrix& D, Matrix& U, bool ascending = false); |
---|
94 | |
---|
95 | void SortSV(DiagonalMatrix& D, Matrix& U, Matrix& V, bool ascending = false); |
---|
96 | |
---|
97 | void Jacobi(const SymmetricMatrix&, DiagonalMatrix&); |
---|
98 | |
---|
99 | void Jacobi(const SymmetricMatrix&, DiagonalMatrix&, SymmetricMatrix&); |
---|
100 | |
---|
101 | void Jacobi(const SymmetricMatrix&, DiagonalMatrix&, Matrix&); |
---|
102 | |
---|
103 | void Jacobi(const SymmetricMatrix&, DiagonalMatrix&, SymmetricMatrix&, |
---|
104 | Matrix&, bool=true); |
---|
105 | |
---|
106 | void eigenvalues(const SymmetricMatrix&, DiagonalMatrix&); |
---|
107 | |
---|
108 | void eigenvalues(const SymmetricMatrix&, DiagonalMatrix&, SymmetricMatrix&); |
---|
109 | |
---|
110 | void eigenvalues(const SymmetricMatrix&, DiagonalMatrix&, Matrix&); |
---|
111 | |
---|
112 | inline void EigenValues(const SymmetricMatrix& A, DiagonalMatrix& D) |
---|
113 | { eigenvalues(A, D); } |
---|
114 | |
---|
115 | inline void EigenValues(const SymmetricMatrix& A, DiagonalMatrix& D, |
---|
116 | SymmetricMatrix& S) { eigenvalues(A, D, S); } |
---|
117 | |
---|
118 | inline void EigenValues(const SymmetricMatrix& A, DiagonalMatrix& D, Matrix& V) |
---|
119 | { eigenvalues(A, D, V); } |
---|
120 | |
---|
121 | class SymmetricEigenAnalysis |
---|
122 | // not implemented yet |
---|
123 | { |
---|
124 | public: |
---|
125 | SymmetricEigenAnalysis(const SymmetricMatrix&); |
---|
126 | private: |
---|
127 | DiagonalMatrix diag; |
---|
128 | DiagonalMatrix offdiag; |
---|
129 | SymmetricMatrix backtransform; |
---|
130 | FREE_CHECK(SymmetricEigenAnalysis) |
---|
131 | }; |
---|
132 | |
---|
133 | void sort_ascending(GeneralMatrix&); |
---|
134 | |
---|
135 | void sort_descending(GeneralMatrix&); |
---|
136 | |
---|
137 | inline void SortAscending(GeneralMatrix& gm) { sort_ascending(gm); } |
---|
138 | |
---|
139 | inline void SortDescending(GeneralMatrix& gm) { sort_descending(gm); } |
---|
140 | |
---|
141 | /// Decide which fft method to use and carry out new fft function |
---|
142 | class FFT_Controller |
---|
143 | { |
---|
144 | public: |
---|
145 | static bool OnlyOldFFT; |
---|
146 | static bool ar_1d_ft (int PTS, Real* X, Real *Y); |
---|
147 | static bool CanFactor(int PTS); |
---|
148 | }; |
---|
149 | |
---|
150 | void FFT(const ColumnVector&, const ColumnVector&, |
---|
151 | ColumnVector&, ColumnVector&); |
---|
152 | |
---|
153 | void FFTI(const ColumnVector&, const ColumnVector&, |
---|
154 | ColumnVector&, ColumnVector&); |
---|
155 | |
---|
156 | void RealFFT(const ColumnVector&, ColumnVector&, ColumnVector&); |
---|
157 | |
---|
158 | void RealFFTI(const ColumnVector&, const ColumnVector&, ColumnVector&); |
---|
159 | |
---|
160 | void DCT_II(const ColumnVector&, ColumnVector&); |
---|
161 | |
---|
162 | void DCT_II_inverse(const ColumnVector&, ColumnVector&); |
---|
163 | |
---|
164 | void DST_II(const ColumnVector&, ColumnVector&); |
---|
165 | |
---|
166 | void DST_II_inverse(const ColumnVector&, ColumnVector&); |
---|
167 | |
---|
168 | void DCT(const ColumnVector&, ColumnVector&); |
---|
169 | |
---|
170 | void DCT_inverse(const ColumnVector&, ColumnVector&); |
---|
171 | |
---|
172 | void DST(const ColumnVector&, ColumnVector&); |
---|
173 | |
---|
174 | void DST_inverse(const ColumnVector&, ColumnVector&); |
---|
175 | |
---|
176 | void FFT2(const Matrix& U, const Matrix& V, Matrix& X, Matrix& Y); |
---|
177 | |
---|
178 | void FFT2I(const Matrix& U, const Matrix& V, Matrix& X, Matrix& Y); |
---|
179 | |
---|
180 | |
---|
181 | // This class is used by the new FFT program |
---|
182 | |
---|
183 | // Suppose an integer is expressed as a sequence of digits with each |
---|
184 | // digit having a different radix. |
---|
185 | // This class supposes we are counting with this multi-radix number |
---|
186 | // but also keeps track of the number with the digits (and radices) |
---|
187 | // reversed. |
---|
188 | // The integer starts at zero |
---|
189 | // operator++() increases it by 1 |
---|
190 | // Counter gives the number of increments |
---|
191 | // Reverse() gives the value with the digits in reverse order |
---|
192 | // Swap is true if reverse is less than counter |
---|
193 | // Finish is true when we have done a complete cycle and are back at zero |
---|
194 | |
---|
195 | class MultiRadixCounter |
---|
196 | { |
---|
197 | const SimpleIntArray& Radix; |
---|
198 | // radix of each digit |
---|
199 | // n-1 highest order, 0 lowest order |
---|
200 | SimpleIntArray& Value; // value of each digit |
---|
201 | const int n; // number of digits |
---|
202 | int reverse; // value when order of digits is reversed |
---|
203 | int product; // product of radices |
---|
204 | int counter; // counter |
---|
205 | bool finish; // true when we have gone over whole range |
---|
206 | public: |
---|
207 | MultiRadixCounter(int nx, const SimpleIntArray& rx, |
---|
208 | SimpleIntArray& vx); |
---|
209 | void operator++(); // increment the multi-radix counter |
---|
210 | bool Swap() const { return reverse < counter; } |
---|
211 | bool Finish() const { return finish; } |
---|
212 | int Reverse() const { return reverse; } |
---|
213 | int Counter() const { return counter; } |
---|
214 | }; |
---|
215 | |
---|
216 | // multiplication by Helmert matrix |
---|
217 | ReturnMatrix Helmert(int n, bool full=false); |
---|
218 | ReturnMatrix Helmert(const ColumnVector& X, bool full=false); |
---|
219 | ReturnMatrix Helmert(int n, int j, bool full=false); |
---|
220 | ReturnMatrix Helmert_transpose(const ColumnVector& Y, bool full=false); |
---|
221 | Real Helmert_transpose(const ColumnVector& Y, int j, bool full=false); |
---|
222 | ReturnMatrix Helmert(const Matrix& X, bool full=false); |
---|
223 | ReturnMatrix Helmert_transpose(const Matrix& Y, bool full=false); |
---|
224 | |
---|
225 | |
---|
226 | |
---|
227 | |
---|
228 | #ifdef use_namespace |
---|
229 | } |
---|
230 | #endif |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | #endif |
---|
235 | |
---|
236 | // body file: cholesky.cpp |
---|
237 | // body file: evalue.cpp |
---|
238 | // body file: fft.cpp |
---|
239 | // body file: hholder.cpp |
---|
240 | // body file: jacobi.cpp |
---|
241 | // body file: newfft.cpp |
---|
242 | // body file: sort.cpp |
---|
243 | // body file: svd.cpp |
---|
244 | // body file: nm_misc.cpp |
---|
245 | |
---|
246 | |
---|
247 | |
---|
248 | ///@} |
---|
249 | |
---|
250 | |
---|