Skip to content

Commit e9340eb

Browse files
committed
Addition of mean_adjacent_gap_ratio.
1 parent e06b0b8 commit e9340eb

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v0.2.32
2+
3+
* Addition of `mean_adjacent_gap_ratio` and test.
4+
15
v0.2.22
26

37
* NNSD with spectral unfolding. Implemented and tested.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ The core package is providing strong randomness improving the simulation quality
4747
* Generation of Mixed Gaussian ensembles (Orthogonal) via `Mixed Matrix Ensemble Sampling (MMES) algoritm`
4848
* Extract offdiagonal elements.
4949
* Spectra generation given ensemble.
50-
* Spectral unfolding.
50+
* Robust Spectral unfolding.
5151
* Nearest-Neigbour Spacing Densities (NNSD).
52+
* Adjacent gap ratio.
5253
* Analytic distributions: Wigner semi-circle law, nearest-neigbour spacing.
5354

5455
### Statistics

leymosun/spectral.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,25 @@ def nnsd(eigenvalues: np.array, locations: np.array = np.arange(0.0, 5.0, 0.1)):
185185
density, _locations = pdf(ueigenvalues_nn, locations=locations)
186186
nnsd_densities.append(density)
187187
return np.array(nnsd_densities), np.array(_locations)
188+
189+
190+
def mean_adjacent_gap_ratio(eigenvalues):
191+
"""Compute ratio of adjacent spacing gap ratio
192+
Due to Oganesyan-Huse Phys. Rev. B 75, 155111 (2007)
193+
194+
Args:
195+
eigenvalues: 2D, eigenvalues over repeaded samples.
196+
locations: Centers to compute PDF of NNSD.
197+
198+
Returns:
199+
Mean given ensemble of eigenvalues
200+
201+
"""
202+
adjacent_gap_ratios = []
203+
for eigens in eigenvalues:
204+
eigens_sorted = np.sort(eigens)
205+
spacings = np.diff(eigens_sorted)
206+
adjacent_gap_ratio = np.minimum(spacings[:-1], spacings[1:]) /(np.maximum(spacings[:-1], spacings[1:])+1e-9)
207+
adjacent_gap_ratios.append(np.mean(adjacent_gap_ratio))
208+
bar_adjacent_gap_ratio = np.mean(adjacent_gap_ratios)
209+
return bar_adjacent_gap_ratio

leymosun/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__="0.2.22"
1+
__version__="0.2.32"

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
description="High-Entropy Randomness Research Toolkit. High-Entropy Random Number Generator (HE-RNGs). \
1818
Generation of random matrices in canonical ensembles. Generating of mixed matrix ensembles via \
1919
Mixed Matrix Ensemble Sampling (MMES) algorithm. \
20-
Matrix utilities, spectral analysis tools, analytic expressions from theory and \
20+
Matrix utilities, spectral analysis, spectral unfolding, nearest-neighbor spacing, \
21+
mean adjacent gap ratio, analytic expressions from theory and \
2122
uncertainty quantification tools.",
2223
long_description=long_description,
2324
long_description_content_type="text/markdown",

tests/test_spectral.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
empirical_spectral_density,
55
eigenvalue_on_polynomial,
66
unfold_spectra,
7-
nnsd
7+
nnsd,
8+
mean_adjacent_gap_ratio
89
)
910
from leymosun.matrix import ensemble, mixed_ensemble
1011
from leymosun.gaussian import goe
@@ -60,3 +61,8 @@ def test_nnsd():
6061
sim_e2 = np.array([normal(size=1000) for _ in range(10)])
6162
nnsd_densities, locations = nnsd(sim_e2)
6263
assert nnsd_densities.shape[1] == 48
64+
65+
def test_mean_adjacent_gap_ratio():
66+
sim_e2 = np.array([normal(size=1000) for _ in range(10)])
67+
r = mean_adjacent_gap_ratio(sim_e2)
68+
assert r > 0.0

0 commit comments

Comments
 (0)