Derivative-free method to find zeros of analytic (holomorphic) functions / solve nonlinear (polynomial / generalized) eigenvalue problems using contour integration. (Block SS-Hankel method, Block Sakurai Sugiura method)
Project description
SS Hankel
Documentation: https://ss-hankel.readthedocs.io
Source Code: https://github.com/34j/ss-hankel
Derivative-free method to find zeros of analytic (holomorphic) functions / solve nonlinear (polynomial / generalized) eigenvalue problems using contour integration. (Block SS-Hankel method, Block Sakurai Sugiura method)
Installation
Install this via pip (or your favourite package manager):
pip install ss-hankel
Usage
Below is a simple example of solving the following nonlinear eigenvalue problem from NEP-PACK Tutorial.
$$ f(x) = \begin{pmatrix} 3+e^{0.5x} & 2+2x+e^{0.5x} \ 3+e^{0.5x} & -1+x+e^{0.5x} \end{pmatrix} , \quad f(x) v = 0 $$
from typing import Any
import numpy as np
from numpy.typing import NDArray
from ss_hankel import score, ss_h_circle
def f(x: NDArray[Any]) -> NDArray[Any]: # deriative is not needed!
return np.stack(
[
np.stack([3 + np.exp(0.5 * x), 2 + 2 * x + np.exp(0.5 * x)], axis=-1),
np.stack([3 + np.exp(0.5 * x), -1 + x + np.exp(0.5 * x)], axis=-1),
],
axis=-2,
)
eig = ss_h_circle(
f,
num_vectors=2,
max_order=8,
circle_n_points=128, # number of integration points
circle_radius=3, # radius of the contour
circle_center=0, # center of the contour
)
print(f"Eigenvalues: {eig.eigval}") # eigenvalues inside the contour
print(f"Eigenvectors: {eig.eigvec}") # corresponding eigenvectors
print(f"|f(λ)v|/|f(λ)||v|: {score(f(eig.eigval), eig.eigvec)}")
Eigenvalues: [-3.+3.19507247e-15j]
Eigenvectors: [[-0.45042759-0.61296714j]
[-0.38438888-0.52309795j]]
|f(λ)v|/|f(λ)||v|: [1.37836544e-15]
- Batch calculation (function and/or contour) is supported.
- Steps until SVD are batched. Function evaluations are batched (called only once).
- Only the final step (solving small generalized eigenvalue problem) is not batched because the size of the eigenvalue problem (the number of eigenvalues in the contour) might be different and moreover
scipy.linalg.eigdoes not support batch calculation.
- Since random matrices
U,Vare used in the algorithm, the results may vary slightly on each run.np.random.Generatorcan be passed to control the randomness. - To get zeros of an analytic function, set
lambda x: f(x)[..., None, None]as an argument. The SS-Hankel method for 1x1 matrix is completely equivalent to the Kravanja (1999)'s derivative-free root-finding method. - The default parameters are set to be impractically small. Consider increasing
circle_n_pointsandmax_orderbased on the problem andnum_vectorsbased on the matrix size. - The number of eigenvalues (zeros) inside the contour is estimated by evaluating the numerical rank of the Hankel matrix. By default the singular values below the largest gap between singular values are considered meaningless, as propsed in Xiao (2016), but the behaviour can be controlled by manually setting
rtol.atol(default:1e-6) is useful in the case when no eigenvalues are inside the contour.
CLI Usage
> ss-hankel "{{3+Exp[x/2],2+2x+Exp[x/2]},{3+Exp[x/2],-1+x+Exp[x/2]}}" --circle-radius 4
eigenvalues:
[-3.-2.29788612e-15j]
eigenvectors (columns):
[[0.35283836-0.67388339j]
[0.30110753-0.57508306j]]
|F(λ)v|/|F(λ)||v|:
[9.82824873e-16]
singular_values:
[1.36659229e-01 5.51578001e-17 3.11252713e-17 2.25070948e-17
1.05446714e-17 9.42202841e-18 6.28427578e-18 2.84988862e-18]
References
- Asakura, J., Sakurai, T., Tadano, H., Ikegami, T., & Kimura, K. (2009). A numerical method for nonlinear eigenvalue problems using contour integrals. JSIAM Letters, 1, 52–55.
- Kravanja, P., & Van Barel, M. (1999). A Derivative-Free Algorithm for Computing Zeros of Analytic Functions. Computing (Vienna/New York), 63, 69–91.
- Xiao, J., Meng, S., Zhang, C., & Zheng, C. (2016). Resolvent sampling based Rayleigh-Ritz method for large-scale nonlinear eigenvalue problems. Computer Methods in Applied Mechanics and Engineering, 310, 33–57.
Alternatives
Zeros of analytic functions
- rparini/cxroots: Find all the roots (zeros) of a complex analytic function within a given contour in the complex plane.
- nennigb/polze: A python package to locate poles and zeros of a meromorphic function with their multiplicities
- Spectral-Analysis-UPB/PyZEAL: Project dealing with the numerical calculation of zeros, poles and residues of holomorphic and meromorphic functions. It aspires to be a PYthon ZEAL (ZEros of AnaLytic functions, a Fortran90 package) successor.
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Credits
This package was created with Copier and the browniebroke/pypackage-template project template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ss_hankel-1.0.0.tar.gz.
File metadata
- Download URL: ss_hankel-1.0.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69b5d9f5bf3aeffc44b83649e50be6984323bfb42d610dc88df590b91708db77
|
|
| MD5 |
b0222fadfde0789dc7242f57225b24d3
|
|
| BLAKE2b-256 |
a0d3c182b4724f6c632d8b1f0dd52fd24705ca4bed581e22107bf6a789371373
|
Provenance
The following attestation bundles were made for ss_hankel-1.0.0.tar.gz:
Publisher:
ci.yml on 34j/ss-hankel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ss_hankel-1.0.0.tar.gz -
Subject digest:
69b5d9f5bf3aeffc44b83649e50be6984323bfb42d610dc88df590b91708db77 - Sigstore transparency entry: 219897066
- Sigstore integration time:
-
Permalink:
34j/ss-hankel@6cd6ff18fe75e1e8f4d2bf3ff31b5e4121643666 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/34j
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6cd6ff18fe75e1e8f4d2bf3ff31b5e4121643666 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ss_hankel-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ss_hankel-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7979cdd3bbbc948dea59780c102eabad95cb82fa39de392d77f73422d6a3251e
|
|
| MD5 |
d51e4111d5de9ba7b974326031a2142f
|
|
| BLAKE2b-256 |
a4ca1e71aa137f3c949b8f1685997fed85aabed8ce7cb70df7d9f5ecce78a8b6
|
Provenance
The following attestation bundles were made for ss_hankel-1.0.0-py3-none-any.whl:
Publisher:
ci.yml on 34j/ss-hankel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ss_hankel-1.0.0-py3-none-any.whl -
Subject digest:
7979cdd3bbbc948dea59780c102eabad95cb82fa39de392d77f73422d6a3251e - Sigstore transparency entry: 219897068
- Sigstore integration time:
-
Permalink:
34j/ss-hankel@6cd6ff18fe75e1e8f4d2bf3ff31b5e4121643666 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/34j
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6cd6ff18fe75e1e8f4d2bf3ff31b5e4121643666 -
Trigger Event:
push
-
Statement type: