Git Product home page Git Product logo

arpack-arma's Introduction

ARPACK-Armadillo

ARPACK-Armadillo is a redesign of the ARPACK software for large scale eigenvalue problems, built on top of Armadillo, an open source C++ linear algebra library.

ARPACK-Armadillo is implemented as a header-only C++ library which relies on the BLAS and LAPACK libraries. Therefore program that uses ARPACK-Armadillo should also link to those two libraries.

Common Usage

ARPACK-Armadillo is designed to calculate a specified number (k) of eigenvalues of a large square matrix (A). Usually k is much less than the size of matrix (n), so that only a few eigenvalues and eigenvectors are computed, which in general is more efficient than calculating the whole spectral decomposition. Users can choose eigenvalue selection rules to pick up the eigenvalues of interest, such as the largest k eigenvalues, or eigenvalues with largest real parts, etc.

To use the eigen solvers in this library, the user does not need to directly provide the whole matrix, but instead, the algorithm only requires certain operations defined on A, and in the basic setting, it is simply the matrix-vector multiplication. Therefore, if the matrix-vector product A * x can be computed efficiently, which is the case when A is sparse, ARPACK-Armadillo will be very powerful for large scale eigenvalue problems.

There are two major steps to use the ARPACK-Armadillo library:

  1. Define a class that implements a certain matrix operation, for example the matrix-vector multiplication y = A * x or the shift-solve operation y = inv(A - σ * I) * x. ARPACK-Armadillo has defined a number of helper classes to quickly create such operations from a matrix object. See the documentation of DenseGenMatProd, DenseSymShiftSolve, etc.
  2. Create an object of one of the eigen solver classes, for example SymEigsSolver for symmetric matrices, and GenEigsSolver for general matrices. Member functions of this object can then be called to conduct the computation and retrieve the eigenvalues and/or eigenvectors.

Below is a list of the available eigen solvers in ARPACK-Armadillo:

Examples

Below is an example that demonstrates the use of the eigen solver for symmetric matrices.

#include <armadillo>
#include <SymEigsSolver.h>  // Also includes <MatOp/DenseGenMatProd.h>

int main()
{
    // We are going to calculate the eigenvalues of M
    arma::mat A = arma::randu(10, 10);
    arma::mat M = A + A.t();

    // Construct matrix operation object using the wrapper class DenseGenMatProd
    DenseGenMatProd<double> op(M);

    // Construct eigen solver object, requesting the largest three eigenvalues
    SymEigsSolver< double, LARGEST_ALGE, DenseGenMatProd<double> > eigs(&op, 3, 6);

    // Initialize and compute
    eigs.init();
    int nconv = eigs.compute();

    // Retrieve results
    arma::vec evalues;
    if(nconv > 0)
     evalues = eigs.eigenvalues();

    evalues.print("Eigenvalues found:");

    return 0;
}

And here is an example for user-supplied matrix operation class.

#include <armadillo>
#include <SymEigsSolver.h>

// M = diag(1, 2, ..., 10)
class MyDiagonalTen
{
public:
    int rows() { return 10; }
    int cols() { return 10; }
    // y_out = M * x_in
    void perform_op(double *x_in, double *y_out)
    {
        for(int i = 0; i < rows(); i++)
        {
            y_out[i] = x_in[i] * (i + 1);
        }
    }
};

int main()
{
    MyDiagonalTen op;
    SymEigsSolver<double, LARGEST_ALGE, MyDiagonalTen> eigs(&op, 3, 6);
    eigs.init();
    eigs.compute();
    arma::vec evalues = eigs.eigenvalues();
    evalues.print("Eigenvalues found:");

    return 0;
}

Shift-and-invert Mode

When we want to find eigenvalues that are closest to a number σ, for example to find the smallest eigenvalues of a positive definite matrix (in which case σ = 0), it is advised to use the shift-and-invert mode of eigen solvers.

In the shift-and-invert mode, selection rules are applied to 1/(λ - σ) rather than λ, where λ are eigenvalues of A. To use this mode, users need to define the shift-solve matrix operation. See the documentation of SymEigsShiftSolver for details.

