freealg 0.1.8__tar.gz → 0.1.10__tar.gz
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-0.1.8 → freealg-0.1.10}/PKG-INFO +1 -1
- {freealg-0.1.8 → freealg-0.1.10}/freealg/__init__.py +2 -1
- freealg-0.1.10/freealg/__version__.py +1 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg/_plot_util.py +55 -2
- {freealg-0.1.8 → freealg-0.1.10}/freealg/_sample.py +8 -1
- {freealg-0.1.8 → freealg-0.1.10}/freealg/distributions/__init__.py +5 -5
- freealg-0.1.8/freealg/distributions/kesten_mckay.py → freealg-0.1.10/freealg/distributions/_kesten_mckay.py +18 -9
- freealg-0.1.8/freealg/distributions/marchenko_pastur.py → freealg-0.1.10/freealg/distributions/_marchenko_pastur.py +14 -4
- freealg-0.1.8/freealg/distributions/meixner.py → freealg-0.1.10/freealg/distributions/_meixner.py +12 -3
- freealg-0.1.8/freealg/distributions/wachter.py → freealg-0.1.10/freealg/distributions/_wachter.py +15 -3
- freealg-0.1.8/freealg/distributions/wigner.py → freealg-0.1.10/freealg/distributions/_wigner.py +12 -3
- {freealg-0.1.8 → freealg-0.1.10}/freealg/freeform.py +10 -11
- {freealg-0.1.8 → freealg-0.1.10}/freealg.egg-info/PKG-INFO +1 -1
- {freealg-0.1.8 → freealg-0.1.10}/freealg.egg-info/SOURCES.txt +5 -5
- freealg-0.1.8/freealg/__version__.py +0 -1
- {freealg-0.1.8 → freealg-0.1.10}/AUTHORS.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/CHANGELOG.rst +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/LICENSE.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/MANIFEST.in +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/README.rst +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg/_chebyshev.py +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg/_damp.py +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg/_decompress.py +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg/_jacobi.py +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg/_pade.py +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg/_util.py +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg.egg-info/dependency_links.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg.egg-info/not-zip-safe +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg.egg-info/requires.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/freealg.egg-info/top_level.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/pyproject.toml +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/requirements.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/setup.cfg +0 -0
- {freealg-0.1.8 → freealg-0.1.10}/setup.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.10"
|
|
@@ -81,6 +81,59 @@ def plot_fit(psi, x_supp, g_supp, g_supp_approx, support, latex=False,
|
|
|
81
81
|
show_and_save=save_status, verbose=True)
|
|
82
82
|
|
|
83
83
|
|
|
84
|
+
# =========
|
|
85
|
+
# auto bins
|
|
86
|
+
# =========
|
|
87
|
+
|
|
88
|
+
def _auto_bins(array, method='scott', factor=5):
|
|
89
|
+
"""
|
|
90
|
+
Automatic choice for the number of bins for the histogram of an array.
|
|
91
|
+
|
|
92
|
+
Parameters
|
|
93
|
+
----------
|
|
94
|
+
|
|
95
|
+
array : numpy.array
|
|
96
|
+
An array for histogram.
|
|
97
|
+
|
|
98
|
+
method : {``'freedman'``, ``'scott'``, ``'sturges'``}, default= ``'scott'``
|
|
99
|
+
Method of choosing number of bins.
|
|
100
|
+
|
|
101
|
+
Returns
|
|
102
|
+
-------
|
|
103
|
+
|
|
104
|
+
num_bins : int
|
|
105
|
+
Number of bins for histogram.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
if method == 'freedman':
|
|
109
|
+
|
|
110
|
+
q75, q25 = numpy.percentile(array, [75, 25])
|
|
111
|
+
iqr = q75 - q25
|
|
112
|
+
bin_width = 2 * iqr / (len(array) ** (1/3))
|
|
113
|
+
|
|
114
|
+
if bin_width == 0:
|
|
115
|
+
# Fallback default
|
|
116
|
+
return
|
|
117
|
+
num_bins = 100
|
|
118
|
+
else:
|
|
119
|
+
num_bins = int(numpy.ceil((array.max() - array.min()) / bin_width))
|
|
120
|
+
|
|
121
|
+
elif method == 'scott':
|
|
122
|
+
|
|
123
|
+
std = numpy.std(array)
|
|
124
|
+
bin_width = 3.5 * std / (len(array) ** (1/3))
|
|
125
|
+
num_bins = int(numpy.ceil((array.max() - array.min()) / bin_width))
|
|
126
|
+
|
|
127
|
+
elif method == 'sturges':
|
|
128
|
+
|
|
129
|
+
num_bins = int(numpy.ceil(numpy.log2(len(array)) + 1))
|
|
130
|
+
|
|
131
|
+
else:
|
|
132
|
+
raise ValueError('"method" is invalid.')
|
|
133
|
+
|
|
134
|
+
return num_bins * factor
|
|
135
|
+
|
|
136
|
+
|
|
84
137
|
# ============
|
|
85
138
|
# plot density
|
|
86
139
|
# ============
|
|
@@ -96,7 +149,7 @@ def plot_density(x, rho, eig=None, support=None, label='',
|
|
|
96
149
|
|
|
97
150
|
if (support is not None) and (eig is not None):
|
|
98
151
|
lam_m, lam_p = support
|
|
99
|
-
bins = numpy.linspace(lam_m, lam_p,
|
|
152
|
+
bins = numpy.linspace(lam_m, lam_p, _auto_bins(eig))
|
|
100
153
|
_ = ax.hist(eig, bins, density=True, color='silver',
|
|
101
154
|
edgecolor='none', label='Histogram')
|
|
102
155
|
else:
|
|
@@ -503,7 +556,7 @@ def plot_samples(x, rho, x_min, x_max, samples, latex=False, save=False):
|
|
|
503
556
|
|
|
504
557
|
fig, ax = plt.subplots(figsize=(6, 3))
|
|
505
558
|
|
|
506
|
-
bins = numpy.linspace(x_min, x_max, samples
|
|
559
|
+
bins = numpy.linspace(x_min, x_max, _auto_bins(samples))
|
|
507
560
|
_ = ax.hist(samples, bins, density=True, color='silver',
|
|
508
561
|
edgecolor='none', label='Samples histogram')
|
|
509
562
|
ax.plot(x, rho, color='black', label='Exact density')
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
# Imports
|
|
11
11
|
# =======
|
|
12
12
|
|
|
13
|
+
import numpy
|
|
13
14
|
from scipy.integrate import cumulative_trapezoid
|
|
14
15
|
from scipy.interpolate import interp1d
|
|
15
16
|
from scipy.stats import qmc
|
|
@@ -35,7 +36,7 @@ def _quantile_func(x, rho):
|
|
|
35
36
|
# qmc sample
|
|
36
37
|
# ==========
|
|
37
38
|
|
|
38
|
-
def qmc_sample(x, rho, num_pts):
|
|
39
|
+
def qmc_sample(x, rho, num_pts, seed=None):
|
|
39
40
|
"""
|
|
40
41
|
Low-discrepancy sampling from a univariate density estimate using
|
|
41
42
|
Quasi-Monte Carlo.
|
|
@@ -52,6 +53,9 @@ def qmc_sample(x, rho, num_pts):
|
|
|
52
53
|
num_pts : int
|
|
53
54
|
Number of sample points to generate from the density estimate.
|
|
54
55
|
|
|
56
|
+
seed : int, default=None
|
|
57
|
+
Seed for random number generator
|
|
58
|
+
|
|
55
59
|
Returns
|
|
56
60
|
-------
|
|
57
61
|
samples : numpy.array, shape (num_pts,)
|
|
@@ -78,6 +82,9 @@ def qmc_sample(x, rho, num_pts):
|
|
|
78
82
|
>>> numpy.allclose(samples.mean(), 0.75, atol=0.02)
|
|
79
83
|
"""
|
|
80
84
|
|
|
85
|
+
if seed is not None:
|
|
86
|
+
numpy.random.rand(seed)
|
|
87
|
+
|
|
81
88
|
quantile = _quantile_func(x, rho)
|
|
82
89
|
engine = qmc.Halton(d=1)
|
|
83
90
|
u = engine.random(num_pts)
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
# under the terms of the license found in the LICENSE.txt file in the root
|
|
7
7
|
# directory of this source tree.
|
|
8
8
|
|
|
9
|
-
from .
|
|
10
|
-
from .
|
|
11
|
-
from .
|
|
12
|
-
from .
|
|
13
|
-
from .
|
|
9
|
+
from ._marchenko_pastur import MarchenkoPastur
|
|
10
|
+
from ._wigner import Wigner
|
|
11
|
+
from ._kesten_mckay import KestenMcKay
|
|
12
|
+
from ._wachter import Wachter
|
|
13
|
+
from ._meixner import Meixner
|
|
14
14
|
|
|
15
15
|
__all__ = ['MarchenkoPastur', 'Wigner', 'KestenMcKay', 'Wachter', 'Meixner']
|
|
@@ -429,8 +429,8 @@ class KestenMcKay(object):
|
|
|
429
429
|
# sample
|
|
430
430
|
# ======
|
|
431
431
|
|
|
432
|
-
def sample(self, size, x_min=None, x_max=None, method='qmc',
|
|
433
|
-
latex=False, save=False):
|
|
432
|
+
def sample(self, size, x_min=None, x_max=None, method='qmc', seed=None,
|
|
433
|
+
plot=False, latex=False, save=False):
|
|
434
434
|
"""
|
|
435
435
|
Sample from distribution.
|
|
436
436
|
|
|
@@ -454,6 +454,9 @@ class KestenMcKay(object):
|
|
|
454
454
|
* ``'mc'``: Monte Carlo
|
|
455
455
|
* ``'qmc'``: Quasi Monte Carlo
|
|
456
456
|
|
|
457
|
+
seed : int, default=None,
|
|
458
|
+
Seed for random number generator.
|
|
459
|
+
|
|
457
460
|
plot : bool, default=False
|
|
458
461
|
If `True`, samples histogram is plotted.
|
|
459
462
|
|
|
@@ -491,6 +494,9 @@ class KestenMcKay(object):
|
|
|
491
494
|
:class: custom-dark
|
|
492
495
|
"""
|
|
493
496
|
|
|
497
|
+
if seed is not None:
|
|
498
|
+
numpy.random.seed(seed)
|
|
499
|
+
|
|
494
500
|
if x_min is None:
|
|
495
501
|
x_min = self.lam_m
|
|
496
502
|
|
|
@@ -537,7 +543,7 @@ class KestenMcKay(object):
|
|
|
537
543
|
# Haar unitary
|
|
538
544
|
# ============
|
|
539
545
|
|
|
540
|
-
def _haar_orthogonal(self, n, k):
|
|
546
|
+
def _haar_orthogonal(self, n, k, seed=None):
|
|
541
547
|
"""
|
|
542
548
|
Haar-distributed O(n) via the Mezzadri QR trick.
|
|
543
549
|
|
|
@@ -559,7 +565,7 @@ class KestenMcKay(object):
|
|
|
559
565
|
uniformly distributed under Haar measure O(n).
|
|
560
566
|
"""
|
|
561
567
|
|
|
562
|
-
rng = numpy.random.default_rng()
|
|
568
|
+
rng = numpy.random.default_rng(seed)
|
|
563
569
|
Z = rng.standard_normal((n, k))
|
|
564
570
|
Q, R = numpy.linalg.qr(Z, mode='reduced') # Q is n by k
|
|
565
571
|
Q *= numpy.sign(numpy.diag(R))
|
|
@@ -570,7 +576,7 @@ class KestenMcKay(object):
|
|
|
570
576
|
# matrix
|
|
571
577
|
# ======
|
|
572
578
|
|
|
573
|
-
def matrix(self, size):
|
|
579
|
+
def matrix(self, size, seed=None):
|
|
574
580
|
"""
|
|
575
581
|
Generate matrix with the spectral density of the distribution.
|
|
576
582
|
|
|
@@ -580,6 +586,9 @@ class KestenMcKay(object):
|
|
|
580
586
|
size : int
|
|
581
587
|
Size :math:`n` of the matrix.
|
|
582
588
|
|
|
589
|
+
seed : int, default=None
|
|
590
|
+
Seed for random number generator.
|
|
591
|
+
|
|
583
592
|
Returns
|
|
584
593
|
-------
|
|
585
594
|
|
|
@@ -621,7 +630,7 @@ class KestenMcKay(object):
|
|
|
621
630
|
https://arxiv.org/abs/2009.11950
|
|
622
631
|
|
|
623
632
|
.. [2] Francesco Mezzadri. How to generate random matrices from the
|
|
624
|
-
classical compact groups. https://arxiv.org/
|
|
633
|
+
classical compact groups. https://arxiv.org/abs/math-ph/0609050
|
|
625
634
|
|
|
626
635
|
Examples
|
|
627
636
|
--------
|
|
@@ -637,12 +646,12 @@ class KestenMcKay(object):
|
|
|
637
646
|
# Uses algorithm 1 . Only if d is even. This is much faster than
|
|
638
647
|
# algorithm 2.
|
|
639
648
|
n = size
|
|
640
|
-
rng = numpy.random.default_rng()
|
|
649
|
+
rng = numpy.random.default_rng(seed)
|
|
641
650
|
m = self.d // 2
|
|
642
651
|
A = numpy.zeros((n, n))
|
|
643
652
|
|
|
644
653
|
for _ in range(m):
|
|
645
|
-
O_ = self._haar_orthogonal(n, n)
|
|
654
|
+
O_ = self._haar_orthogonal(n, n, seed=seed)
|
|
646
655
|
A += O_ + O_.T
|
|
647
656
|
else:
|
|
648
657
|
# Uses algorithm 2. Only when d is odd, but this algorithm works
|
|
@@ -650,7 +659,7 @@ class KestenMcKay(object):
|
|
|
650
659
|
# especially if d is larger. As such, as only use algorithm 1 when
|
|
651
660
|
# d is even and use algorithm 2 for the rest.
|
|
652
661
|
n = size * self.d
|
|
653
|
-
rng = numpy.random.default_rng()
|
|
662
|
+
rng = numpy.random.default_rng(seed)
|
|
654
663
|
|
|
655
664
|
# Deterministic pieces
|
|
656
665
|
k = size
|
|
@@ -436,8 +436,8 @@ class MarchenkoPastur(object):
|
|
|
436
436
|
# sample
|
|
437
437
|
# ======
|
|
438
438
|
|
|
439
|
-
def sample(self, size, x_min=None, x_max=None, method='qmc',
|
|
440
|
-
latex=False, save=False):
|
|
439
|
+
def sample(self, size, x_min=None, x_max=None, method='qmc', seed=None,
|
|
440
|
+
plot=False, latex=False, save=False):
|
|
441
441
|
"""
|
|
442
442
|
Sample from distribution.
|
|
443
443
|
|
|
@@ -461,6 +461,9 @@ class MarchenkoPastur(object):
|
|
|
461
461
|
* ``'mc'``: Monte Carlo
|
|
462
462
|
* ``'qmc'``: Quasi Monte Carlo
|
|
463
463
|
|
|
464
|
+
seed : int, default=None,
|
|
465
|
+
Seed for random number generator.
|
|
466
|
+
|
|
464
467
|
plot : bool, default=False
|
|
465
468
|
If `True`, samples histogram is plotted.
|
|
466
469
|
|
|
@@ -498,6 +501,9 @@ class MarchenkoPastur(object):
|
|
|
498
501
|
:class: custom-dark
|
|
499
502
|
"""
|
|
500
503
|
|
|
504
|
+
if seed is not None:
|
|
505
|
+
numpy.random.seed(seed)
|
|
506
|
+
|
|
501
507
|
if x_min is None:
|
|
502
508
|
x_min = self.lam_m
|
|
503
509
|
|
|
@@ -544,7 +550,7 @@ class MarchenkoPastur(object):
|
|
|
544
550
|
# matrix
|
|
545
551
|
# ======
|
|
546
552
|
|
|
547
|
-
def matrix(self, size):
|
|
553
|
+
def matrix(self, size, seed=None):
|
|
548
554
|
"""
|
|
549
555
|
Generate matrix with the spectral density of the distribution.
|
|
550
556
|
|
|
@@ -554,6 +560,9 @@ class MarchenkoPastur(object):
|
|
|
554
560
|
size : int
|
|
555
561
|
Size :math:`n` of the matrix.
|
|
556
562
|
|
|
563
|
+
seed : int, default=None
|
|
564
|
+
Seed for random number generator.
|
|
565
|
+
|
|
557
566
|
Returns
|
|
558
567
|
-------
|
|
559
568
|
|
|
@@ -570,7 +579,8 @@ class MarchenkoPastur(object):
|
|
|
570
579
|
>>> A = mp.matrix(2000)
|
|
571
580
|
"""
|
|
572
581
|
|
|
573
|
-
|
|
582
|
+
if seed is not None:
|
|
583
|
+
numpy.random.seed(seed)
|
|
574
584
|
|
|
575
585
|
# Parameters
|
|
576
586
|
m = int(size / self.lam)
|
freealg-0.1.8/freealg/distributions/meixner.py → freealg-0.1.10/freealg/distributions/_meixner.py
RENAMED
|
@@ -461,8 +461,8 @@ class Meixner(object):
|
|
|
461
461
|
# sample
|
|
462
462
|
# ======
|
|
463
463
|
|
|
464
|
-
def sample(self, size, x_min=None, x_max=None, method='qmc',
|
|
465
|
-
latex=False, save=False):
|
|
464
|
+
def sample(self, size, x_min=None, x_max=None, method='qmc', seed=None,
|
|
465
|
+
plot=False, latex=False, save=False):
|
|
466
466
|
"""
|
|
467
467
|
Sample from distribution.
|
|
468
468
|
|
|
@@ -486,6 +486,9 @@ class Meixner(object):
|
|
|
486
486
|
* ``'mc'``: Monte Carlo
|
|
487
487
|
* ``'qmc'``: Quasi Monte Carlo
|
|
488
488
|
|
|
489
|
+
seed : int, default=None,
|
|
490
|
+
Seed for random number generator.
|
|
491
|
+
|
|
489
492
|
plot : bool, default=False
|
|
490
493
|
If `True`, samples histogram is plotted.
|
|
491
494
|
|
|
@@ -523,6 +526,9 @@ class Meixner(object):
|
|
|
523
526
|
:class: custom-dark
|
|
524
527
|
"""
|
|
525
528
|
|
|
529
|
+
if seed is not None:
|
|
530
|
+
numpy.random.seed(seed)
|
|
531
|
+
|
|
526
532
|
if x_min is None:
|
|
527
533
|
x_min = self.lam_m
|
|
528
534
|
|
|
@@ -569,7 +575,7 @@ class Meixner(object):
|
|
|
569
575
|
# matrix
|
|
570
576
|
# ======
|
|
571
577
|
|
|
572
|
-
def matrix(self, size):
|
|
578
|
+
def matrix(self, size, seed=None):
|
|
573
579
|
"""
|
|
574
580
|
Generate matrix with the spectral density of the distribution.
|
|
575
581
|
|
|
@@ -579,6 +585,9 @@ class Meixner(object):
|
|
|
579
585
|
size : int
|
|
580
586
|
Size :math:`n` of the matrix.
|
|
581
587
|
|
|
588
|
+
seed : int, default=None
|
|
589
|
+
Seed for random number generator.
|
|
590
|
+
|
|
582
591
|
Returns
|
|
583
592
|
-------
|
|
584
593
|
|
freealg-0.1.8/freealg/distributions/wachter.py → freealg-0.1.10/freealg/distributions/_wachter.py
RENAMED
|
@@ -436,8 +436,8 @@ class Wachter(object):
|
|
|
436
436
|
# sample
|
|
437
437
|
# ======
|
|
438
438
|
|
|
439
|
-
def sample(self, size, x_min=None, x_max=None, method='qmc',
|
|
440
|
-
latex=False, save=False):
|
|
439
|
+
def sample(self, size, x_min=None, x_max=None, method='qmc', seed=None,
|
|
440
|
+
plot=False, latex=False, save=False):
|
|
441
441
|
"""
|
|
442
442
|
Sample from distribution.
|
|
443
443
|
|
|
@@ -461,6 +461,9 @@ class Wachter(object):
|
|
|
461
461
|
* ``'mc'``: Monte Carlo
|
|
462
462
|
* ``'qmc'``: Quasi Monte Carlo
|
|
463
463
|
|
|
464
|
+
seed : int, default=None,
|
|
465
|
+
Seed for random number generator.
|
|
466
|
+
|
|
464
467
|
plot : bool, default=False
|
|
465
468
|
If `True`, samples histogram is plotted.
|
|
466
469
|
|
|
@@ -498,6 +501,9 @@ class Wachter(object):
|
|
|
498
501
|
:class: custom-dark
|
|
499
502
|
"""
|
|
500
503
|
|
|
504
|
+
if seed is not None:
|
|
505
|
+
numpy.random.seed(seed)
|
|
506
|
+
|
|
501
507
|
if x_min is None:
|
|
502
508
|
x_min = self.lam_m
|
|
503
509
|
|
|
@@ -544,7 +550,7 @@ class Wachter(object):
|
|
|
544
550
|
# matrix
|
|
545
551
|
# ======
|
|
546
552
|
|
|
547
|
-
def matrix(self, size):
|
|
553
|
+
def matrix(self, size, seed=None):
|
|
548
554
|
"""
|
|
549
555
|
Generate matrix with the spectral density of the distribution.
|
|
550
556
|
|
|
@@ -554,6 +560,9 @@ class Wachter(object):
|
|
|
554
560
|
size : int
|
|
555
561
|
Size :math:`n` of the matrix.
|
|
556
562
|
|
|
563
|
+
seed : int, default=None
|
|
564
|
+
Seed for random number generator.
|
|
565
|
+
|
|
557
566
|
Returns
|
|
558
567
|
-------
|
|
559
568
|
|
|
@@ -573,6 +582,9 @@ class Wachter(object):
|
|
|
573
582
|
>>> A = wa.matrix(2000)
|
|
574
583
|
"""
|
|
575
584
|
|
|
585
|
+
if seed is not None:
|
|
586
|
+
numpy.random.seed(seed)
|
|
587
|
+
|
|
576
588
|
n = size
|
|
577
589
|
m1 = int(self.a * n)
|
|
578
590
|
m2 = int(self.b * n)
|
freealg-0.1.8/freealg/distributions/wigner.py → freealg-0.1.10/freealg/distributions/_wigner.py
RENAMED
|
@@ -416,8 +416,8 @@ class Wigner(object):
|
|
|
416
416
|
# sample
|
|
417
417
|
# ======
|
|
418
418
|
|
|
419
|
-
def sample(self, size, x_min=None, x_max=None, method='qmc',
|
|
420
|
-
latex=False, save=False):
|
|
419
|
+
def sample(self, size, x_min=None, x_max=None, method='qmc', seed=None,
|
|
420
|
+
plot=False, latex=False, save=False):
|
|
421
421
|
"""
|
|
422
422
|
Sample from distribution.
|
|
423
423
|
|
|
@@ -478,6 +478,9 @@ class Wigner(object):
|
|
|
478
478
|
:class: custom-dark
|
|
479
479
|
"""
|
|
480
480
|
|
|
481
|
+
if seed is not None:
|
|
482
|
+
numpy.random.seed(seed)
|
|
483
|
+
|
|
481
484
|
if x_min is None:
|
|
482
485
|
x_min = self.lam_m
|
|
483
486
|
|
|
@@ -524,7 +527,7 @@ class Wigner(object):
|
|
|
524
527
|
# matrix
|
|
525
528
|
# ======
|
|
526
529
|
|
|
527
|
-
def matrix(self, size):
|
|
530
|
+
def matrix(self, size, seed=None):
|
|
528
531
|
"""
|
|
529
532
|
Generate matrix with the spectral density of the distribution.
|
|
530
533
|
|
|
@@ -534,6 +537,9 @@ class Wigner(object):
|
|
|
534
537
|
size : int
|
|
535
538
|
Size :math:`n` of the matrix.
|
|
536
539
|
|
|
540
|
+
seed : int, default=None
|
|
541
|
+
Seed for random number generator.
|
|
542
|
+
|
|
537
543
|
Returns
|
|
538
544
|
-------
|
|
539
545
|
|
|
@@ -550,6 +556,9 @@ class Wigner(object):
|
|
|
550
556
|
>>> A = wg.matrix(2000)
|
|
551
557
|
"""
|
|
552
558
|
|
|
559
|
+
if seed is not None:
|
|
560
|
+
numpy.random.seed(seed)
|
|
561
|
+
|
|
553
562
|
# Parameters
|
|
554
563
|
n = size
|
|
555
564
|
X = numpy.random.randn(n, n)
|
|
@@ -499,17 +499,13 @@ class FreeForm(object):
|
|
|
499
499
|
# Check density is unit mass
|
|
500
500
|
mass = numpy.trapz(rho, x)
|
|
501
501
|
if not numpy.isclose(mass, 1.0, atol=1e-2):
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
print(f'"rho" is not unit mass. mass: {mass}. Set "force=True".')
|
|
502
|
+
print(f'"rho" is not unit mass. mass: {mass:>0.3f}. Set ' +
|
|
503
|
+
r'"force=True".')
|
|
505
504
|
|
|
506
505
|
# Check density is positive
|
|
507
506
|
min_rho = numpy.min(rho)
|
|
508
507
|
if min_rho < 0.0 - 1e-3:
|
|
509
|
-
|
|
510
|
-
# f'"rho" is not positive. min_rho: {min_rho}. Set ' +
|
|
511
|
-
# r'"force=True".')
|
|
512
|
-
print(f'"rho" is not positive. min_rho: {min_rho}. Set ' +
|
|
508
|
+
print(f'"rho" is not positive. min_rho: {min_rho:>0.3f}. Set ' +
|
|
513
509
|
r'"force=True".')
|
|
514
510
|
|
|
515
511
|
if plot:
|
|
@@ -631,7 +627,7 @@ class FreeForm(object):
|
|
|
631
627
|
# stieltjes
|
|
632
628
|
# =========
|
|
633
629
|
|
|
634
|
-
def stieltjes(self, x, y, plot=False, latex=False, save=False):
|
|
630
|
+
def stieltjes(self, x=None, y=None, plot=False, latex=False, save=False):
|
|
635
631
|
"""
|
|
636
632
|
Compute Stieltjes transform of the spectral density over a 2D Cartesian
|
|
637
633
|
grid on the complex plane.
|
|
@@ -839,8 +835,8 @@ class FreeForm(object):
|
|
|
839
835
|
# ==========
|
|
840
836
|
|
|
841
837
|
def decompress(self, size, x=None, delta=1e-6, iterations=500,
|
|
842
|
-
step_size=0.1, tolerance=1e-4,
|
|
843
|
-
save=False):
|
|
838
|
+
step_size=0.1, tolerance=1e-4, seed=None, plot=False,
|
|
839
|
+
latex=False, save=False):
|
|
844
840
|
"""
|
|
845
841
|
Free decompression of spectral density.
|
|
846
842
|
|
|
@@ -868,6 +864,9 @@ class FreeForm(object):
|
|
|
868
864
|
Tolerance for the solution obtained by the Newton solver. Also
|
|
869
865
|
used for the finite difference approximation to the derivative.
|
|
870
866
|
|
|
867
|
+
seed : int, default=None
|
|
868
|
+
Seed for random number generator. Used for QMC sampling.
|
|
869
|
+
|
|
871
870
|
plot : bool, default=False
|
|
872
871
|
If `True`, density is plotted.
|
|
873
872
|
|
|
@@ -925,6 +924,6 @@ class FreeForm(object):
|
|
|
925
924
|
plot_density(x, rho, support=(lb, ub),
|
|
926
925
|
label='Decompression', latex=latex, save=save)
|
|
927
926
|
|
|
928
|
-
eigs = numpy.sort(qmc_sample(x, rho, size))
|
|
927
|
+
eigs = numpy.sort(qmc_sample(x, rho, size, seed=seed))
|
|
929
928
|
|
|
930
929
|
return rho, eigs
|
|
@@ -25,8 +25,8 @@ freealg.egg-info/not-zip-safe
|
|
|
25
25
|
freealg.egg-info/requires.txt
|
|
26
26
|
freealg.egg-info/top_level.txt
|
|
27
27
|
freealg/distributions/__init__.py
|
|
28
|
-
freealg/distributions/
|
|
29
|
-
freealg/distributions/
|
|
30
|
-
freealg/distributions/
|
|
31
|
-
freealg/distributions/
|
|
32
|
-
freealg/distributions/
|
|
28
|
+
freealg/distributions/_kesten_mckay.py
|
|
29
|
+
freealg/distributions/_marchenko_pastur.py
|
|
30
|
+
freealg/distributions/_meixner.py
|
|
31
|
+
freealg/distributions/_wachter.py
|
|
32
|
+
freealg/distributions/_wigner.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.8"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|