10 #ifndef EIGEN_ITERSCALING_H 11 #define EIGEN_ITERSCALING_H 47 template<
typename _MatrixType>
51 typedef _MatrixType MatrixType;
52 typedef typename MatrixType::Scalar Scalar;
53 typedef typename MatrixType::Index Index;
78 eigen_assert((m>0 && m == n) &&
"Please give a non - empty matrix");
87 double EpsRow = 1.0, EpsCol = 1.0;
93 for (
int k=0; k<m_matrix.outerSize(); ++k)
95 for (
typename MatrixType::InnerIterator it(m_matrix, k); it; ++it)
97 if ( Dr(it.row()) <
abs(it.value()) )
98 Dr(it.row()) =
abs(it.value());
100 if ( Dc(it.col()) <
abs(it.value()) )
101 Dc(it.col()) =
abs(it.value());
104 for (
int i = 0; i < m; ++i)
106 Dr(i) = std::sqrt(Dr(i));
108 for (
int i = 0; i < n; ++i)
110 Dc(i) = std::sqrt(Dc(i));
113 for (
int i = 0; i < m; ++i)
117 for (
int i = 0; i < n; ++i)
123 for (
int k=0; k<m_matrix.outerSize(); ++k)
125 for (
typename MatrixType::InnerIterator it(m_matrix, k); it; ++it)
127 it.valueRef() = it.value()/( Dr(it.row()) * Dc(it.col()) );
129 if ( DrRes(it.row()) <
abs(it.value()) )
130 DrRes(it.row()) =
abs(it.value());
132 if ( DcRes(it.col()) <
abs(it.value()) )
133 DcRes(it.col()) =
abs(it.value());
136 DrRes.array() = (1-DrRes.array()).
abs();
137 EpsRow = DrRes.maxCoeff();
138 DcRes.array() = (1-DcRes.array()).
abs();
139 EpsCol = DcRes.maxCoeff();
141 }
while ( (EpsRow >m_tol || EpsCol > m_tol) && (its < m_maxits) );
142 m_isInitialized =
true;
181 m_isInitialized =
false;
186 bool m_isInitialized;
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: Scaling.h:48
Namespace containing all symbols from the Eigen library.
VectorXd & LeftScaling()
Definition: Scaling.h:156
void resize(Index rows, Index cols)
Derived & setOnes(Index size)
Derived & setZero(Index size)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
void compute(const MatrixType &mat)
Definition: Scaling.h:73
VectorXd & RightScaling()
Definition: Scaling.h:163
void computeRef(MatrixType &mat)
Definition: Scaling.h:149
void setTolerance(double tol)
Definition: Scaling.h:170