Keep consistent order of eigenvalues and eigenvectors of successive eigenvalue/vector problems based on the inital ordering of eigenvalues from low to high by matching closest eigenvectors and eigenvalues.
Project description
eigenshuffle
Adapted from code by bmachiel, which in turn was based on matlab eigenshuffle.
Consistently sort eigenvalues and eigenvectors of a series of matrices based on initial ordering from low to high.
Includes eigenshuffle_eig
and eigenshuffle_eigh
for non-hermitian and hermitian matrices, respectively.
Installation
Install from pypi with:
pip install eigenshuffle
or clone repo and install with pip
or directly install from GitHub with:
pip install git+https://github.com/ograsdijk/CeNTREX-trajectories
Example
import numpy as np
import numpy.typing as npt
import matplotlib.pyplot as plt
from eigenshuffle import eigenshuffle_eig
def eigenvalue_function(
t: float,
) -> npt.NDArray[np.float_]:
return np.array(
[
[1, 2 * t + 1, t**2, t**3],
[2 * t + 1, 2 - t, t**2, 1 - t**3],
[t**2, t**2, 3 - 2 * t, t**2],
[t**3, 1 - t**3, t**2, 4 - 3 * t],
]
)
tseq = np.arange(-1, 1.1, 0.1)
Aseq = np.array([eigenvalue_function(ti) for ti in tseq])
e, v = np.linalg.eig(Aseq)
es, vs = eigenshuffle_eig(Aseq)
# sorting original eig result from low to high
v[np.argsort(e)]
e = np.sort(e)
fig, ax = plt.subplots()
lines = ax.plot(tseq, e)
for i in range(ei.shape[-1]):
ax.plot(tseq, ei.real[:, i], "--", color=lines[i].get_color())
# for generating the legend
line1 = plt.Line2D([0, 1], [0, 1], linestyle="-", color="black")
line2 = plt.Line2D([0, 1], [0, 1], linestyle="--", color="black")
ax.set_xlabel("t")
ax.set_ylabel("eigenvalue")
ax.legend([line1, line2], ["sorted", "eigenshuffle"])
ax.grid()
Here the eigenvalues are consistently ordered, and are not switching positions after a level crossing (around t=0.3) when using eigenshuffle
.
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
File details
Details for the file eigenshuffle-0.1.0.tar.gz
.
File metadata
- Download URL: eigenshuffle-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.2 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7ba9ee7ab186c695aed7402f46653b606aa06118a1562c20862db4b71e8d973 |
|
MD5 | 60bf88e08b809ce00beacc78b08c3f49 |
|
BLAKE2b-256 | db3a65c0ea9bfdd0d1dda73628759b47cd8141ca5183787cb1dd476565b5f826 |
File details
Details for the file eigenshuffle-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: eigenshuffle-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.2 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40188e28fcd3292ee440a46f75ecc74fa077e116502c07295b6584e889f6f1f6 |
|
MD5 | 922bda95b29198d255648d0ec61ab238 |
|
BLAKE2b-256 | 64b845bf4c58a6427923dc5cc59bf39cc4aaaeec908ab427d3ab582e7a89aab6 |