66 if (vec.size() % 3 != 0)
68 qWarning(
"Linalg::combine_xyz: Input must be a row or column vector with 3N components.");
72 MatrixXd tmp = MatrixXd(vec.transpose());
75 SparseMatrix<double> sC = s * s.transpose();
76 VectorXd comb(sC.rows());
78 for (qint32 i = 0; i < sC.rows(); ++i)
79 comb[i] = sC.coeff(i, i);
89 JacobiSVD<MatrixXd> svd(A);
90 s = svd.singularValues();
92 double c = s.maxCoeff()/s.minCoeff();
102 JacobiSVD<MatrixXd> svd(A);
103 s = svd.singularValues();
105 double c = s.maxCoeff()/s.mean();
118 SelfAdjointEigenSolver<MatrixXd> t_eigenSolver(A);
120 eig = t_eigenSolver.eigenvalues();
121 eigvec = t_eigenSolver.eigenvectors().transpose();
126 for(qint32 i = 0; i < eig.size()-rnk; ++i)
129 printf(
"Setting small %s eigenvalues to zero.\n", ch_type.toUtf8().constData());
131 printf(
"Not doing PCA for %s\n", ch_type.toUtf8().constData());
134 printf(
"Doing PCA for %s.",ch_type.toUtf8().constData());
135 eigvec = eigvec.block(eigvec.rows()-rnk, 0, rnk, eigvec.cols());
143 const std::string& ch_type,
147 SelfAdjointEigenSolver<MatrixXd> t_eigenSolver(A);
149 eig = t_eigenSolver.eigenvalues();
150 eigvec = t_eigenSolver.eigenvectors().transpose();
155 for(qint32 i = 0; i < eig.size()-rnk; ++i)
158 printf(
"Setting small %s eigenvalues to zero.\n", ch_type.c_str());
160 printf(
"Not doing PCA for %s\n", ch_type.c_str());
163 printf(
"Doing PCA for %s.",ch_type.c_str());
164 eigvec = eigvec.block(eigvec.rows()-rnk, 0, rnk, eigvec.cols());
174 std::vector<int> tmp;
176 std::vector< std::pair<int,int> > t_vecIntIdxValue;
178 for(qint32 i = 0; i < v1.size(); ++i)
179 tmp.push_back(v1[i]);
181 std::vector<int>::iterator it;
182 for(qint32 i = 0; i < v2.size(); ++i)
184 it = std::search(tmp.begin(), tmp.end(), &v2[i], &v2[i]+1);
186 t_vecIntIdxValue.push_back(std::pair<int,int>(v2[i], it-tmp.begin()));
191 VectorXi p_res(t_vecIntIdxValue.size());
192 idx_sel = VectorXi(t_vecIntIdxValue.size());
194 for(quint32 i = 0; i < t_vecIntIdxValue.size(); ++i)
196 p_res[i] = t_vecIntIdxValue[i].first;
197 idx_sel[i] = t_vecIntIdxValue[i].second;
208 qint32 ma = A.rows();
209 qint32 na = A.cols();
210 float bdn =
static_cast<float>(na) / n;
212 if (bdn - std::floor(bdn))
214 qWarning(
"Linalg::make_block_diag: Width of matrix must be an even multiple of n.");
215 return SparseMatrix<double>();
218 typedef Eigen::Triplet<double> T;
219 std::vector<T> tripletList;
220 tripletList.reserve(
static_cast<size_t>(bdn * ma * n));
222 for (qint32 i = 0; i < static_cast<qint32>(bdn); ++i)
224 qint32 current_col = i * n;
225 qint32 current_row = i * ma;
227 for (qint32 r = 0; r < ma; ++r)
228 for (qint32 c = 0; c < n; ++c)
229 tripletList.push_back(T(r + current_row, c + current_col, A(r, c + current_col)));
232 SparseMatrix<double> bd(
static_cast<int>(std::floor(ma * bdn + 0.5f)), na);
233 bd.setFromTriplets(tripletList.begin(), tripletList.end());
243 JacobiSVD<MatrixXd> t_svdA(A);
244 VectorXd s = t_svdA.singularValues();
245 double t_dMax = s.maxCoeff();
248 for(qint32 i = 0; i < s.size(); ++i)
249 sum += s[i] > t_dMax ? 1 : 0;
Linalg class declaration.
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)