59 if (vec.size() % 3 != 0)
61 qWarning(
"Linalg::combine_xyz: Input must be a row or column vector with 3N components.");
65 MatrixXd tmp = MatrixXd(vec.transpose());
68 SparseMatrix<double> sC = s * s.transpose();
69 VectorXd comb(sC.rows());
71 for (qint32 i = 0; i < sC.rows(); ++i)
72 comb[i] = sC.coeff(i, i);
82 JacobiSVD<MatrixXd>
svd(A);
83 s =
svd.singularValues();
85 double c = s.maxCoeff()/s.minCoeff();
95 JacobiSVD<MatrixXd>
svd(A);
96 s =
svd.singularValues();
98 double c = s.maxCoeff()/s.mean();
111 SelfAdjointEigenSolver<MatrixXd> t_eigenSolver(A);
113 eig = t_eigenSolver.eigenvalues();
114 eigvec = t_eigenSolver.eigenvectors().transpose();
119 for(qint32 i = 0; i < eig.size()-rnk; ++i)
122 qInfo(
"Setting small %s eigenvalues to zero.", ch_type.toUtf8().constData());
124 qInfo(
"Not doing PCA for %s", ch_type.toUtf8().constData());
127 qInfo(
"Doing PCA for %s.", ch_type.toUtf8().constData());
128 eigvec = eigvec.block(eigvec.rows()-rnk, 0, rnk, eigvec.cols());
136 const std::string& ch_type,
140 SelfAdjointEigenSolver<MatrixXd> t_eigenSolver(A);
142 eig = t_eigenSolver.eigenvalues();
143 eigvec = t_eigenSolver.eigenvectors().transpose();
148 for(qint32 i = 0; i < eig.size()-rnk; ++i)
151 qInfo(
"Setting small %s eigenvalues to zero.", ch_type.c_str());
153 qInfo(
"Not doing PCA for %s", ch_type.c_str());
156 qInfo(
"Doing PCA for %s.", ch_type.c_str());
157 eigvec = eigvec.block(eigvec.rows()-rnk, 0, rnk, eigvec.cols());
167 std::vector<int> tmp;
169 std::vector< std::pair<int,int> > t_vecIntIdxValue;
171 for(qint32 i = 0; i < v1.size(); ++i)
172 tmp.push_back(v1[i]);
174 std::vector<int>::iterator it;
175 for(qint32 i = 0; i < v2.size(); ++i)
177 it = std::search(tmp.begin(), tmp.end(), &v2[i], &v2[i]+1);
179 t_vecIntIdxValue.push_back(std::pair<int,int>(v2[i], it-tmp.begin()));
184 VectorXi p_res(t_vecIntIdxValue.size());
185 idx_sel = VectorXi(t_vecIntIdxValue.size());
187 for(quint32 i = 0; i < t_vecIntIdxValue.size(); ++i)
189 p_res[i] = t_vecIntIdxValue[i].first;
190 idx_sel[i] = t_vecIntIdxValue[i].second;
201 qint32 ma = A.rows();
202 qint32 na = A.cols();
203 float bdn =
static_cast<float>(na) / n;
205 if (bdn - std::floor(bdn))
207 qWarning(
"Linalg::make_block_diag: Width of matrix must be an even multiple of n.");
208 return SparseMatrix<double>();
211 typedef Eigen::Triplet<double> T;
212 std::vector<T> tripletList;
213 tripletList.reserve(
static_cast<size_t>(bdn * ma * n));
215 for (qint32 i = 0; i < static_cast<qint32>(bdn); ++i)
217 qint32 current_col = i * n;
218 qint32 current_row = i * ma;
220 for (qint32 r = 0; r < ma; ++r)
221 for (qint32 c = 0; c < n; ++c)
222 tripletList.push_back(T(r + current_row, c + current_col, A(r, c + current_col)));
225 SparseMatrix<double> bd(
static_cast<int>(std::floor(ma * bdn + 0.5f)), na);
226 bd.setFromTriplets(tripletList.begin(), tripletList.end());
236 JacobiSVD<MatrixXd> t_svdA(A);
237 VectorXd s = t_svdA.singularValues();
238 double t_dMax = s.maxCoeff();
241 for(qint32 i = 0; i < s.size(); ++i)
242 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)