59 if (vec.size() % 3 != 0) {
60 qWarning(
"Linalg::combine_xyz: Input must be a row or column vector with 3N components.");
64 MatrixXd tmp = MatrixXd(vec.transpose());
67 SparseMatrix<double> sC = s * s.transpose();
68 VectorXd comb(sC.rows());
70 for (qint32 i = 0; i < sC.rows(); ++i)
71 comb[i] = sC.coeff(i, i);
81 JacobiSVD<MatrixXd>
svd(A);
82 s =
svd.singularValues();
84 double c = s.maxCoeff() / s.minCoeff();
94 JacobiSVD<MatrixXd>
svd(A);
95 s =
svd.singularValues();
97 double c = s.maxCoeff() / s.mean();
110 SelfAdjointEigenSolver<MatrixXd> t_eigenSolver(A);
112 eig = t_eigenSolver.eigenvalues();
113 eigvec = t_eigenSolver.eigenvectors().transpose();
118 for (qint32 i = 0; i < eig.size() - rnk; ++i)
121 qInfo(
"Setting small %s eigenvalues to zero.", ch_type.toUtf8().constData());
123 qInfo(
"Not doing PCA for %s", ch_type.toUtf8().constData());
125 qInfo(
"Doing PCA for %s.", ch_type.toUtf8().constData());
126 eigvec = eigvec.bottomRows(rnk).eval();
134 const std::string& ch_type,
138 SelfAdjointEigenSolver<MatrixXd> t_eigenSolver(A);
140 eig = t_eigenSolver.eigenvalues();
141 eigvec = t_eigenSolver.eigenvectors().transpose();
146 for (qint32 i = 0; i < eig.size() - rnk; ++i)
149 qInfo(
"Setting small %s eigenvalues to zero.", ch_type.c_str());
151 qInfo(
"Not doing PCA for %s", ch_type.c_str());
153 qInfo(
"Doing PCA for %s.", ch_type.c_str());
154 eigvec = eigvec.bottomRows(rnk).eval();
164 std::vector<int> tmp;
166 std::vector<std::pair<int, int>> t_vecIntIdxValue;
168 for (qint32 i = 0; i < v1.size(); ++i)
169 tmp.push_back(v1[i]);
171 std::vector<int>::iterator it;
172 for (qint32 i = 0; i < v2.size(); ++i) {
173 it = std::search(tmp.begin(), tmp.end(), &v2[i], &v2[i] + 1);
175 t_vecIntIdxValue.push_back(std::pair<int, int>(v2[i], it - tmp.begin()));
180 VectorXi p_res(t_vecIntIdxValue.size());
181 idx_sel = VectorXi(t_vecIntIdxValue.size());
183 for (quint32 i = 0; i < t_vecIntIdxValue.size(); ++i) {
184 p_res[i] = t_vecIntIdxValue[i].first;
185 idx_sel[i] = t_vecIntIdxValue[i].second;
196 qint32 ma = A.rows();
197 qint32 na = A.cols();
198 float bdn =
static_cast<float>(na) / n;
200 if (bdn - std::floor(bdn)) {
201 qWarning(
"Linalg::make_block_diag: Width of matrix must be an even multiple of n.");
202 return SparseMatrix<double>();
205 typedef Eigen::Triplet<double> T;
206 std::vector<T> tripletList;
207 tripletList.reserve(
static_cast<size_t>(bdn * ma * n));
209 for (qint32 i = 0; i < static_cast<qint32>(bdn); ++i) {
210 qint32 current_col = i * n;
211 qint32 current_row = i * ma;
213 for (qint32 r = 0; r < ma; ++r)
214 for (qint32 c = 0; c < n; ++c)
215 tripletList.push_back(T(r + current_row, c + current_col, A(r, c + current_col)));
218 SparseMatrix<double> bd(
static_cast<int>(std::floor(ma * bdn + 0.5f)), na);
219 bd.setFromTriplets(tripletList.begin(), tripletList.end());
229 JacobiSVD<MatrixXd> t_svdA(A);
230 VectorXd s = t_svdA.singularValues();
231 double t_dMax = s.maxCoeff();
234 for (qint32 i = 0; i < s.size(); ++i)
235 sum += s[i] > t_dMax ? 1 : 0;
Eigen::JacobiSVD< Eigen::Matrix3f > svd(S, Eigen::ComputeFullU|Eigen::ComputeFullV)
Static linear-algebra helpers: SVD-based conditioning, block-diagonal assembly, sorted index pairs.
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
static bool compareIdxValuePairSmallerThan(const std::pair< int, T > &lhs, const std::pair< int, T > &rhs)
static Eigen::VectorXd combine_xyz(const Eigen::VectorXd &vec)
static Eigen::VectorXi sort(Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, bool desc=true)
static qint32 rank(const Eigen::MatrixXd &A, double tol=1e-8)
static void get_whitener(Eigen::MatrixXd &A, bool pca, QString ch_type, Eigen::VectorXd &eig, Eigen::MatrixXd &eigvec)
static Eigen::VectorXi intersect(const Eigen::VectorXi &v1, const Eigen::VectorXi &v2, Eigen::VectorXi &idx_sel)
static double getConditionNumber(const Eigen::MatrixXd &A, Eigen::VectorXd &s)
static double getConditionSlope(const Eigen::MatrixXd &A, Eigen::VectorXd &s)
static Eigen::SparseMatrix< double > make_block_diag(const Eigen::MatrixXd &A, qint32 n)