libqe 0.2.6-dev.9001
QE C++ library
Loading...
Searching...
No Matches
normalization.hpp
Go to the documentation of this file.
1
5#ifndef LIBQE_NORMALIZATION_HPP
6#define LIBQE_NORMALIZATION_HPP
7
8#include <armadillo>
9#include <cmath>
10
11namespace qe {
12
22inline arma::mat normalize_networks(arma::mat m) {
23 arma::mat out(m.n_rows, m.n_cols, arma::fill::zeros);
24 for (arma::uword r = 0; r < m.n_rows; r++) {
25 double len = arma::norm(m.row(r), 2);
26 if (std::isfinite(len) && len > 0.0) out.row(r) = m.row(r) / len;
27 }
28 return out;
29}
30
42inline arma::mat scale_networks(arma::mat m) {
43 double largest = 0.0;
44 for (arma::uword r = 0; r < m.n_rows; r++) {
45 double len = arma::norm(m.row(r), 2);
46 if (std::isfinite(len)) largest = std::max(largest, len);
47 }
48 if (largest > 0.0) m /= largest;
49 return m;
50}
51
52} // namespace qe
53
54#endif // LIBQE_NORMALIZATION_HPP
Definition adjacency.hpp:16
arma::mat normalize_networks(arma::mat m)
Normalize each row to unit L2 norm (project onto the unit hypersphere).
Definition normalization.hpp:22
arma::mat scale_networks(arma::mat m)
Scale every entry by the reciprocal of the largest row L2 norm.
Definition normalization.hpp:42