예제 #1
0
파일: nomalloc.cpp 프로젝트: Aerobota/c2tam
void ctms_decompositions()
{
  const int maxSize = 16;
  const int size    = 12;

  typedef Eigen::Matrix<Scalar,
                        Eigen::Dynamic, Eigen::Dynamic,
                        0,
                        maxSize, maxSize> Matrix;

  typedef Eigen::Matrix<Scalar,
                        Eigen::Dynamic, 1,
                        0,
                        maxSize, 1> Vector;

  typedef Eigen::Matrix<std::complex<Scalar>,
                        Eigen::Dynamic, Eigen::Dynamic,
                        0,
                        maxSize, maxSize> ComplexMatrix;

  const Matrix A(Matrix::Random(size, size));
  const ComplexMatrix complexA(ComplexMatrix::Random(size, size));
  const Matrix saA = A.adjoint() * A;

  // Cholesky module
  Eigen::LLT<Matrix>  LLT;  LLT.compute(A);
  Eigen::LDLT<Matrix> LDLT; LDLT.compute(A);

  // Eigenvalues module
  Eigen::HessenbergDecomposition<ComplexMatrix> hessDecomp;        hessDecomp.compute(complexA);
  Eigen::ComplexSchur<ComplexMatrix>            cSchur(size);      cSchur.compute(complexA);
  Eigen::ComplexEigenSolver<ComplexMatrix>      cEigSolver;        cEigSolver.compute(complexA);
  Eigen::EigenSolver<Matrix>                    eigSolver;         eigSolver.compute(A);
  Eigen::SelfAdjointEigenSolver<Matrix>         saEigSolver(size); saEigSolver.compute(saA);
  Eigen::Tridiagonalization<Matrix>             tridiag;           tridiag.compute(saA);

  // LU module
  Eigen::PartialPivLU<Matrix> ppLU; ppLU.compute(A);
  Eigen::FullPivLU<Matrix>    fpLU; fpLU.compute(A);

  // QR module
  Eigen::HouseholderQR<Matrix>        hQR;  hQR.compute(A);
  Eigen::ColPivHouseholderQR<Matrix>  cpQR; cpQR.compute(A);
  Eigen::FullPivHouseholderQR<Matrix> fpQR; fpQR.compute(A);

  // SVD module
  Eigen::JacobiSVD<Matrix> jSVD; jSVD.compute(A, ComputeFullU | ComputeFullV);
}
예제 #2
0
파일: pca.cpp 프로젝트: Jorjor70/meuh
  pca& pca::compute(mat samples, real eps, mat metric) {
    
    mean_ = samples.colwise().mean().transpose();
    samples.rowwise() -= mean().transpose();
    
    Eigen::LLT< mat > llt;

    if( !metric.empty() ) {
      assert( metric.rows() == samples.cols() );
      assert( metric.cols() == metric.rows() );
      
      llt.compute( metric );
       
      samples = samples * llt.matrixL();
    }
    
    math::svd svd;
    svd.compute(samples, eps, Eigen::ComputeThinV );
  
    if( !metric.empty() ) {
      basis_ = llt.matrixU().solve( svd.v() );
    } else {
      basis_ = svd.v();
    }
    
    // surprisingly, this one works for both cases (coords = samples *
    // U^{-T}) where U is the eigen basis
    coords_ = samples * svd.v();

    dev_ = svd.singular().cwiseAbs();
    
    rank_ = svd.rank();

    // print_vec( cumul() );

    return *this;
  }