freealg 0.7.16__py3-none-any.whl → 0.7.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- freealg/__init__.py +8 -6
- freealg/__version__.py +1 -1
- freealg/_algebraic_form/_branch_points.py +18 -18
- freealg/_algebraic_form/_continuation_algebraic.py +13 -13
- freealg/_algebraic_form/_cusp.py +15 -15
- freealg/_algebraic_form/_cusp_wrap.py +6 -6
- freealg/_algebraic_form/_decompress.py +16 -16
- freealg/_algebraic_form/_decompress4.py +31 -31
- freealg/_algebraic_form/_decompress5.py +23 -23
- freealg/_algebraic_form/_decompress6.py +13 -13
- freealg/_algebraic_form/_decompress7.py +15 -15
- freealg/_algebraic_form/_decompress8.py +17 -17
- freealg/_algebraic_form/_decompress9.py +18 -18
- freealg/_algebraic_form/_decompress_new.py +17 -17
- freealg/_algebraic_form/_decompress_new_2.py +57 -57
- freealg/_algebraic_form/_decompress_util.py +10 -10
- freealg/_algebraic_form/_decompressible.py +292 -0
- freealg/_algebraic_form/_edge.py +10 -10
- freealg/_algebraic_form/_homotopy4.py +9 -9
- freealg/_algebraic_form/_homotopy5.py +9 -9
- freealg/_algebraic_form/_support.py +19 -19
- freealg/_algebraic_form/algebraic_form.py +262 -468
- freealg/_base_form.py +401 -0
- freealg/_free_form/__init__.py +1 -4
- freealg/_free_form/_density_util.py +1 -1
- freealg/_free_form/_plot_util.py +3 -511
- freealg/_free_form/free_form.py +8 -367
- freealg/_util.py +59 -11
- freealg/distributions/__init__.py +2 -1
- freealg/distributions/_base_distribution.py +163 -0
- freealg/distributions/_chiral_block.py +137 -11
- freealg/distributions/_compound_poisson.py +168 -64
- freealg/distributions/_deformed_marchenko_pastur.py +137 -88
- freealg/distributions/_deformed_wigner.py +92 -40
- freealg/distributions/_fuss_catalan.py +269 -0
- freealg/distributions/_kesten_mckay.py +4 -130
- freealg/distributions/_marchenko_pastur.py +8 -196
- freealg/distributions/_meixner.py +4 -130
- freealg/distributions/_wachter.py +4 -130
- freealg/distributions/_wigner.py +10 -127
- freealg/visualization/__init__.py +2 -2
- freealg/visualization/{_rgb_hsv.py → _domain_coloring.py} +37 -29
- freealg/visualization/_plot_util.py +513 -0
- {freealg-0.7.16.dist-info → freealg-0.7.18.dist-info}/METADATA +1 -1
- freealg-0.7.18.dist-info/RECORD +74 -0
- freealg-0.7.16.dist-info/RECORD +0 -69
- /freealg/{_free_form/_sample.py → _sample.py} +0 -0
- /freealg/{_free_form/_support.py → _support.py} +0 -0
- {freealg-0.7.16.dist-info → freealg-0.7.18.dist-info}/WHEEL +0 -0
- {freealg-0.7.16.dist-info → freealg-0.7.18.dist-info}/licenses/AUTHORS.txt +0 -0
- {freealg-0.7.16.dist-info → freealg-0.7.18.dist-info}/licenses/LICENSE.txt +0 -0
- {freealg-0.7.16.dist-info → freealg-0.7.18.dist-info}/top_level.txt +0 -0
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
# =======
|
|
13
13
|
|
|
14
14
|
import numpy
|
|
15
|
+
from ..visualization._plot_util import plot_density
|
|
15
16
|
from .._algebraic_form._sheets_util import _pick_physical_root_scalar
|
|
17
|
+
from ._base_distribution import BaseDistribution
|
|
16
18
|
|
|
17
19
|
__all__ = ['DeformedMarchenkoPastur']
|
|
18
20
|
|
|
@@ -21,9 +23,45 @@ __all__ = ['DeformedMarchenkoPastur']
|
|
|
21
23
|
# Deformed Marchenko Pastur
|
|
22
24
|
# =========================
|
|
23
25
|
|
|
24
|
-
class DeformedMarchenkoPastur(
|
|
26
|
+
class DeformedMarchenkoPastur(BaseDistribution):
|
|
25
27
|
"""
|
|
26
|
-
Deformed Marchenko-Pastur
|
|
28
|
+
Deformed Marchenko-Pastur distribution
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
|
|
33
|
+
t1, t2 : float
|
|
34
|
+
Jump sizes (must be > 0). For PSD-like support, keep them > 0.
|
|
35
|
+
|
|
36
|
+
w1 : float
|
|
37
|
+
Mixture weight in (0, 1) for ``t1``. Second weight is ``1-w1``.
|
|
38
|
+
|
|
39
|
+
c : float
|
|
40
|
+
Ratio parameter of Marchenko-Pastur distribution, must be > 0.
|
|
41
|
+
|
|
42
|
+
Methods
|
|
43
|
+
-------
|
|
44
|
+
|
|
45
|
+
density
|
|
46
|
+
Spectral density of distribution.
|
|
47
|
+
|
|
48
|
+
roots
|
|
49
|
+
Roots of polynomial implicitly representing Stieltjes transform
|
|
50
|
+
|
|
51
|
+
stieltjes
|
|
52
|
+
Stieltjes transform
|
|
53
|
+
|
|
54
|
+
support
|
|
55
|
+
Support intervals of distribution
|
|
56
|
+
|
|
57
|
+
sample
|
|
58
|
+
Sample from distribution.
|
|
59
|
+
|
|
60
|
+
matrix
|
|
61
|
+
Generate matrix with its empirical spectral density of distribution
|
|
62
|
+
|
|
63
|
+
poly
|
|
64
|
+
Polynomial coefficients implicitly representing the Stieltjes
|
|
27
65
|
|
|
28
66
|
Notes
|
|
29
67
|
-----
|
|
@@ -84,6 +122,14 @@ class DeformedMarchenkoPastur(object):
|
|
|
84
122
|
self.w1 = w1
|
|
85
123
|
self.c = c
|
|
86
124
|
|
|
125
|
+
# Bounds for smallest and largest eigenvalues
|
|
126
|
+
if c > 1.0:
|
|
127
|
+
# In this case, there is an atom at the origin
|
|
128
|
+
self.lam_lb = 0.0
|
|
129
|
+
else:
|
|
130
|
+
self.lam_lb = numpy.min([t1, t2]) * (1 - numpy.sqrt(c))**2
|
|
131
|
+
self.lam_ub = numpy.max([t1, t2]) * (1 + numpy.sqrt(c))**2
|
|
132
|
+
|
|
87
133
|
# ====================
|
|
88
134
|
# roots cubic u scalar
|
|
89
135
|
# ====================
|
|
@@ -105,8 +151,6 @@ class DeformedMarchenkoPastur(object):
|
|
|
105
151
|
mu1 = w1 * t1 + w2 * t2
|
|
106
152
|
|
|
107
153
|
# Cubic coefficients for u:
|
|
108
|
-
# (z t1 t2) u^3 + ( z(t1+t2) + t1 t2(1-c) ) u^2
|
|
109
|
-
# + ( z + (t1+t2) - c*mu1 ) u + 1 = 0
|
|
110
154
|
c3 = z * (t1 * t2)
|
|
111
155
|
c2 = z * (t1 + t2) + (t1 * t2) * (1.0 - c)
|
|
112
156
|
c1 = z + (t1 + t2) - c * mu1
|
|
@@ -138,10 +182,7 @@ class DeformedMarchenkoPastur(object):
|
|
|
138
182
|
d1 = 1.0 + t1 * u
|
|
139
183
|
d2 = 1.0 + t2 * u
|
|
140
184
|
|
|
141
|
-
# f(u) = -1/u + c*(w1*t1/d1 + w2*t2/d2) - z
|
|
142
185
|
f = (-1.0 / u) + c * (w1 * t1 / d1 + w2 * t2 / d2) - z
|
|
143
|
-
|
|
144
|
-
# f'(u) = 1/u^2 - c*(w1*t1^2/d1^2 + w2*t2^2/d2^2)
|
|
145
186
|
fp = (1.0 / (u * u)) - c * (w1 * (t1 * t1) / (d1 * d1) +
|
|
146
187
|
w2 * (t2 * t2) / (d2 * d2))
|
|
147
188
|
|
|
@@ -159,6 +200,8 @@ class DeformedMarchenkoPastur(object):
|
|
|
159
200
|
|
|
160
201
|
def stieltjes(self, z, max_iter=100, tol=1e-12):
|
|
161
202
|
"""
|
|
203
|
+
Stieltjes transform
|
|
204
|
+
|
|
162
205
|
Physical/Herglotz branch of m(z) for \\mu = H \\boxtimes MP_c with
|
|
163
206
|
H = w_1 \\delta_{t_1} + (1-w_1) \\delta_{t_2}.
|
|
164
207
|
Fast masked Newton in u (companion Stieltjes), keeping z's original
|
|
@@ -246,89 +289,99 @@ class DeformedMarchenkoPastur(object):
|
|
|
246
289
|
# density
|
|
247
290
|
# =======
|
|
248
291
|
|
|
249
|
-
def density(self, x, eta=1e-3
|
|
292
|
+
def density(self, x=None, eta=1e-3, ac_only=True, plot=False, latex=False,
|
|
293
|
+
save=False, eig=None):
|
|
250
294
|
"""
|
|
251
|
-
Density
|
|
252
|
-
|
|
253
|
-
Notes:
|
|
254
|
-
- Do not warm-start across x<0 (MP-type support is >=0).
|
|
255
|
-
- Reset warm-start when previous u is (nearly) real.
|
|
256
|
-
- If Newton lands on a non-Herglotz root, fall back to cubic roots +
|
|
257
|
-
pick.
|
|
258
|
-
"""
|
|
259
|
-
|
|
260
|
-
# Unpack parameters
|
|
261
|
-
t1 = self.t1
|
|
262
|
-
t2 = self.t2
|
|
263
|
-
w1 = self.w1
|
|
264
|
-
c = self.c
|
|
265
|
-
|
|
266
|
-
x = numpy.asarray(x, dtype=numpy.float64)
|
|
267
|
-
rho = numpy.zeros_like(x, dtype=numpy.float64)
|
|
295
|
+
Density of distribution.
|
|
268
296
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
raise ValueError("c must be >= 0.")
|
|
272
|
-
if c == 0.0:
|
|
273
|
-
# Degenerate: μ = H when c=0, so m(z)=E[1/(t-z)] and rho from Im m.
|
|
274
|
-
z = x + 1j * float(eta)
|
|
275
|
-
w2 = 1.0 - w1
|
|
276
|
-
m = (w1 / (t1 - z)) + (w2 / (t2 - z))
|
|
277
|
-
rho = numpy.maximum(numpy.imag(m) / numpy.pi, 0.0)
|
|
278
|
-
return rho
|
|
297
|
+
Parameters
|
|
298
|
+
----------
|
|
279
299
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return rho
|
|
300
|
+
x : numpy.array, default=None
|
|
301
|
+
The locations where density is evaluated at. If `None`, an interval
|
|
302
|
+
slightly larger than the supp interval of the spectral density
|
|
303
|
+
is used.
|
|
285
304
|
|
|
286
|
-
|
|
305
|
+
rho : numpy.array, default=None
|
|
306
|
+
Density. If `None`, it will be computed.
|
|
287
307
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
inv[order] = numpy.arange(order.size)
|
|
308
|
+
eta : float, default=1e-3
|
|
309
|
+
The offset :math:`\\eta` from the real axis where the density
|
|
310
|
+
is evaluated using Plemelj formula at :math:`z = x + i \\eta`.
|
|
292
311
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
zf = z.ravel()
|
|
312
|
+
ac_only : bool, default=True
|
|
313
|
+
If `True`, it returns the absolutely-continuous part of density.
|
|
296
314
|
|
|
297
|
-
|
|
298
|
-
|
|
315
|
+
plot : bool, default=False
|
|
316
|
+
If `True`, density is plotted.
|
|
299
317
|
|
|
300
|
-
|
|
301
|
-
|
|
318
|
+
latex : bool, default=False
|
|
319
|
+
If `True`, the plot is rendered using LaTeX. This option is
|
|
320
|
+
relevant only if ``plot=True``.
|
|
302
321
|
|
|
303
|
-
|
|
322
|
+
save : bool, default=False
|
|
323
|
+
If not `False`, the plot is saved. If a string is given, it is
|
|
324
|
+
assumed to the save filename (with the file extension). This option
|
|
325
|
+
is relevant only if ``plot=True``.
|
|
304
326
|
|
|
305
|
-
|
|
306
|
-
|
|
327
|
+
eig : numpy.array, default=None
|
|
328
|
+
A collection of eigenvalues to compare to via histogram. This
|
|
329
|
+
option is relevant only if ``plot=True``.
|
|
307
330
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (u_prev is None) or (abs(u_prev.imag) <= imag_eps):
|
|
311
|
-
ui0 = -1.0 / zi
|
|
312
|
-
else:
|
|
313
|
-
ui0 = complex(u_prev)
|
|
331
|
+
Returns
|
|
332
|
+
-------
|
|
314
333
|
|
|
315
|
-
|
|
334
|
+
rho : numpy.array
|
|
335
|
+
Density.
|
|
316
336
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
if (not numpy.isfinite(ui)) or (ui.imag <= 0.0):
|
|
320
|
-
u_roots = self._roots_cubic_u_scalar(zi)
|
|
321
|
-
ui = _pick_physical_root_scalar(zi, u_roots)
|
|
337
|
+
Notes
|
|
338
|
+
-----
|
|
322
339
|
|
|
323
|
-
|
|
324
|
-
|
|
340
|
+
* Do not warm-start across x<0 (MP-type support is >=0).
|
|
341
|
+
* Reset warm-start when previous u is (nearly) real.
|
|
342
|
+
* If Newton lands on a non-Herglotz root, fall back to cubic roots +
|
|
343
|
+
pick.
|
|
325
344
|
|
|
326
|
-
|
|
327
|
-
|
|
345
|
+
If ac_only is True and c < 1, subtract the smeared atom at zero of mass
|
|
346
|
+
(1-c) for visualization.
|
|
347
|
+
"""
|
|
328
348
|
|
|
329
|
-
#
|
|
330
|
-
|
|
331
|
-
|
|
349
|
+
# Create x if not given
|
|
350
|
+
if x is None:
|
|
351
|
+
radius = 0.5 * (self.lam_ub - self.lam_lb)
|
|
352
|
+
center = 0.5 * (self.lam_ub + self.lam_lb)
|
|
353
|
+
scale = 1.25
|
|
354
|
+
x_min = numpy.floor(center - radius * scale)
|
|
355
|
+
x_max = numpy.ceil(center + radius * scale)
|
|
356
|
+
x = numpy.linspace(x_min, x_max, 500)
|
|
357
|
+
else:
|
|
358
|
+
x = numpy.asarray(x, dtype=numpy.float64)
|
|
359
|
+
|
|
360
|
+
z = x + 1j * float(eta)
|
|
361
|
+
m = self.stieltjes(z)
|
|
362
|
+
rho = numpy.imag(m) / numpy.pi
|
|
363
|
+
|
|
364
|
+
# Atoms
|
|
365
|
+
atoms = None
|
|
366
|
+
if self.c > 1.0:
|
|
367
|
+
atom_loc = 0.0
|
|
368
|
+
atom_w = 1.0 - 1.0 / self.c
|
|
369
|
+
atoms = [(atom_loc, atom_w)]
|
|
370
|
+
|
|
371
|
+
# Optional: remove the atom at zero (only for visualization of AC part)
|
|
372
|
+
if (atoms is not None) and (ac_only is True):
|
|
373
|
+
atom = atom_w * (float(eta) / numpy.pi) / \
|
|
374
|
+
(x * x + float(eta) * float(eta))
|
|
375
|
+
rho = rho - atom
|
|
376
|
+
rho = numpy.maximum(rho, 0.0)
|
|
377
|
+
|
|
378
|
+
if plot:
|
|
379
|
+
if eig is not None:
|
|
380
|
+
label = 'Theoretical'
|
|
381
|
+
else:
|
|
382
|
+
label = ''
|
|
383
|
+
plot_density(x, rho, atoms=atoms, label=label, latex=latex,
|
|
384
|
+
save=save, eig=eig)
|
|
332
385
|
|
|
333
386
|
return rho
|
|
334
387
|
|
|
@@ -338,8 +391,7 @@ class DeformedMarchenkoPastur(object):
|
|
|
338
391
|
|
|
339
392
|
def roots(self, z):
|
|
340
393
|
"""
|
|
341
|
-
|
|
342
|
-
m).
|
|
394
|
+
Roots of polynomial implicitly representing Stieltjes transform
|
|
343
395
|
"""
|
|
344
396
|
|
|
345
397
|
# Unpack parameters
|
|
@@ -383,6 +435,8 @@ class DeformedMarchenkoPastur(object):
|
|
|
383
435
|
def support(self, eta=2e-4, n_probe=4000, thr=5e-4, x_max=None, x_pad=0.05,
|
|
384
436
|
method='quartic'):
|
|
385
437
|
"""
|
|
438
|
+
Support intervals of distribution
|
|
439
|
+
|
|
386
440
|
Estimate support intervals of μ = H \\boxtimes MP_c where H = w1
|
|
387
441
|
\\delta_{t1} + (1-w1) \\delta_{t2}.
|
|
388
442
|
|
|
@@ -515,8 +569,7 @@ class DeformedMarchenkoPastur(object):
|
|
|
515
569
|
return cuts
|
|
516
570
|
method = 'probe'
|
|
517
571
|
|
|
518
|
-
#
|
|
519
|
-
# Heuristic x-range
|
|
572
|
+
# Legacy probing (kept as fallback / comparison). Heuristic x-range
|
|
520
573
|
tmax = float(max(abs(t1), abs(t2), 1e-12))
|
|
521
574
|
if x_max is None:
|
|
522
575
|
s = (1.0 + numpy.sqrt(max(c, 0.0))) ** 2
|
|
@@ -679,11 +732,10 @@ class DeformedMarchenkoPastur(object):
|
|
|
679
732
|
|
|
680
733
|
def poly(self):
|
|
681
734
|
"""
|
|
682
|
-
|
|
683
|
-
MP model.
|
|
735
|
+
Polynomial coefficients implicitly representing the Stieltjes
|
|
684
736
|
|
|
685
737
|
This is the eliminated polynomial in m (not underline{m}).
|
|
686
|
-
|
|
738
|
+
coeffs[i, j] is the coefficient of z^i m^j.
|
|
687
739
|
Shape is (3, 4).
|
|
688
740
|
"""
|
|
689
741
|
|
|
@@ -700,24 +752,21 @@ class DeformedMarchenkoPastur(object):
|
|
|
700
752
|
# NOTE: This polynomial is defined up to a global nonzero factor.
|
|
701
753
|
# The scaling below is chosen so that the m^3 term is (-c^3 t1 t2) z^2.
|
|
702
754
|
|
|
703
|
-
#
|
|
755
|
+
# Coefficients of m^3:
|
|
704
756
|
a[2, 3] = -(c**3) * t1 * t2
|
|
705
757
|
|
|
706
|
-
#
|
|
758
|
+
# Coefficients of m^2:
|
|
707
759
|
a[0, 2] = 0.0
|
|
708
760
|
a[1, 2] = -(2.0 * (c**3) * t1 * t2 - 2.0 * (c**2) * t1 * t2)
|
|
709
761
|
a[2, 2] = -(c**2) * (t1 + t2)
|
|
710
762
|
|
|
711
|
-
#
|
|
712
|
-
# -c * [ c^2 t1 t2 - 2 c t1 t2 + t1 t2
|
|
713
|
-
# + z^2
|
|
714
|
-
# + z*( -c*w1*t1 + 2c*t1 + c*w1*t2 + c*t2 - t1 - t2 ) ]
|
|
763
|
+
# Coefficients of m^1:
|
|
715
764
|
a[0, 1] = -c * ((c**2) * t1 * t2 - 2.0 * c * t1 * t2 + t1 * t2)
|
|
716
765
|
a[1, 1] = -c * ((-c * w1 * t1) + (2.0 * c * t1) + (c * w1 * t2) +
|
|
717
766
|
(c * t2) - t1 - t2)
|
|
718
767
|
a[2, 1] = -c * (1.0)
|
|
719
768
|
|
|
720
|
-
#
|
|
769
|
+
# Coefficients of m^0
|
|
721
770
|
a[0, 0] = c * (1.0 - c) * (w2 * t1 + w1 * t2)
|
|
722
771
|
a[1, 0] = -c
|
|
723
772
|
a[2, 0] = 0.0
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
# =======
|
|
13
13
|
|
|
14
14
|
import numpy
|
|
15
|
+
from ..visualization._plot_util import plot_density
|
|
15
16
|
from .._algebraic_form._sheets_util import _pick_physical_root_scalar
|
|
17
|
+
from ._base_distribution import BaseDistribution
|
|
16
18
|
|
|
17
19
|
__all__ = ['DeformedWigner']
|
|
18
20
|
|
|
@@ -21,9 +23,33 @@ __all__ = ['DeformedWigner']
|
|
|
21
23
|
# Deformed Wigner
|
|
22
24
|
# ===============
|
|
23
25
|
|
|
24
|
-
class DeformedWigner(
|
|
26
|
+
class DeformedWigner(BaseDistribution):
|
|
25
27
|
"""
|
|
26
|
-
Deformed Wiger
|
|
28
|
+
Deformed Wiger distribution
|
|
29
|
+
|
|
30
|
+
Methods
|
|
31
|
+
-------
|
|
32
|
+
|
|
33
|
+
density
|
|
34
|
+
Spectral density of distribution.
|
|
35
|
+
|
|
36
|
+
roots
|
|
37
|
+
Roots of polynomial implicitly representing Stieltjes transform
|
|
38
|
+
|
|
39
|
+
stieltjes
|
|
40
|
+
Stieltjes transform
|
|
41
|
+
|
|
42
|
+
support
|
|
43
|
+
Support intervals of distribution
|
|
44
|
+
|
|
45
|
+
sample
|
|
46
|
+
Sample from distribution.
|
|
47
|
+
|
|
48
|
+
matrix
|
|
49
|
+
Generate matrix with its empirical spectral density of distribution
|
|
50
|
+
|
|
51
|
+
poly
|
|
52
|
+
Polynomial coefficients implicitly representing the Stieltjes
|
|
27
53
|
"""
|
|
28
54
|
|
|
29
55
|
# ====
|
|
@@ -43,6 +69,10 @@ class DeformedWigner(object):
|
|
|
43
69
|
self.w1 = w1
|
|
44
70
|
self.sigma = sigma
|
|
45
71
|
|
|
72
|
+
# Bounds for smallest and largest eigenvalues
|
|
73
|
+
self.lam_lb = numpy.min([t1, t2]) - 2.0 * self.sigma
|
|
74
|
+
self.lam_ub = numpy.max([t1, t2]) + 2.0 * self.sigma
|
|
75
|
+
|
|
46
76
|
# ==================
|
|
47
77
|
# roots cubic scalar
|
|
48
78
|
# ==================
|
|
@@ -135,53 +165,74 @@ class DeformedWigner(object):
|
|
|
135
165
|
# density
|
|
136
166
|
# =======
|
|
137
167
|
|
|
138
|
-
def density(self, x, eta=1e-3
|
|
139
|
-
|
|
168
|
+
def density(self, x=None, eta=1e-3, plot=False, latex=False, save=False,
|
|
169
|
+
eig=None):
|
|
140
170
|
"""
|
|
171
|
+
Density of distribution.
|
|
141
172
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
t2 = self.t2
|
|
145
|
-
w1 = self.w1
|
|
146
|
-
sigma = self.sigma
|
|
173
|
+
Parameters
|
|
174
|
+
----------
|
|
147
175
|
|
|
148
|
-
x
|
|
149
|
-
|
|
176
|
+
x : numpy.array, default=None
|
|
177
|
+
The locations where density is evaluated at. If `None`, an interval
|
|
178
|
+
slightly larger than the supp interval of the spectral density
|
|
179
|
+
is used.
|
|
150
180
|
|
|
151
|
-
|
|
152
|
-
|
|
181
|
+
rho : numpy.array, default=None
|
|
182
|
+
Density. If `None`, it will be computed.
|
|
153
183
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
184
|
+
eta : float, default=1e-3
|
|
185
|
+
The offset :math:`\\eta` from the real axis where the density
|
|
186
|
+
is evaluated using Plemelj formula at :math:`z = x + i \\eta`.
|
|
187
|
+
|
|
188
|
+
plot : bool, default=False
|
|
189
|
+
If `True`, density is plotted.
|
|
190
|
+
|
|
191
|
+
latex : bool, default=False
|
|
192
|
+
If `True`, the plot is rendered using LaTeX. This option is
|
|
193
|
+
relevant only if ``plot=True``.
|
|
194
|
+
|
|
195
|
+
save : bool, default=False
|
|
196
|
+
If not `False`, the plot is saved. If a string is given, it is
|
|
197
|
+
assumed to the save filename (with the file extension). This option
|
|
198
|
+
is relevant only if ``plot=True``.
|
|
161
199
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
200
|
+
eig : numpy.array, default=None
|
|
201
|
+
A collection of eigenvalues to compare to via histogram. This
|
|
202
|
+
option is relevant only if ``plot=True``.
|
|
165
203
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
w1 * (sigma * sigma) / (d1 * d1) +
|
|
169
|
-
(1.0 - w1) * (sigma * sigma) / (d2 * d2)
|
|
170
|
-
)
|
|
204
|
+
Returns
|
|
205
|
+
-------
|
|
171
206
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
mi = mi2
|
|
176
|
-
break
|
|
177
|
-
mi = mi2
|
|
207
|
+
rho : numpy.array
|
|
208
|
+
Density.
|
|
209
|
+
"""
|
|
178
210
|
|
|
179
|
-
|
|
180
|
-
|
|
211
|
+
# Create x if not given
|
|
212
|
+
if x is None:
|
|
213
|
+
radius = 0.5 * (self.lam_ub - self.lam_lb)
|
|
214
|
+
center = 0.5 * (self.lam_ub + self.lam_lb)
|
|
215
|
+
scale = 1.25
|
|
216
|
+
x_min = numpy.floor(center - radius * scale)
|
|
217
|
+
x_max = numpy.ceil(center + radius * scale)
|
|
218
|
+
x = numpy.linspace(x_min, x_max, 500)
|
|
219
|
+
else:
|
|
220
|
+
x = numpy.asarray(x, dtype=numpy.float64)
|
|
181
221
|
|
|
182
|
-
|
|
222
|
+
z = x + 1j * float(eta)
|
|
223
|
+
m = self.stieltjes(z)
|
|
183
224
|
rho = numpy.imag(m) / numpy.pi
|
|
225
|
+
|
|
184
226
|
rho = numpy.maximum(rho, 0.0)
|
|
227
|
+
|
|
228
|
+
if plot:
|
|
229
|
+
if eig is not None:
|
|
230
|
+
label = 'Theoretical'
|
|
231
|
+
else:
|
|
232
|
+
label = ''
|
|
233
|
+
plot_density(x, rho, atoms=None, label=label, latex=latex,
|
|
234
|
+
save=save, eig=eig)
|
|
235
|
+
|
|
185
236
|
return rho
|
|
186
237
|
|
|
187
238
|
# =====
|
|
@@ -190,6 +241,7 @@ class DeformedWigner(object):
|
|
|
190
241
|
|
|
191
242
|
def roots(self, z):
|
|
192
243
|
"""
|
|
244
|
+
Roots of polynomial implicitly representing Stieltjes transform
|
|
193
245
|
"""
|
|
194
246
|
|
|
195
247
|
z = numpy.asarray(z, dtype=numpy.complex128)
|
|
@@ -213,6 +265,7 @@ class DeformedWigner(object):
|
|
|
213
265
|
|
|
214
266
|
def support(self, y_probe=1e-6):
|
|
215
267
|
"""
|
|
268
|
+
Support intervals of distribution
|
|
216
269
|
"""
|
|
217
270
|
|
|
218
271
|
# Unpack parameters
|
|
@@ -347,10 +400,9 @@ class DeformedWigner(object):
|
|
|
347
400
|
|
|
348
401
|
def poly(self):
|
|
349
402
|
"""
|
|
350
|
-
|
|
351
|
-
Wigner model.
|
|
403
|
+
Polynomial coefficients implicitly representing the Stieltjes
|
|
352
404
|
|
|
353
|
-
|
|
405
|
+
coeffs[i, j] is the coefficient of z^i m^j.
|
|
354
406
|
Shape is (deg_z+1, deg_m+1) = (3, 4).
|
|
355
407
|
"""
|
|
356
408
|
|