Go to the documentation of this file.
46 size_t n2 = actual.cols(),
m2 = actual.rows();
48 cout <<
"not equal:" << endl;
50 print(actual,
"actual = ");
52 cout <<
m1 <<
"," <<
n1 <<
" != " <<
m2 <<
"," <<
n2 << endl;
55 print(diff,
"actual - expected = ");
63 cout <<
"Erroneously equal:" << endl;
70 bool assert_equal(
const std::list<Matrix>& As,
const std::list<Matrix>& Bs,
double tol) {
71 if (As.size() != Bs.size())
return false;
73 list<Matrix>::const_iterator itA, itB;
74 itA = As.begin(); itB = Bs.begin();
75 for (; itA != As.end(); itA++, itB++)
86 size_t n1 =
A.cols(),
m1 =
A.rows();
87 size_t n2 =
B.cols(),
m2 =
B.rows();
89 bool dependent =
true;
90 if(
m1!=
m2 ||
n1!=
n2) dependent =
false;
92 for(
size_t i=0; dependent &&
i<
m1;
i++) {
105 cout <<
"not linearly dependent:" << endl;
108 if(
A.rows()!=
B.rows() ||
A.cols()!=
B.cols())
109 cout <<
A.rows() <<
"x" <<
A.cols() <<
" != " <<
B.rows() <<
"x" <<
B.cols() << endl;
119 cout <<
"not linearly dependent:" << endl;
122 if(
A.rows()!=
B.rows() ||
A.cols()!=
B.cols())
123 cout <<
A.rows() <<
"x" <<
A.cols() <<
" != " <<
B.rows() <<
"x" <<
B.cols() << endl;
130 if (
A.rows()!=
v.size()) {
131 throw std::invalid_argument(
"Matrix operator^ : A.m(" + std::to_string(
A.rows()) +
")!=v.size(" +
132 std::to_string(
v.size()) +
")");
137 return A.transpose() *
v;
180 while(getline(inputStream, line)) {
182 coeffs.push_back(vector<double>());
184 coeffs.back().reserve(width);
185 stringstream lineStream(line);
186 std::copy(istream_iterator<double>(lineStream), istream_iterator<double>(),
187 back_insert_iterator<vector<double> >(coeffs.back()));
189 width = coeffs.back().size();
190 if(coeffs.back().size() != width)
191 throw runtime_error(
"Error reading matrix from input stream, inconsistent numbers of elements in rows");
196 destinationMatrix.resize(height, width);
198 for(
const vector<double>& rowVec: coeffs) {
209 for (
size_t i = 0;
i<Hs.size(); ++
i) {
215 for (
size_t i = 0;
i<Hs.size(); ++
i) {
226 for (
size_t i = 0 ;
i < (
size_t)
A.cols() ; ++
i ) {
227 v[
i] =
A.col(
i).dot(
A.col(
i));
236 const size_t m =
A.rows(),
n =
A.cols(), kprime =
min(
m,
n);
242 for(
size_t j=0;
j < kprime;
j++){
249 for(
size_t k = 0 ; k < mm; k++)
256 for(
size_t k = 0 ; k <
m; k++)
257 v(k) = k<
j ? 0.0 : vjm(k-
j);
267 return make_pair(
Q,
R);
271 list<std::tuple<Vector, double, double> >
273 size_t m =
A.rows(),
n =
A.cols();
274 size_t maxRank =
min(
m,
n);
277 list<std::tuple<Vector, double, double> >
results;
286 for (
size_t j=0;
j<
n; ++
j) {
298 for (
size_t j2=
j+1; j2<
n; ++j2)
299 r(j2) = pseudo.dot(
A.col(j2));
302 double d = pseudo.dot(
b);
309 if (
results.size()>=maxRank)
break;
313 A -=
a * r.transpose();
327 const size_t m =
A.rows(),
n =
A.cols(), kprime =
min(k,
min(
m,
n));
329 for(
size_t j=0;
j < kprime;
j++) {
337 gttic(householder_update);
340 A.block(
j,
j,
m-
j,
n-
j) -= vjm *
w.transpose();
341 gttoc(householder_update);
345 gttic(householder_vector_copy);
346 A.col(
j).segment(
j+1,
m-(
j+1)) = vjm.segment(1,
m-(
j+1));
347 gttoc(householder_vector_copy);
368 assert(
L.rows() ==
L.cols());
378 assert(
U.rows() ==
U.cols());
388 assert(
U.rows() ==
U.cols());
401 va_start(ap, nrMatrices);
402 for(
size_t i = 0 ;
i < nrMatrices ;
i++) {
408 va_start(ap, nrMatrices);
411 for(
size_t i = 0 ;
i < nrMatrices ;
i++) {
413 for(
size_t d1 = 0; d1 < (
size_t)
M->rows(); d1++)
415 A(vindex+d1,
d2) = (*M)(d1,
d2);
424 if (blocks.size() == 1)
return blocks.at(0);
425 DenseIndex nrows = 0, ncols = blocks.at(0).cols();
428 if (ncols !=
mat.cols())
429 throw invalid_argument(
"Matrix::stack(): column size mismatch!");
436 cur_row +=
mat.rows();
446 size_t dimA2 =
n*matrices.size();
448 for(
const Matrix*
M: matrices) {
457 for(
const Matrix*
M: matrices) {
458 size_t row_len =
M->cols();
459 A.block(0, hindex, dimA1, row_len) = *
M;
469 vector<const Matrix *> matrices;
471 va_start(ap, nrMatrices);
472 for(
size_t i = 0 ;
i < nrMatrices ;
i++) {
474 matrices.push_back(
M);
485 const double& vi =
v(
i);
507 const size_t n =
A.cols();
509 for (
size_t j=0;
j<
n; ++
j) {
510 const double& vj =
v(
j);
515 for (
size_t j=0;
j<
n; ++
j)
525 return llt.matrixL();
532 return llt.matrixU();
541 Matrix inv = Matrix::Identity(
A.rows(),
A.rows());
543 return inv*inv.transpose();
553 Matrix inv = Matrix::Identity(
A.rows(),
A.rows());
555 return inv.transpose();
562 S =
svd.singularValues();
567 std::tuple<int, double, Vector>
DLT(
const Matrix& A,
double rank_tol) {
570 size_t n =
A.rows(),
p =
A.cols(),
m =
min(
n,
p);
579 for (
size_t j = 0;
j <
m;
j++)
580 if (
s(
j) > rank_tol) rank++;
589 Matrix E = Matrix::Identity(
A.rows(),
A.rows()), A_k = Matrix::Identity(
A.rows(),
A.rows());
590 for(
size_t k=1;k<=
K;k++) {
591 A_k = A_k*
A/double(k);
601 const string firstline = label;
603 const string padding(firstline.size(),
' ');
604 const bool transposeMatrix = makeVectorHorizontal &&
matrix.cols() == 1 &&
matrix.rows() > 1;
609 stringstream matrixPrinted;
611 matrixPrinted <<
matrix.transpose();
614 const std::string matrixStr = matrixPrinted.str();
618 std::istringstream iss(matrixStr);
620 while (std::getline(iss, line)) {
621 assert(
row < effectiveRows);
624 ss <<
"[ " << line <<
" ]";
625 if(
row < effectiveRows - 1)
638 size_t rows =
A.rows();
639 size_t cols =
A.cols();
644 HCoeffsType hCoeffs(
size);
645 RowVectorType temp(
cols);
647 #if !EIGEN_VERSION_AT_LEAST(3,2,5)
list< std::tuple< Vector, double, double > > weighted_eliminate(Matrix &A, Vector &b, const Vector &sigmas)
std::tuple< int, double, Vector > DLT(const Matrix &A, double rank_tol)
istream & operator>>(istream &inputStream, Matrix &destinationMatrix)
const EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_boolean_xor_op, const Derived, const OtherDerived > operator^(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
const MATRIX::ConstColXpr column(const MATRIX &A, size_t j)
void zeroBelowDiagonal(MATRIX &A, size_t cols=0)
EIGEN_DONT_INLINE void llt(const Mat &A, const Mat &B, Mat &C)
typedef and functions to augment Eigen's VectorXd
Included from all GTSAM files.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static const double d[K][N]
double weightedPseudoinverse(const Vector &a, const Vector &weights, Vector &pseudo)
double houseInPlace(Vector &v)
Matrix inverse_square_root(const Matrix &A)
typedef and functions to augment Eigen's MatrixXd
Matrix vector_scale(const Matrix &A, const Vector &v, bool inf_mask)
Matrix diag(const std::vector< Matrix > &Hs)
void householder_(Matrix &A, size_t k, bool copy_vectors)
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
Matrix stack(const std::vector< Matrix > &blocks)
const Eigen::IOFormat & matlabFormat()
pair< Matrix, Matrix > qr(const Matrix &A)
double beta(double a, double b)
cout<< "Here is the matrix m:"<< endl<< m<< endl;JacobiSVD< MatrixXf > svd(m, ComputeThinU|ComputeThinV)
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
static std::stringstream ss
void householder(const MatrixType &m)
void vector_scale_inplace(const Vector &v, Matrix &A, bool inf_mask)
Matrix RtR(const Matrix &A)
Matrix cholesky_inverse(const Matrix &A)
Matrix expm(const Matrix &A, size_t K)
Vector columnNormSquare(const Matrix &A)
A matrix or vector expression mapping an existing array of data.
std::ofstream out("Result.txt")
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
void save(const Matrix &A, const string &s, const string &filename)
Two-sided Jacobi SVD decomposition of a rectangular matrix.
The quaternion class used to represent 3D orientations and rotations.
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
void inplace_QR(Matrix &A)
static void run(MatrixQR &mat, HCoeffs &hCoeffs, Index maxBlockSize=32, typename MatrixQR::Scalar *tempData=0)
ptrdiff_t DenseIndex
The index type for Eigen objects.
Vector backSubstituteLower(const Matrix &L, const Vector &b, bool unit)
bool assert_equal(const std::list< Matrix > &As, const std::list< Matrix > &Bs, double tol)
void insertSub(Eigen::MatrixBase< Derived1 > &fullMatrix, const Eigen::MatrixBase< Derived2 > &subMatrix, size_t i, size_t j)
Array< int, Dynamic, 1 > v
std::map< std::string, Array< float, 1, 8, DontAlign|RowMajor > > results
A thin wrapper around std::list that uses boost's fast_pool_allocator.
pair< double, Vector > house(const Vector &x)
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
Vector backSubstituteUpper(const Vector &b, const Matrix &U, bool unit)
bool linear_independent(const Matrix &A, const Matrix &B, double tol)
void print(const Matrix &A, const string &s)
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Jet< T, N > sqrt(const Jet< T, N > &f)
Rot2 R(Rot2::fromAngle(0.1))
bool linear_dependent(const Matrix &A, const Matrix &B, double tol)
static bool is_linear_dependent(const Matrix &A, const Matrix &B, double tol)
Matrix collect(size_t nrMatrices,...)
std::string formatMatrixIndented(const std::string &label, const Matrix &matrix, bool makeVectorHorizontal)
Matrix LLt(const Matrix &A)
Matrix< RealScalar, Dynamic, Dynamic > M
gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:12:12