36 #ifndef GMM_CONDITION_NUMBER_H__
37 #define GMM_CONDITION_NUMBER_H__
48 template <
typename T>
struct condition_number_work_type
50 template <>
struct condition_number_work_type<float>
51 {
typedef double type; };
52 template <>
struct condition_number_work_type<std::complex<float> >
53 {
typedef std::complex<double> type; };
65 template <
typename MAT>
66 typename number_traits<
typename
67 linalg_traits<MAT>::value_type>::magnitude_type
69 typename number_traits<
typename
70 linalg_traits<MAT>::value_type>::magnitude_type& emin,
71 typename number_traits<
typename
72 linalg_traits<MAT>::value_type>::magnitude_type& emax) {
73 typedef typename linalg_traits<MAT>::value_type T;
74 typedef typename number_traits<T>::magnitude_type R;
75 typedef typename condition_number_work_type<T>::type TW;
76 typedef typename number_traits<TW>::magnitude_type RW;
79 if (
sizeof(T) !=
sizeof(R) && gmm::abs(
gmm::lu_det(M)) == R(0))
80 return gmm::default_max(R());
82 size_type m = mat_nrows(M), n = mat_ncols(M);
84 std::vector<RW> eig(m+n);
86 if (m+n == 0)
return R(0);
88 dense_matrix<TW> A(m, m);
91 gmm::symmetric_qr_algorithm(A, eig);
94 dense_matrix<TW> B(m+n, m+n);
96 gmm::copy(M, sub_matrix(B, sub_interval(0, m),
98 gmm::symmetric_qr_algorithm(B, eig);
100 RW eminw = gmm::abs(eig[0]), emaxw = eminw;
101 for (size_type i = 1; i < eig.size(); ++i) {
102 RW e = gmm::abs(eig[i]);
103 eminw = std::min(eminw, e);
104 emaxw = std::max(emaxw, e);
106 emin = R(eminw); emax = R(emaxw);
107 if (eminw == RW(0))
return gmm::default_max(R());
108 RW c = emaxw / eminw;
110 if (c >= RW(gmm::default_max(R())))
return gmm::default_max(R());
114 template <
typename MAT>
115 typename number_traits<
typename
116 linalg_traits<MAT>::value_type>::magnitude_type
117 condition_number(
const MAT& M) {
118 typename number_traits<
typename
119 linalg_traits<MAT>::value_type>::magnitude_type emax, emin;
120 return condition_number(M, emin, emax);
123 template <
typename MAT>
124 typename number_traits<
typename
125 linalg_traits<MAT>::value_type>::magnitude_type
126 Frobenius_condition_number_sqr(
const MAT& M) {
127 typedef typename linalg_traits<MAT>::value_type T;
128 typedef typename number_traits<T>::magnitude_type R;
129 size_type m = mat_nrows(M), n = mat_ncols(M);
130 dense_matrix<T> B(std::min(m,n), std::min(m,n));
131 if (m < n)
mult(M,gmm::conjugated(M),B);
132 else mult(gmm::conjugated(M),M,B);
138 template <
typename MAT>
139 typename number_traits<
typename
140 linalg_traits<MAT>::value_type>::magnitude_type
141 Frobenius_condition_number(
const MAT& M)
142 {
return sqrt(Frobenius_condition_number_sqr(M)); }
146 template <
typename MAT>
147 typename number_traits<
typename
148 linalg_traits<MAT>::value_type>::magnitude_type
150 typename number_traits<
typename
151 linalg_traits<MAT>::value_type>::magnitude_type& emin,
152 typename number_traits<
typename
153 linalg_traits<MAT>::value_type>::magnitude_type& emax) {
157 template <
typename MAT>
158 typename number_traits<
typename
159 linalg_traits<MAT>::value_type>::magnitude_type
160 condest(
const MAT& M) {
161 typename number_traits<
typename
162 linalg_traits<MAT>::value_type>::magnitude_type emax, emin;
163 return condest(M, emin, emax);
void copy(const L1 &l1, L2 &l2)
*/
linalg_traits< M >::value_type mat_trace(const M &m)
Trace of a matrix.
void mult(const L1 &l1, const L2 &l2, L3 &l3)
*/
bool is_hermitian(const MAT &A, magnitude_of_linalg(MAT) tol=magnitude_of_linalg(MAT)(-1))
*/
number_traits< typename linalg_traits< MAT >::value_type >::magnitude_type condition_number(const MAT &M, typename number_traits< typename linalg_traits< MAT >::value_type >::magnitude_type &emin, typename number_traits< typename linalg_traits< MAT >::value_type >::magnitude_type &emax)
computation of the condition number of matrices (ratio of the extreme singular values).
number_traits< typename linalg_traits< MAT >::value_type >::magnitude_type condest(const MAT &M, typename number_traits< typename linalg_traits< MAT >::value_type >::magnitude_type &emin, typename number_traits< typename linalg_traits< MAT >::value_type >::magnitude_type &emax)
estimation of the condition number (TO BE DONE...)
conjugated_return< L >::return_type conjugated(const L &v)
return a conjugated view of the input matrix or vector.
linalg_traits< DenseMatrixLU >::value_type lu_det(const DenseMatrixLU &LU, const Pvector &pvector)
Compute the matrix determinant (via a LU factorization)
size_t size_type
used as the common size type in the library