Search code examples
pythonnumpyscipysparse-matrix

Python package to estimate Perron-Frobenius Eigenvalue of real, square, non-negative matrix


Is there an optimized package or method that estimates the Perron-Frobenius eigenvalue of a real, square, non-negative matrix? This could be significantly faster (especially for large and/or sparse matrices) than an exact calculation -- given that the Perron-Frobenius eigenvalue can be arrived at by iterating the matrix. I am hoping an optimized package exists which does this.


Solution

  • If A is a square matrix, possibly in a sparse format, then you can get its largest magnitude (LM) eigenvalue, i.e. its Perron-Frobenius eigenvalue, and the corresponding eigenvector using SciPy’s eigs and eigsh functions:

    from scipy.sparse.linalg import eigs
    
    val, vec = eigs(a, k=1, which='LM')
    

    SciPy has solvers for sparse eigenvalue problems of various forms that use the ARPACK library. You can read more in SciPy’s ARPACK tutorial.