Warning, file /include/eigen3/unsupported/Eigen/src/IterativeSolvers/Scaling.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_ITERSCALING_H
0011 #define EIGEN_ITERSCALING_H
0012
0013 namespace Eigen {
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 template<typename _MatrixType>
0048 class IterScaling
0049 {
0050 public:
0051 typedef _MatrixType MatrixType;
0052 typedef typename MatrixType::Scalar Scalar;
0053 typedef typename MatrixType::Index Index;
0054
0055 public:
0056 IterScaling() { init(); }
0057
0058 IterScaling(const MatrixType& matrix)
0059 {
0060 init();
0061 compute(matrix);
0062 }
0063
0064 ~IterScaling() { }
0065
0066
0067
0068
0069
0070
0071
0072
0073 void compute (const MatrixType& mat)
0074 {
0075 using std::abs;
0076 int m = mat.rows();
0077 int n = mat.cols();
0078 eigen_assert((m>0 && m == n) && "Please give a non - empty matrix");
0079 m_left.resize(m);
0080 m_right.resize(n);
0081 m_left.setOnes();
0082 m_right.setOnes();
0083 m_matrix = mat;
0084 VectorXd Dr, Dc, DrRes, DcRes;
0085 Dr.resize(m); Dc.resize(n);
0086 DrRes.resize(m); DcRes.resize(n);
0087 double EpsRow = 1.0, EpsCol = 1.0;
0088 int its = 0;
0089 do
0090 {
0091
0092 Dr.setZero(); Dc.setZero();
0093 for (int k=0; k<m_matrix.outerSize(); ++k)
0094 {
0095 for (typename MatrixType::InnerIterator it(m_matrix, k); it; ++it)
0096 {
0097 if ( Dr(it.row()) < abs(it.value()) )
0098 Dr(it.row()) = abs(it.value());
0099
0100 if ( Dc(it.col()) < abs(it.value()) )
0101 Dc(it.col()) = abs(it.value());
0102 }
0103 }
0104 for (int i = 0; i < m; ++i)
0105 {
0106 Dr(i) = std::sqrt(Dr(i));
0107 }
0108 for (int i = 0; i < n; ++i)
0109 {
0110 Dc(i) = std::sqrt(Dc(i));
0111 }
0112
0113 for (int i = 0; i < m; ++i)
0114 {
0115 m_left(i) /= Dr(i);
0116 }
0117 for (int i = 0; i < n; ++i)
0118 {
0119 m_right(i) /= Dc(i);
0120 }
0121
0122 DrRes.setZero(); DcRes.setZero();
0123 for (int k=0; k<m_matrix.outerSize(); ++k)
0124 {
0125 for (typename MatrixType::InnerIterator it(m_matrix, k); it; ++it)
0126 {
0127 it.valueRef() = it.value()/( Dr(it.row()) * Dc(it.col()) );
0128
0129 if ( DrRes(it.row()) < abs(it.value()) )
0130 DrRes(it.row()) = abs(it.value());
0131
0132 if ( DcRes(it.col()) < abs(it.value()) )
0133 DcRes(it.col()) = abs(it.value());
0134 }
0135 }
0136 DrRes.array() = (1-DrRes.array()).abs();
0137 EpsRow = DrRes.maxCoeff();
0138 DcRes.array() = (1-DcRes.array()).abs();
0139 EpsCol = DcRes.maxCoeff();
0140 its++;
0141 }while ( (EpsRow >m_tol || EpsCol > m_tol) && (its < m_maxits) );
0142 m_isInitialized = true;
0143 }
0144
0145
0146
0147
0148
0149 void computeRef (MatrixType& mat)
0150 {
0151 compute (mat);
0152 mat = m_matrix;
0153 }
0154
0155
0156 VectorXd& LeftScaling()
0157 {
0158 return m_left;
0159 }
0160
0161
0162
0163 VectorXd& RightScaling()
0164 {
0165 return m_right;
0166 }
0167
0168
0169
0170 void setTolerance(double tol)
0171 {
0172 m_tol = tol;
0173 }
0174
0175 protected:
0176
0177 void init()
0178 {
0179 m_tol = 1e-10;
0180 m_maxits = 5;
0181 m_isInitialized = false;
0182 }
0183
0184 MatrixType m_matrix;
0185 mutable ComputationInfo m_info;
0186 bool m_isInitialized;
0187 VectorXd m_left;
0188 VectorXd m_right;
0189 double m_tol;
0190 int m_maxits;
0191 };
0192 }
0193 #endif