10 #ifndef EIGEN_ITERSCALING_H
11 #define EIGEN_ITERSCALING_H
13 #include "./InternalHeaderCheck.h"
49 template<
typename MatrixType_>
53 typedef MatrixType_ MatrixType;
54 typedef typename MatrixType::Scalar Scalar;
55 typedef typename MatrixType::Index Index;
80 eigen_assert((m>0 && m == n) &&
"Please give a non - empty matrix");
89 double EpsRow = 1.0, EpsCol = 1.0;
95 for (
int k=0; k<m_matrix.outerSize(); ++k)
97 for (
typename MatrixType::InnerIterator it(m_matrix, k); it; ++it)
99 if ( Dr(it.row()) <
abs(it.value()) )
100 Dr(it.row()) =
abs(it.value());
102 if ( Dc(it.col()) <
abs(it.value()) )
103 Dc(it.col()) =
abs(it.value());
106 for (
int i = 0; i < m; ++i)
108 Dr(i) = std::sqrt(Dr(i));
110 for (
int i = 0; i < n; ++i)
112 Dc(i) = std::sqrt(Dc(i));
115 for (
int i = 0; i < m; ++i)
119 for (
int i = 0; i < n; ++i)
125 for (
int k=0; k<m_matrix.outerSize(); ++k)
127 for (
typename MatrixType::InnerIterator it(m_matrix, k); it; ++it)
129 it.valueRef() = it.value()/( Dr(it.row()) * Dc(it.col()) );
131 if ( DrRes(it.row()) <
abs(it.value()) )
132 DrRes(it.row()) =
abs(it.value());
134 if ( DcRes(it.col()) <
abs(it.value()) )
135 DcRes(it.col()) =
abs(it.value());
138 DrRes.array() = (1-DrRes.array()).
abs();
139 EpsRow = DrRes.maxCoeff();
140 DcRes.array() = (1-DcRes.array()).
abs();
141 EpsCol = DcRes.maxCoeff();
143 }
while ( (EpsRow >m_tol || EpsCol > m_tol) && (its < m_maxits) );
144 m_isInitialized =
true;
183 m_isInitialized =
false;
188 bool m_isInitialized;
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: Scaling.h:51
void setTolerance(double tol)
Definition: Scaling.h:172
void compute(const MatrixType &mat)
Definition: Scaling.h:75
void computeRef(MatrixType &mat)
Definition: Scaling.h:151
VectorXd & LeftScaling()
Definition: Scaling.h:158
VectorXd & RightScaling()
Definition: Scaling.h:165
Derived & setOnes(Index size)
void resize(Index rows, Index cols)
Derived & setZero(Index size)
Matrix< double, Dynamic, 1 > VectorXd
Namespace containing all symbols from the Eigen library.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)