freealg 0.1.9__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.
Files changed (34) hide show
  1. {freealg-0.1.9 → freealg-0.1.10}/PKG-INFO +1 -1
  2. {freealg-0.1.9 → freealg-0.1.10}/freealg/__init__.py +2 -1
  3. freealg-0.1.10/freealg/__version__.py +1 -0
  4. {freealg-0.1.9 → freealg-0.1.10}/freealg/_plot_util.py +55 -2
  5. {freealg-0.1.9 → freealg-0.1.10}/freealg/_sample.py +2 -1
  6. {freealg-0.1.9 → freealg-0.1.10}/freealg/distributions/__init__.py +5 -5
  7. freealg-0.1.9/freealg/distributions/kesten_mckay.py → freealg-0.1.10/freealg/distributions/_kesten_mckay.py +2 -1
  8. freealg-0.1.9/freealg/distributions/marchenko_pastur.py → freealg-0.1.10/freealg/distributions/_marchenko_pastur.py +4 -2
  9. freealg-0.1.9/freealg/distributions/meixner.py → freealg-0.1.10/freealg/distributions/_meixner.py +2 -1
  10. freealg-0.1.9/freealg/distributions/wachter.py → freealg-0.1.10/freealg/distributions/_wachter.py +4 -2
  11. freealg-0.1.9/freealg/distributions/wigner.py → freealg-0.1.10/freealg/distributions/_wigner.py +4 -2
  12. {freealg-0.1.9 → freealg-0.1.10}/freealg/freeform.py +4 -8
  13. {freealg-0.1.9 → freealg-0.1.10}/freealg.egg-info/PKG-INFO +1 -1
  14. {freealg-0.1.9 → freealg-0.1.10}/freealg.egg-info/SOURCES.txt +5 -5
  15. freealg-0.1.9/freealg/__version__.py +0 -1
  16. {freealg-0.1.9 → freealg-0.1.10}/AUTHORS.txt +0 -0
  17. {freealg-0.1.9 → freealg-0.1.10}/CHANGELOG.rst +0 -0
  18. {freealg-0.1.9 → freealg-0.1.10}/LICENSE.txt +0 -0
  19. {freealg-0.1.9 → freealg-0.1.10}/MANIFEST.in +0 -0
  20. {freealg-0.1.9 → freealg-0.1.10}/README.rst +0 -0
  21. {freealg-0.1.9 → freealg-0.1.10}/freealg/_chebyshev.py +0 -0
  22. {freealg-0.1.9 → freealg-0.1.10}/freealg/_damp.py +0 -0
  23. {freealg-0.1.9 → freealg-0.1.10}/freealg/_decompress.py +0 -0
  24. {freealg-0.1.9 → freealg-0.1.10}/freealg/_jacobi.py +0 -0
  25. {freealg-0.1.9 → freealg-0.1.10}/freealg/_pade.py +0 -0
  26. {freealg-0.1.9 → freealg-0.1.10}/freealg/_util.py +0 -0
  27. {freealg-0.1.9 → freealg-0.1.10}/freealg.egg-info/dependency_links.txt +0 -0
  28. {freealg-0.1.9 → freealg-0.1.10}/freealg.egg-info/not-zip-safe +0 -0
  29. {freealg-0.1.9 → freealg-0.1.10}/freealg.egg-info/requires.txt +0 -0
  30. {freealg-0.1.9 → freealg-0.1.10}/freealg.egg-info/top_level.txt +0 -0
  31. {freealg-0.1.9 → freealg-0.1.10}/pyproject.toml +0 -0
  32. {freealg-0.1.9 → freealg-0.1.10}/requirements.txt +0 -0
  33. {freealg-0.1.9 → freealg-0.1.10}/setup.cfg +0 -0
  34. {freealg-0.1.9 → freealg-0.1.10}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: freealg
3
- Version: 0.1.9
3
+ Version: 0.1.10
4
4
  Summary: Free probability for large matrices
5
5
  Keywords: leaderboard bot chat
6
6
  Platform: Linux
@@ -7,7 +7,8 @@
7
7
  # directory of this source tree.
8
8
 
9
9
  from .freeform import FreeForm
