Classes | |
class | op_pinv |
Functions | |
template<typename eT > | |
static void | op_pinv::direct_pinv (Mat< eT > &out, const Mat< eT > &X, eT tol) |
template<typename T > | |
void | op_pinv::direct_pinv (Mat< std::complex< T > > &out, const Mat< std::complex< T > > &A, T tol) |
template<typename T1 > | |
static void | op_pinv::apply (Mat< typename T1::pod_type > &out, const Op< T1, op_pinv > &in) |
template<typename T1 > | |
static void | op_pinv::apply (Mat< std::complex< typename T1::pod_type > > &out, const Op< T1, op_pinv > &in) |
void op_pinv::direct_pinv | ( | Mat< eT > & | out, | |
const Mat< eT > & | X, | |||
eT | tol | |||
) | [inline, static, inherited] |
Definition at line 27 of file op_pinv_meat.hpp.
References Mat< eT >::cols(), diagmat(), op_eps::direct_eps(), max(), Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, Col< eT >::rows(), svd(), trans(), and Mat< eT >::zeros().
Referenced by apply().
00028 { 00029 arma_extra_debug_sigprint(); 00030 00031 const u32 n_rows = A.n_rows; 00032 const u32 n_cols = A.n_cols; 00033 00034 // SVD decomposition 00035 Mat<eT> U; 00036 Col<eT> s; 00037 Mat<eT> V; 00038 00039 (n_cols > n_rows) ? svd(U,s,V,trans(A)) : svd(U,s,V,A); 00040 00041 // set tolerance to default if it hasn't been specified as an argument 00042 if(tol == eT(0)) 00043 { 00044 tol = (std::max)(n_rows,n_cols) * op_eps::direct_eps(max(s)); 00045 } 00046 00047 // count non zero valued elements in s 00048 u32 count = 0; 00049 for(u32 i = 0; i < s.n_elem; ++i) 00050 { 00051 if(s[i] > tol) 00052 { 00053 ++count; 00054 } 00055 } 00056 00057 00058 if(count != 0) 00059 { 00060 // reduce the length of s in order to contain only the values above tolerance 00061 s = s.rows(0,count-1); 00062 00063 // set the elements of s equal to their reciprocals 00064 s = eT(1) / s; 00065 00066 if(A.n_cols <= A.n_rows) 00067 { 00068 out = V.cols(0,count-1) * diagmat(s) * trans(U.cols(0,count-1)); 00069 } 00070 else 00071 { 00072 out = U.cols(0,count-1) * diagmat(s) * trans(V.cols(0,count-1)); 00073 } 00074 } 00075 else 00076 { 00077 out.zeros(n_cols, n_rows); 00078 } 00079 }
void op_pinv::direct_pinv | ( | Mat< std::complex< T > > & | out, | |
const Mat< std::complex< T > > & | A, | |||
T | tol | |||
) | [inline, inherited] |
Definition at line 86 of file op_pinv_meat.hpp.
References Mat< eT >::cols(), diagmat(), op_eps::direct_eps(), htrans(), max(), Mat< eT >::n_elem, Col< eT >::rows(), and svd().
00087 { 00088 arma_extra_debug_sigprint(); 00089 00090 const u32 n_rows = A.n_rows; 00091 const u32 n_cols = A.n_cols; 00092 00093 typedef typename std::complex<T> eT; 00094 00095 // SVD decomposition 00096 Mat<eT> U; 00097 Col< T> s; 00098 Mat<eT> V; 00099 00100 (n_cols > n_rows) ? svd(U,s,V,htrans(A)) : svd(U,s,V,A); 00101 00102 // set tolerance to default if it hasn't been specified as an argument 00103 if(tol == T(0)) 00104 { 00105 tol = (std::max)(n_rows,n_cols) * op_eps::direct_eps(max(s)); 00106 } 00107 00108 00109 // count non zero valued elements in s 00110 u32 count = 0; 00111 for(u32 i = 0; i < s.n_elem; ++i) 00112 { 00113 if(s[i] > tol) 00114 { 00115 ++count; 00116 } 00117 } 00118 00119 if(count != 0) 00120 { 00121 // reduce the length of s in order to contain only the values above tolerance 00122 s = s.rows(0,count-1); 00123 00124 // set the elements of s equal to their reciprocals 00125 s = T(1) / s; 00126 00127 if(n_rows >= n_cols) 00128 { 00129 out = V.cols(0,count-1) * diagmat(s) * htrans(U.cols(0,count-1)); 00130 } 00131 else 00132 { 00133 out = U.cols(0,count-1) * diagmat(s) * htrans(V.cols(0,count-1)); 00134 } 00135 } 00136 else 00137 { 00138 out.zeros(n_cols, n_rows); 00139 } 00140 }
void op_pinv::apply | ( | Mat< typename T1::pod_type > & | out, | |
const Op< T1, op_pinv > & | in | |||
) | [inline, static, inherited] |
Definition at line 147 of file op_pinv_meat.hpp.
References Op< T1, op_type >::aux, direct_pinv(), and Op< T1, op_type >::m.
00148 { 00149 arma_extra_debug_sigprint(); 00150 00151 typedef typename T1::pod_type eT; 00152 00153 const eT tol = in.aux; 00154 00155 arma_debug_check((tol < eT(0)), "pinv(): tol must be >= 0"); 00156 00157 const unwrap_check<T1> tmp(in.m, out); 00158 const Mat<eT>& A = tmp.M; 00159 00160 op_pinv::direct_pinv(out, A, tol); 00161 }
void op_pinv::apply | ( | Mat< std::complex< typename T1::pod_type > > & | out, | |
const Op< T1, op_pinv > & | in | |||
) | [inline, static, inherited] |
Definition at line 168 of file op_pinv_meat.hpp.
References Op< T1, op_type >::aux, direct_pinv(), and Op< T1, op_type >::m.
00169 { 00170 arma_extra_debug_sigprint(); 00171 00172 typedef typename T1::pod_type T; 00173 00174 typedef typename std::complex<typename T1::pod_type> eT; 00175 00176 const T tol = in.aux.real(); 00177 00178 arma_debug_check((tol < T(0)), "pinv(): tol must be >= 0"); 00179 00180 const unwrap_check<T1> tmp(in.m, out); 00181 const Mat<eT>& A = tmp.M; 00182 00183 op_pinv::direct_pinv(out, A, tol); 00184 }