10 #ifndef EIGEN_ITERSCALING_H 11 #define EIGEN_ITERSCALING_H 14 #include "./InternalHeaderCheck.h" 50 template <
typename MatrixType_>
53 typedef MatrixType_ MatrixType;
54 typedef typename MatrixType::Scalar Scalar;
55 typedef typename MatrixType::Index Index;
78 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) {
96 for (
typename MatrixType::InnerIterator it(m_matrix, k); it; ++it) {
97 if (Dr(it.row()) <
abs(it.value())) Dr(it.row()) =
abs(it.value());
99 if (Dc(it.col()) <
abs(it.value())) Dc(it.col()) =
abs(it.value());
102 for (
int i = 0; i < m; ++i) {
103 Dr(i) = std::sqrt(Dr(i));
105 for (
int i = 0; i < n; ++i) {
106 Dc(i) = std::sqrt(Dc(i));
109 for (
int i = 0; i < m; ++i) {
112 for (
int i = 0; i < n; ++i) {
118 for (
int k = 0; k < m_matrix.outerSize(); ++k) {
119 for (
typename MatrixType::InnerIterator it(m_matrix, k); it; ++it) {
120 it.valueRef() = it.value() / (Dr(it.row()) * Dc(it.col()));
122 if (DrRes(it.row()) <
abs(it.value())) DrRes(it.row()) =
abs(it.value());
124 if (DcRes(it.col()) <
abs(it.value())) DcRes(it.col()) =
abs(it.value());
127 DrRes.array() = (1 - DrRes.array()).
abs();
128 EpsRow = DrRes.maxCoeff();
129 DcRes.array() = (1 - DcRes.array()).
abs();
130 EpsCol = DcRes.maxCoeff();
132 }
while ((EpsRow > m_tol || EpsCol > m_tol) && (its < m_maxits));
133 m_isInitialized =
true;
160 m_isInitialized =
false;
165 bool m_isInitialized;
constexpr void resize(Index rows, Index cols)
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: Scaling.h:51
void setTolerance(double tol)
Definition: Scaling.h:154
Namespace containing all symbols from the Eigen library.
void computeRef(MatrixType &mat)
Definition: Scaling.h:140
VectorXd & RightScaling()
Definition: Scaling.h:150
Derived & setOnes(Index size)
Derived & setZero(Index size)
Matrix< double, Dynamic, 1 > VectorXd
void compute(const MatrixType &mat)
Definition: Scaling.h:74
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
VectorXd & LeftScaling()
Definition: Scaling.h:146