10
+ from . import distributions
10
11
 
11
- __all__ = ['FreeForm']
12
+ __all__ = ['FreeForm', 'distributions']
12
13
 
13
14
  from .__version__ import __version__ # noqa: F401 E402
@@ -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, 250)
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.size // 15)
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')
@@ -82,7 +82,8 @@ def qmc_sample(x, rho, num_pts, seed=None):
82
82
  >>> numpy.allclose(samples.mean(), 0.75, atol=0.02)
83
83
  """
84
84
 
85
- numpy.random.rand(seed)
85
+ if seed is not None:
86
+ numpy.random.rand(seed)
86
87
 
87
88
  quantile = _quantile_func(x, rho)
88
89
  engine = qmc.Halton(d=1)
@@ -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 .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
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']
@@ -494,7 +494,8 @@ class KestenMcKay(object):
494
494
  :class: custom-dark
495
495
  """
496
496
 
497
- numpy.random.seed(seed)
497
+ if seed is not None:
498
+ numpy.random.seed(seed)
498
499
 
499
500
  if x_min is None:
500
501
  x_min = self.lam_m
@@ -501,7 +501,8 @@ class MarchenkoPastur(object):
501
501
  :class: custom-dark
502
502
  """
503
503
 
504
- numpy.random.seed(seed)
504
+ if seed is not None:
505
+ numpy.random.seed(seed)
505
506
 
506
507
  if x_min is None:
507
508
  x_min = self.lam_m
@@ -578,7 +579,8 @@ class MarchenkoPastur(object):
578
579
  >>> A = mp.matrix(2000)
579
580
  """
580
581
 
581
- numpy.random.seed(seed)
582
+ if seed is not None:
583
+ numpy.random.seed(seed)
582
584
 
583
585
  # Parameters
584
586
  m = int(size / self.lam)
@@ -526,7 +526,8 @@ class Meixner(object):
526
526
  :class: custom-dark
527
527
  """
528
528
 
529
- numpy.random.seed(seed)
529
+ if seed is not None:
530
+ numpy.random.seed(seed)
530
531
 
531
532
  if x_min is None:
532
533
  x_min = self.lam_m
@@ -501,7 +501,8 @@ class Wachter(object):
501
501
  :class: custom-dark
502
502
  """
503
503
 
504
- numpy.random.seed(seed)
504
+ if seed is not None:
505
+ numpy.random.seed(seed)
505
506
 
506
507
  if x_min is None:
507
508
  x_min = self.lam_m
@@ -581,7 +582,8 @@ class Wachter(object):
581
582
  >>> A = wa.matrix(2000)
582
583
  """
583
584
 
584
- numpy.random.seed(seed)
585
+ if seed is not None:
586
+ numpy.random.seed(seed)
585
587
 
586
588
  n = size
587
589
  m1 = int(self.a * n)
@@ -478,7 +478,8 @@ class Wigner(object):
478
478
  :class: custom-dark
479
479
  """
480
480
 
481
- numpy.random.seed(seed)
481
+ if seed is not None:
482
+ numpy.random.seed(seed)
482
483
 
483
484
  if x_min is None:
484
485
  x_min = self.lam_m
@@ -555,7 +556,8 @@ class Wigner(object):
555
556
  >>> A = wg.matrix(2000)
556
557
  """
557
558
 
558
- numpy.random.seed(seed)
559
+ if seed is not None:
560
+ numpy.random.seed(seed)
559
561
 
560
562
  # Parameters
561
563
  n = size
@@ -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
- # raise RuntimeWarning(f'"rho" is not unit mass. mass: {mass}. ' +
503
- # r'Set "force=True".')
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
- # raise RuntimeWarning(
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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: freealg
3
- Version: 0.1.9
3
+ Version: 0.1.10
4
4
  Summary: Free probability for large matrices
5
5
  Keywords: leaderboard bot chat
6
6
  Platform: Linux
@@ -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/kesten_mckay.py
29
- freealg/distributions/marchenko_pastur.py
30
- freealg/distributions/meixner.py
31
- freealg/distributions/wachter.py
32
- freealg/distributions/wigner.py
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.9"
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