https://github.com/peekxc/primate
Implicit matrix function and trace estimator
https://github.com/peekxc/primate
lanczos-algorithm linear-algebra matrix-functions python-package randomized-algorithm scientific-computing
Last synced: 16 days ago
JSON representation
Implicit matrix function and trace estimator
- Host: GitHub
- URL: https://github.com/peekxc/primate
- Owner: peekxc
- License: apache-2.0
- Created: 2023-08-31T01:20:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-28T01:08:19.000Z (5 months ago)
- Last Synced: 2025-04-13T23:07:48.194Z (about 1 month ago)
- Topics: lanczos-algorithm, linear-algebra, matrix-functions, python-package, randomized-algorithm, scientific-computing
- Language: Python
- Homepage: https://peekxc.github.io/primate/
- Size: 24.2 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://peekxc.github.io/primate/)
[](https://github.com/peekxc/primate/actions/workflows/wheels.yml)
[](https://coveralls.io/github/peekxc/primate?branch=main)
[](https://github.com/peekxc/primate/actions)
[](https://pypi.org/project/scikit-primate/)
[](https://github.com/astral-sh/ruff)`primate`, short for **Pr**obabilistic **I**mplicit **Ma**trix **T**race **E**stimator, is a Python package that provides estimators of quantities from matrices, linear operators, and [matrix functions](https://en.wikipedia.org/wiki/Analytic_function_of_a_matrix):
$$ f(A) \triangleq U f(\Lambda) U^{\intercal}, \quad \quad f : [a,b] \to \mathbb{R}$$
This definition is quite general in that different parameterizations of $f$ produce a variety of spectral quantities, including the matrix inverse $A^{-1}$, the matrix exponential $\mathrm{exp}(A)$, the matrix logarithm $\mathrm{log}(A)$, and so on.
Composing these with _trace_ and _diagonal_ estimators yields approximations for the [numerical rank](https://doi.org/10.1016/j.amc.2007.06.005), the [log-determinant](https://en.wikipedia.org/wiki/Determinant#Trace), the [Schatten norms](https://en.wikipedia.org/wiki/Schatten_norm), the [eigencount](https://doi.org/10.1002/nla.2048), the [Estrada index](https://en.wikipedia.org/wiki/Estrada_index), the [Heat Kernel Signature](https://en.wikipedia.org/wiki/Heat_kernel_signature), and so on.
Notable features of `primate` include:
- Efficient methods for _trace_, _diagonal_, and _matrix function_ approximation
- Support for _arbitrary_ matrix types, e.g. NumPy arrays, sparse matrices, or [LinearOperator](https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html#scipy-sparse-linalg-linearoperator)'s
- Support for _arbitrary_ matrix functions, i.e. `Callable`'s (Python) and `invocable`'s[^3] (C++)
- Matrix-free interface to the _Lanczos_ and _Golub-Welsch_ methods
- Various composable stopping criteria for easy and adaptive convergence checking`primate` was partially inspired by the [`imate` package](https://github.com/ameli/imate)---for a comparison of the two, see [here](https://peekxc.github.io/primate/imate_compare.html).
## Installation
`primate` is a standard PEP-517 package, and thus can be installed via pip:
```{bash}
python -m pip install scikit-primate
```Assuming your platform is supported, no compilation is needed.
See the [installation page](https://peekxc.github.io/primate/basic/install.html) for details.
## Applications
Applications of matrix functions include [characterizing folding in proteins](https://en.wikipedia.org/wiki/Estrada_index), [principal component regression](https://en.wikipedia.org/wiki/Principal_component_regression), [spectral clustering](https://en.wikipedia.org/wiki/Spectral_clustering), [Gaussian process likelihood estimation](https://en.wikipedia.org/wiki/Gaussian_process), [counting triangles in distributed-memory networks](https://doi.org/10.1137/23M1548323), [characterizing graph similarity](https://doi.org/10.1016/j.patcog.2008.12.029), and [deep neural loss landscape analysis](https://proceedings.mlr.press/v97/ghorbani19b).
If you have a particular application, feel free to make a computational notebook to illustrate it as a use-case!
[^1]: Musco, Cameron, Christopher Musco, and Aaron Sidford. (2018) "Stability of the Lanczos method for matrix function approximation."
[^2]: Ubaru, S., Chen, J., & Saad, Y. (2017). Fast estimation of tr(f(A)) via stochastic Lanczos quadrature.
[^3]: This includes [std::function](https://en.cppreference.com/w/cpp/utility/functional/function)'s, C-style function pointers, [functors](https://stackoverflow.com/questions/356950/what-are-c-functors-and-their-uses), and [lambda expressions](https://en.cppreference.com/w/cpp/language/lambda).