Documentation

This page contains the documentation of ARPACK-Armadillo generated by Doxygen, including all the background knowledge, example code and class APIs.

Acknowledgements

ARPACK-Armadillo was a GSOC project in the year of 2015. The author would like to express special thanks to the three mentors, Dirk Eddelbuettel, Ryan Curtin and Drew Schmidt, who provided numerous helpful comments and suggestions during the development.

License

ARPACK-Armadillo is an open source project licensed under MPL2, the same license used by Armadillo.

arpack-arma's People

Contributors

yixuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

arpack-arma's Issues

OPENMP - Dense vs Sparse

Hello,

First a big thank you for putting up such a brilliant piece of code. I tested arpack-arma last week the first time and it nicely worked in an arpack-arma -> armadillo -> openblas "construct".

Following the examples is also straightforward and I am crunching huge test matrices on my workspace computer...

One very convenient thing was that the OpenMP support of OpenBlas works nicely in armadillo and arpack-arma when computing eigenvalues for dense matrices using DenseGenMatProd and SymEigsSolver.

When switching to SparseGenMatProd in SymEigsSolver it seems only single-CPU execution is working (according to top and the runtime). Basically I just changed all "Dense" to "Sparse" including the header and I am feeding an armadillo sp_mat to SparseGenMatProd op(Bsp). Eigenvalues/Eigenvectors are fine, though. Since I am not exactly an expert in reading your rather advanced code, I am not sure if something is missing in my program....?

This should not be a feature request - I just want to avoid spending coding effort into the wrong direction, if OMP is not working with SparseGenMatProd.

Many thanks and best regards,
Thomas

Library is incompatible with 64-bit BLAS

The library currently assumes that BLAS integers are the same as int, meaning that the library doesn't work with large matrix support i.e. -DARMA_64BIT_WORD -DARMA_BLAS_LONG.

Which version of armadillo is required?

I just downloaded armadillo (stable version 8.100) and arpack-arma and tried to compile the sample program of the arpack-arma readme (attached below for clarity). Unfortunately, I get compilation errors, starting as follows.

In file included from /home/michael/Documents/test/cpp/arpack_arma/arpack-arma/include/LinAlg/TridiagEigen.h:12:0,
                 from /home/michael/Documents/test/cpp/arpack_arma/arpack-arma/include/SymEigsSolver.h:19,
                 from test3.cpp:2:
/home/michael/Documents/test/cpp/arpack_arma/arpack-arma/include/LinAlg/LapackWrapperExtra.h:94:9: error: redefinition of ‘template<class eT> void arma::lapack::sytrs(char*, arma::blas_int*, arma::blas_int*, eT*, arma::blas_int*, arma::blas_int*, eT*, arma::blas_int*, arma::blas_int*)’
         sytrs(char* uplo, blas_int* n, blas_int* nrhs, eT* a, blas_int* lda, blas_int* ipiv, eT* b, blas_int* ldb, blas_int* info)
         ^
...

What is the lastest version of armadillo I can use to build arpack-arma? Or is there a way to use the latest version of armadillo?
Thanks in advance!

#include <armadillo>
#include <SymEigsSolver.h>  // Also includes <MatOp/DenseGenMatProd.h>

int main()
{
    // We are going to calculate the eigenvalues of M
    arma::mat A = arma::randu(10, 10);
    arma::mat M = A + A.t();

    // Construct matrix operation object using the wrapper class DenseGenMatProd
    DenseGenMatProd<double> op(M);

    // Construct eigen solver object, requesting the largest three eigenvalues
    SymEigsSolver< double, LARGEST_ALGE, DenseGenMatProd<double> > eigs(&op, 3, 6);

    // Initialize and compute
    eigs.init();
    int nconv = eigs.compute();

    // Retrieve results
    arma::vec evalues;
    if(nconv > 0)
     evalues = eigs.eigenvalues();

    evalues.print("Eigenvalues found:");

    return 0;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.