5 #include <gsl/gsl_vector.h> 6 #include <gsl/gsl_vector_int.h> 7 #include <gsl/gsl_matrix.h> 9 #include <Eigen/Sparse> 10 #include <ATSuite/atmatrix.hpp> 13 #define plog2p( x ) ( (x) > 0.0 ? (x) * log(x) / log(2) : 0.0 ) 15 using namespace Eigen;
25 typedef SparseMatrix<double, RowMajor>
SpMatCSR;
29 typedef SparseMatrix<double, ColMajor>
SpMatCSC;
58 VectorXd rowSum = VectorXd::Zero(T->rows());
60 for (j = 0; j < T->cols(); j++)
61 for (SpMatCSC::InnerIterator it(*T, j); it; ++it)
62 rowSum(it.row()) += it.value();
65 for (j = 0; j < T->cols(); j++)
66 for (SpMatCSC::InnerIterator it(*T, j); it; ++it)
67 if (rowSum(it.row()) > 0.)
68 it.valueRef() /= rowSum(it.row());
89 gsl_vector_free(rowSum);
104 VectorXd colSum = VectorXd::Zero(T->cols());
106 for (j = 0; j < T->rows(); j++)
107 for (SpMatCSR::InnerIterator it(*T, j); it; ++it)
108 colSum(it.col()) += it.value();
111 for (j = 0; j < T->rows(); j++)
112 for (SpMatCSR::InnerIterator it(*T, j); it; ++it)
113 if (colSum(it.col()) > 0.)
114 it.valueRef() /= colSum(it.col());
130 for (
int outerIdx = 0; outerIdx < T->outerSize(); outerIdx++)
131 for (SpMatCSR::InnerIterator it(*T, outerIdx); it; ++it)
132 it.valueRef() /= norm;
147 for (
int outerIdx = 0; outerIdx < T->outerSize(); outerIdx++)
148 for (SpMatCSC::InnerIterator it(*T, outerIdx); it; ++it)
151 for (
int outerIdx = 0; outerIdx < T->outerSize(); outerIdx++)
152 for (SpMatCSC::InnerIterator it(*T, outerIdx); it; ++it)
153 it.valueRef() /= norm;
174 gsl_vector *rowCut, gsl_vector *colCut,
175 double tol,
int norm)
177 double valRow, valCol;
179 for (
int outerIdx = 0; outerIdx < T->outerSize(); outerIdx++){
180 valRow = gsl_vector_get(rowCut, outerIdx);
181 for (SpMatCSR::InnerIterator it(*T, outerIdx); it; ++it){
182 valCol = gsl_vector_get(colCut, it.col());
184 if ((valRow < tol) || (valCol < tol))
void filterTransitionMatrix(SpMatCSR *, gsl_vector *, gsl_vector *, double, int)
Remove weak nodes from a transition matrix.
void toAndStochastic(SpMatCSR *)
Make an Eigen CSR matrix and stochastic.
void toLeftStochastic(SpMatCSR *)
Make an Eigen CSR matrix left stochastic.
SparseMatrix< double, ColMajor > SpMatCSC
Eigen CSC matrix of double type.
void toRightStochastic(SpMatCSC *)
Make an Eigen CSC matrix right stochastic.
SparseMatrix< bool, ColMajor > SpMatCSCBool
Eigen CSC matrix of boolean type.
SparseMatrix< double, RowMajor > SpMatCSR
Eigen CSR matrix of double type.
gsl_vector * getRowSum(SpMatCSR *)
Get the sum of each row of an Eigen CSR matrix.
double getSum(SpMatCSR *)
Returns a the sum of the elements of an Eigen CSR matrix.
SparseMatrix< int, RowMajor > SpMatIntCSR
Eigen CSR matrix of integer type.
void normalizeVector(gsl_vector *)
Normalize a GSL vector by the sum of its elements.
void normalizeRows(SpMatCSR *, gsl_vector *)
Normalize each row of an Eigen CSR matrix by a GSL vector.
Eigen::SparseMatrix< double, Eigen::ColMajor > SpMatCSC
Eigen sparse CSC matrix of double type.