freealg 0.1.8__py3-none-any.whl → 0.1.9__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/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.8"
1
+ __version__ = "0.1.9"
freealg/_sample.py CHANGED
@@ -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', plot=False,
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/pdf/math-ph/0609050
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', plot=False,
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(0)
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', plot=False,
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', plot=False,
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', plot=False,
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)
freealg/freeform.py CHANGED
@@ -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, plot=False, latex=False,
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: freealg
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: Free probability for large matrices
5
5
  Keywords: leaderboard bot chat
6
6
  Platform: Linux
@@ -0,0 +1,23 @@
1
+ freealg/__init__.py,sha256=K92neXJZ9VE1U_j_pj28Qyq1MzlMXhOuYK2ZihgwCaU,463
2
+ freealg/__version__.py,sha256=XIaxbMbyiP-L3kguR1GhxirFblTXiHR1lMfDVITvHUI,22
3
+ freealg/_chebyshev.py,sha256=X6u5pKjR1HPZ-KbCfr7zT6HRwB6pZMADvVS3sT5LTkA,5638
4
+ freealg/_damp.py,sha256=k2vtBtWOxQBf4qXaWu_En81lQBXbEO4QbxxWpvuVhdE,1802
5
+ freealg/_decompress.py,sha256=7U2lL8F5z76aFuZJBsPj70jEVRuzvJHnIh5FSw-aLME,4680
6
+ freealg/_jacobi.py,sha256=AT4ONSHGGDxVKE3MGMLyMR8uDFiO-e9u3x5udYfdJJk,5635
7
+ freealg/_pade.py,sha256=mP96wEPfIzHLZ6PDB5OyhmSA8N1uVPVUkmJa3ebXXiU,13623
8
+ freealg/_plot_util.py,sha256=wVx99GRdIFu_wzmG8f5JSDZ65BJohnuSBm3mZ58wElg,18426
9
+ freealg/_sample.py,sha256=J7zvtPd9iQdvtE6di9ZlAymj2UWnVg2Rn8WXAt6gg7w,2447
10
+ freealg/_util.py,sha256=alJ9s1U_sHL7dXq7hI10fa8CF_AZ6Xmy_QsoyDYPSDQ,3677
11
+ freealg/freeform.py,sha256=3SKO9vC3t2ef0pmudUk6UyxRUAwV1OwkLuhAIwrp1Wk,28875
12
+ freealg/distributions/__init__.py,sha256=ufiL5OG_Jyma3D2il0BedhGuilROilbmSjxqoiz45GE,574
13
+ freealg/distributions/kesten_mckay.py,sha256=6r8pyOZArrEbW_OhtQA8hk3KiMlyVtQ30Kl684ja7z8,19533
14
+ freealg/distributions/marchenko_pastur.py,sha256=XvBS-SglB8a6bLGGDZmQaTRLvUObQnlEu14aESdQ42Y,16622
15
+ freealg/distributions/meixner.py,sha256=qhtcuKGCyWnFw6XerfzePOHEkznkuUdxeaeic3KVqE4,17173
16
+ freealg/distributions/wachter.py,sha256=EnG5VCN61fq737_kz3BgsZz95OUm7-NpMSLKz6XIWqY,16525
17
+ freealg/distributions/wigner.py,sha256=bFoDx-_jqB7EryXsHgRAOghKb3G-Wjo0NXBDS5Fycqk,15499
18
+ freealg-0.1.9.dist-info/licenses/AUTHORS.txt,sha256=0b67Nz4_JgIzUupHJTAZxu5QdSUM_HRM_X_w4xCb17o,30
19
+ freealg-0.1.9.dist-info/licenses/LICENSE.txt,sha256=J-EEYEtxb3VVf_Bn1TYfWnpY5lMFIM15iLDDcnaDTPA,1443
20
+ freealg-0.1.9.dist-info/METADATA,sha256=yIPvqM3ijpWvacUUT1PxHX3bvqCeuusfwBt5XTDkPuo,2941
21
+ freealg-0.1.9.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
22
+ freealg-0.1.9.dist-info/top_level.txt,sha256=eR2wrgYwDdnnJ9Zf5PruPqe4kQav0GMvRsqct6y00Q8,8
23
+ freealg-0.1.9.dist-info/RECORD,,
@@ -1,23 +0,0 @@
1
- freealg/__init__.py,sha256=K92neXJZ9VE1U_j_pj28Qyq1MzlMXhOuYK2ZihgwCaU,463
2
- freealg/__version__.py,sha256=C69ADlbQREQlR15trneyA2sk8x0-oH4rDAX5fsv19_U,22
3
- freealg/_chebyshev.py,sha256=X6u5pKjR1HPZ-KbCfr7zT6HRwB6pZMADvVS3sT5LTkA,5638
4
- freealg/_damp.py,sha256=k2vtBtWOxQBf4qXaWu_En81lQBXbEO4QbxxWpvuVhdE,1802
5
- freealg/_decompress.py,sha256=7U2lL8F5z76aFuZJBsPj70jEVRuzvJHnIh5FSw-aLME,4680
6
- freealg/_jacobi.py,sha256=AT4ONSHGGDxVKE3MGMLyMR8uDFiO-e9u3x5udYfdJJk,5635
7
- freealg/_pade.py,sha256=mP96wEPfIzHLZ6PDB5OyhmSA8N1uVPVUkmJa3ebXXiU,13623
8
- freealg/_plot_util.py,sha256=wVx99GRdIFu_wzmG8f5JSDZ65BJohnuSBm3mZ58wElg,18426
9
- freealg/_sample.py,sha256=K1ZxKoiuPbEKyh-swL5X7gz1kYcQno6Mof0o1xF38tg,2323
10
- freealg/_util.py,sha256=alJ9s1U_sHL7dXq7hI10fa8CF_AZ6Xmy_QsoyDYPSDQ,3677
11
- freealg/freeform.py,sha256=kbh7UoOJkAVFKj2Zmddy803-asoslkqn-gWJ-HpLN7U,28750
12
- freealg/distributions/__init__.py,sha256=ufiL5OG_Jyma3D2il0BedhGuilROilbmSjxqoiz45GE,574
13
- freealg/distributions/kesten_mckay.py,sha256=DNxDleEPg0NVsIuECU__24ianK_VE_kuU7c8aRFJBOE,19283
14
- freealg/distributions/marchenko_pastur.py,sha256=_lZMKu7TmGu9dkusEJ9ZO5OD04TUuvoQcqN4u5PdAQ4,16403
15
- freealg/distributions/meixner.py,sha256=PgVjAwvr2Xq-5Ghx002ByGWPlfDPs2Zfhh8BmILkoks,16957
16
- freealg/distributions/wachter.py,sha256=vhyboqYXqisoUCNCVZDhuM3VL5E-IVBSpTamotN-4TI,16276
17
- freealg/distributions/wigner.py,sha256=ZcEYcYBUJdLp-5dEqc_h0_qPv49z6ed4S9l6jwptpyE,15331
18
- freealg-0.1.8.dist-info/licenses/AUTHORS.txt,sha256=0b67Nz4_JgIzUupHJTAZxu5QdSUM_HRM_X_w4xCb17o,30
19
- freealg-0.1.8.dist-info/licenses/LICENSE.txt,sha256=J-EEYEtxb3VVf_Bn1TYfWnpY5lMFIM15iLDDcnaDTPA,1443
20
- freealg-0.1.8.dist-info/METADATA,sha256=KtQ-AACsZ-KH8Jn-m_QovDFmIzxbIGLeQeGObvY9mRA,2941
21
- freealg-0.1.8.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
22
- freealg-0.1.8.dist-info/top_level.txt,sha256=eR2wrgYwDdnnJ9Zf5PruPqe4kQav0GMvRsqct6y00Q8,8
23
- freealg-0.1.8.dist-info/RECORD,,