freealg 0.1.8__tar.gz → 0.1.9__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.9}/PKG-INFO +1 -1
- freealg-0.1.9/freealg/__version__.py +1 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg/_sample.py +7 -1
- {freealg-0.1.8 → freealg-0.1.9}/freealg/distributions/kesten_mckay.py +17 -9
- {freealg-0.1.8 → freealg-0.1.9}/freealg/distributions/marchenko_pastur.py +12 -4
- {freealg-0.1.8 → freealg-0.1.9}/freealg/distributions/meixner.py +11 -3
- {freealg-0.1.8 → freealg-0.1.9}/freealg/distributions/wachter.py +13 -3
- {freealg-0.1.8 → freealg-0.1.9}/freealg/distributions/wigner.py +10 -3
- {freealg-0.1.8 → freealg-0.1.9}/freealg/freeform.py +6 -3
- {freealg-0.1.8 → freealg-0.1.9}/freealg.egg-info/PKG-INFO +1 -1
- freealg-0.1.8/freealg/__version__.py +0 -1
- {freealg-0.1.8 → freealg-0.1.9}/AUTHORS.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/CHANGELOG.rst +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/LICENSE.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/MANIFEST.in +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/README.rst +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg/__init__.py +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg/_chebyshev.py +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg/_damp.py +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg/_decompress.py +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg/_jacobi.py +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg/_pade.py +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg/_plot_util.py +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg/_util.py +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg/distributions/__init__.py +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg.egg-info/SOURCES.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg.egg-info/dependency_links.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg.egg-info/not-zip-safe +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg.egg-info/requires.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/freealg.egg-info/top_level.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/pyproject.toml +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/requirements.txt +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/setup.cfg +0 -0
- {freealg-0.1.8 → freealg-0.1.9}/setup.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.9"
|
|
@@ -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,8 @@ def qmc_sample(x, rho, num_pts):
|
|
|
78
82
|
>>> numpy.allclose(samples.mean(), 0.75, atol=0.02)
|
|
79
83
|
"""
|
|
80
84
|
|
|
85
|
+
numpy.random.rand(seed)
|
|
86
|
+
|
|
81
87
|
quantile = _quantile_func(x, rho)
|
|
82
88
|
engine = qmc.Halton(d=1)
|
|
83
89
|
u = engine.random(num_pts)
|
|
@@ -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,8 @@ class KestenMcKay(object):
|
|
|
491
494
|
:class: custom-dark
|
|
492
495
|
"""
|
|
493
496
|
|
|
497
|
+
numpy.random.seed(seed)
|
|
498
|
+
|
|
494
499
|
if x_min is None:
|
|
495
500
|
x_min = self.lam_m
|
|
496
501
|
|
|
@@ -537,7 +542,7 @@ class KestenMcKay(object):
|
|
|
537
542
|
# Haar unitary
|
|
538
543
|
# ============
|
|
539
544
|
|
|
540
|
-
def _haar_orthogonal(self, n, k):
|
|
545
|
+
def _haar_orthogonal(self, n, k, seed=None):
|
|
541
546
|
"""
|
|
542
547
|
Haar-distributed O(n) via the Mezzadri QR trick.
|
|
543
548
|
|
|
@@ -559,7 +564,7 @@ class KestenMcKay(object):
|
|
|
559
564
|
uniformly distributed under Haar measure O(n).
|
|
560
565
|
"""
|
|
561
566
|
|
|
562
|
-
rng = numpy.random.default_rng()
|
|
567
|
+
rng = numpy.random.default_rng(seed)
|
|
563
568
|
Z = rng.standard_normal((n, k))
|
|
564
569
|
Q, R = numpy.linalg.qr(Z, mode='reduced') # Q is n by k
|
|
565
570
|
Q *= numpy.sign(numpy.diag(R))
|
|
@@ -570,7 +575,7 @@ class KestenMcKay(object):
|
|
|
570
575
|
# matrix
|
|
571
576
|
# ======
|
|
572
577
|
|
|
573
|
-
def matrix(self, size):
|
|
578
|
+
def matrix(self, size, seed=None):
|
|
574
579
|
"""
|
|
575
580
|
Generate matrix with the spectral density of the distribution.
|
|
576
581
|
|
|
@@ -580,6 +585,9 @@ class KestenMcKay(object):
|
|
|
580
585
|
size : int
|
|
581
586
|
Size :math:`n` of the matrix.
|
|
582
587
|
|
|
588
|
+
seed : int, default=None
|
|
589
|
+
Seed for random number generator.
|
|
590
|
+
|
|
583
591
|
Returns
|
|
584
592
|
-------
|
|
585
593
|
|
|
@@ -621,7 +629,7 @@ class KestenMcKay(object):
|
|
|
621
629
|
https://arxiv.org/abs/2009.11950
|
|
622
630
|
|
|
623
631
|
.. [2] Francesco Mezzadri. How to generate random matrices from the
|
|
624
|
-
classical compact groups. https://arxiv.org/
|
|
632
|
+
classical compact groups. https://arxiv.org/abs/math-ph/0609050
|
|
625
633
|
|
|
626
634
|
Examples
|
|
627
635
|
--------
|
|
@@ -637,12 +645,12 @@ class KestenMcKay(object):
|
|
|
637
645
|
# Uses algorithm 1 . Only if d is even. This is much faster than
|
|
638
646
|
# algorithm 2.
|
|
639
647
|
n = size
|
|
640
|
-
rng = numpy.random.default_rng()
|
|
648
|
+
rng = numpy.random.default_rng(seed)
|
|
641
649
|
m = self.d // 2
|
|
642
650
|
A = numpy.zeros((n, n))
|
|
643
651
|
|
|
644
652
|
for _ in range(m):
|
|
645
|
-
O_ = self._haar_orthogonal(n, n)
|
|
653
|
+
O_ = self._haar_orthogonal(n, n, seed=seed)
|
|
646
654
|
A += O_ + O_.T
|
|
647
655
|
else:
|
|
648
656
|
# Uses algorithm 2. Only when d is odd, but this algorithm works
|
|
@@ -650,7 +658,7 @@ class KestenMcKay(object):
|
|
|
650
658
|
# especially if d is larger. As such, as only use algorithm 1 when
|
|
651
659
|
# d is even and use algorithm 2 for the rest.
|
|
652
660
|
n = size * self.d
|
|
653
|
-
rng = numpy.random.default_rng()
|
|
661
|
+
rng = numpy.random.default_rng(seed)
|
|
654
662
|
|
|
655
663
|
# Deterministic pieces
|
|
656
664
|
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,8 @@ class MarchenkoPastur(object):
|
|
|
498
501
|
:class: custom-dark
|
|
499
502
|
"""
|
|
500
503
|
|
|
504
|
+
numpy.random.seed(seed)
|
|
505
|
+
|
|
501
506
|
if x_min is None:
|
|
502
507
|
x_min = self.lam_m
|
|
503
508
|
|
|
@@ -544,7 +549,7 @@ class MarchenkoPastur(object):
|
|
|
544
549
|
# matrix
|
|
545
550
|
# ======
|
|
546
551
|
|
|
547
|
-
def matrix(self, size):
|
|
552
|
+
def matrix(self, size, seed=None):
|
|
548
553
|
"""
|
|
549
554
|
Generate matrix with the spectral density of the distribution.
|
|
550
555
|
|
|
@@ -554,6 +559,9 @@ class MarchenkoPastur(object):
|
|
|
554
559
|
size : int
|
|
555
560
|
Size :math:`n` of the matrix.
|
|
556
561
|
|
|
562
|
+
seed : int, default=None
|
|
563
|
+
Seed for random number generator.
|
|
564
|
+
|
|
557
565
|
Returns
|
|
558
566
|
-------
|
|
559
567
|
|
|
@@ -570,7 +578,7 @@ class MarchenkoPastur(object):
|
|
|
570
578
|
>>> A = mp.matrix(2000)
|
|
571
579
|
"""
|
|
572
580
|
|
|
573
|
-
numpy.random.seed(
|
|
581
|
+
numpy.random.seed(seed)
|
|
574
582
|
|
|
575
583
|
# Parameters
|
|
576
584
|
m = int(size / self.lam)
|
|
@@ -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,8 @@ class Meixner(object):
|
|
|
523
526
|
:class: custom-dark
|
|
524
527
|
"""
|
|
525
528
|
|
|
529
|
+
numpy.random.seed(seed)
|
|
530
|
+
|
|
526
531
|
if x_min is None:
|
|
527
532
|
x_min = self.lam_m
|
|
528
533
|
|
|
@@ -569,7 +574,7 @@ class Meixner(object):
|
|
|
569
574
|
# matrix
|
|
570
575
|
# ======
|
|
571
576
|
|
|
572
|
-
def matrix(self, size):
|
|
577
|
+
def matrix(self, size, seed=None):
|
|
573
578
|
"""
|
|
574
579
|
Generate matrix with the spectral density of the distribution.
|
|
575
580
|
|
|
@@ -579,6 +584,9 @@ class Meixner(object):
|
|
|
579
584
|
size : int
|
|
580
585
|
Size :math:`n` of the matrix.
|
|
581
586
|
|
|
587
|
+
seed : int, default=None
|
|
588
|
+
Seed for random number generator.
|
|
589
|
+
|
|
582
590
|
Returns
|
|
583
591
|
-------
|
|
584
592
|
|
|
@@ -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,8 @@ class Wachter(object):
|
|
|
498
501
|
:class: custom-dark
|
|
499
502
|
"""
|
|
500
503
|
|
|
504
|
+
numpy.random.seed(seed)
|
|
505
|
+
|
|
501
506
|
if x_min is None:
|
|
502
507
|
x_min = self.lam_m
|
|
503
508
|
|
|
@@ -544,7 +549,7 @@ class Wachter(object):
|
|
|
544
549
|
# matrix
|
|
545
550
|
# ======
|
|
546
551
|
|
|
547
|
-
def matrix(self, size):
|
|
552
|
+
def matrix(self, size, seed=None):
|
|
548
553
|
"""
|
|
549
554
|
Generate matrix with the spectral density of the distribution.
|
|
550
555
|
|
|
@@ -554,6 +559,9 @@ class Wachter(object):
|
|
|
554
559
|
size : int
|
|
555
560
|
Size :math:`n` of the matrix.
|
|
556
561
|
|
|
562
|
+
seed : int, default=None
|
|
563
|
+
Seed for random number generator.
|
|
564
|
+
|
|
557
565
|
Returns
|
|
558
566
|
-------
|
|
559
567
|
|
|
@@ -573,6 +581,8 @@ class Wachter(object):
|
|
|
573
581
|
>>> A = wa.matrix(2000)
|
|
574
582
|
"""
|
|
575
583
|
|
|
584
|
+
numpy.random.seed(seed)
|
|
585
|
+
|
|
576
586
|
n = size
|
|
577
587
|
m1 = int(self.a * n)
|
|
578
588
|
m2 = int(self.b * n)
|
|
@@ -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,8 @@ class Wigner(object):
|
|
|
478
478
|
:class: custom-dark
|
|
479
479
|
"""
|
|
480
480
|
|
|
481
|
+
numpy.random.seed(seed)
|
|
482
|
+
|
|
481
483
|
if x_min is None:
|
|
482
484
|
x_min = self.lam_m
|
|
483
485
|
|
|
@@ -524,7 +526,7 @@ class Wigner(object):
|
|
|
524
526
|
# matrix
|
|
525
527
|
# ======
|
|
526
528
|
|
|
527
|
-
def matrix(self, size):
|
|
529
|
+
def matrix(self, size, seed=None):
|
|
528
530
|
"""
|
|
529
531
|
Generate matrix with the spectral density of the distribution.
|
|
530
532
|
|
|
@@ -534,6 +536,9 @@ class Wigner(object):
|
|
|
534
536
|
size : int
|
|
535
537
|
Size :math:`n` of the matrix.
|
|
536
538
|
|
|
539
|
+
seed : int, default=None
|
|
540
|
+
Seed for random number generator.
|
|
541
|
+
|
|
537
542
|
Returns
|
|
538
543
|
-------
|
|
539
544
|
|
|
@@ -550,6 +555,8 @@ class Wigner(object):
|
|
|
550
555
|
>>> A = wg.matrix(2000)
|
|
551
556
|
"""
|
|
552
557
|
|
|
558
|
+
numpy.random.seed(seed)
|
|
559
|
+
|
|
553
560
|
# Parameters
|
|
554
561
|
n = size
|
|
555
562
|
X = numpy.random.randn(n, n)
|
|
@@ -839,8 +839,8 @@ class FreeForm(object):
|
|
|
839
839
|
# ==========
|
|
840
840
|
|
|
841
841
|
def decompress(self, size, x=None, delta=1e-6, iterations=500,
|
|
842
|
-
step_size=0.1, tolerance=1e-4,
|
|
843
|
-
save=False):
|
|
842
|
+
step_size=0.1, tolerance=1e-4, seed=None, plot=False,
|
|
843
|
+
latex=False, save=False):
|
|
844
844
|
"""
|
|
845
845
|
Free decompression of spectral density.
|
|
846
846
|
|
|
@@ -868,6 +868,9 @@ class FreeForm(object):
|
|
|
868
868
|
Tolerance for the solution obtained by the Newton solver. Also
|
|
869
869
|
used for the finite difference approximation to the derivative.
|
|
870
870
|
|
|
871
|
+
seed : int, default=None
|
|
872
|
+
Seed for random number generator. Used for QMC sampling.
|
|
873
|
+
|
|
871
874
|
plot : bool, default=False
|
|
872
875
|
If `True`, density is plotted.
|
|
873
876
|
|
|
@@ -925,6 +928,6 @@ class FreeForm(object):
|
|
|
925
928
|
plot_density(x, rho, support=(lb, ub),
|
|
926
929
|
label='Decompression', latex=latex, save=save)
|
|
927
930
|
|
|
928
|
-
eigs = numpy.sort(qmc_sample(x, rho, size))
|
|
931
|
+
eigs = numpy.sort(qmc_sample(x, rho, size, seed=seed))
|
|
929
932
|
|
|
930
933
|
return rho, eigs
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|