freealg 0.0.1__tar.gz → 0.0.2__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 (27) hide show
  1. {freealg-0.0.1/freealg.egg-info → freealg-0.0.2}/PKG-INFO +1 -1
  2. freealg-0.0.2/freealg/__version__.py +1 -0
  3. {freealg-0.0.1 → freealg-0.0.2}/freealg/_plot_util.py +47 -6
  4. {freealg-0.0.1 → freealg-0.0.2}/freealg/distributions/marchenko_pastur.py +71 -15
  5. {freealg-0.0.1 → freealg-0.0.2}/freealg/freeform.py +1 -1
  6. {freealg-0.0.1 → freealg-0.0.2/freealg.egg-info}/PKG-INFO +1 -1
  7. freealg-0.0.1/freealg/__version__.py +0 -1
  8. {freealg-0.0.1 → freealg-0.0.2}/CHANGELOG.rst +0 -0
  9. {freealg-0.0.1 → freealg-0.0.2}/LICENSE.txt +0 -0
  10. {freealg-0.0.1 → freealg-0.0.2}/MANIFEST.in +0 -0
  11. {freealg-0.0.1 → freealg-0.0.2}/README.rst +0 -0
  12. {freealg-0.0.1 → freealg-0.0.2}/freealg/__init__.py +0 -0
  13. {freealg-0.0.1 → freealg-0.0.2}/freealg/_chebyshev.py +0 -0
  14. {freealg-0.0.1 → freealg-0.0.2}/freealg/_damp.py +0 -0
  15. {freealg-0.0.1 → freealg-0.0.2}/freealg/_jacobi.py +0 -0
  16. {freealg-0.0.1 → freealg-0.0.2}/freealg/_pade.py +0 -0
  17. {freealg-0.0.1 → freealg-0.0.2}/freealg/_util.py +0 -0
  18. {freealg-0.0.1 → freealg-0.0.2}/freealg/distributions/__init__.py +0 -0
  19. {freealg-0.0.1 → freealg-0.0.2}/freealg.egg-info/SOURCES.txt +0 -0
  20. {freealg-0.0.1 → freealg-0.0.2}/freealg.egg-info/dependency_links.txt +0 -0
  21. {freealg-0.0.1 → freealg-0.0.2}/freealg.egg-info/not-zip-safe +0 -0
  22. {freealg-0.0.1 → freealg-0.0.2}/freealg.egg-info/requires.txt +0 -0
  23. {freealg-0.0.1 → freealg-0.0.2}/freealg.egg-info/top_level.txt +0 -0
  24. {freealg-0.0.1 → freealg-0.0.2}/pyproject.toml +0 -0
  25. {freealg-0.0.1 → freealg-0.0.2}/requirements.txt +0 -0
  26. {freealg-0.0.1 → freealg-0.0.2}/setup.cfg +0 -0
  27. {freealg-0.0.1 → freealg-0.0.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: freealg
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Free probability for large matrices
5
5
  Keywords: leaderboard bot chat
6
6
  Platform: Linux
@@ -0,0 +1 @@
1
+ __version__ = "0.0.2"
@@ -54,7 +54,7 @@ def plot_coeff(psi, latex=False, save=False):
54
54
  save_filename = 'energy.pdf'
55
55
 
56
56
  texplot.show_or_save_plot(plt, default_filename=save_filename,
57
- transparent_background=True, dpi=200,
57
+ transparent_background=True, dpi=400,
58
58
  show_and_save=save_status, verbose=True)
59
59
 
60
60
 
@@ -76,6 +76,8 @@ def plot_density(x, rho, eig=None, support=None, label='',
76
76
  bins = numpy.linspace(lam_m, lam_p, 250)
77
77
  _ = ax.hist(eig, bins, density=True, color='silver',
78
78
  edgecolor='none', label='Histogram')
79
+ else:
80
+ plt.fill_between(x, y1=rho, y2=0, color='silver', zorder=-1)
79
81
 
80
82
  ax.plot(x, rho, color='black', label=label, zorder=3)
81
83
  ax.set_xlabel(r'$\lambda$')
@@ -99,7 +101,7 @@ def plot_density(x, rho, eig=None, support=None, label='',
99
101
  save_filename = 'density.pdf'
100
102
 
101
103
  texplot.show_or_save_plot(plt, default_filename=save_filename,
102
- transparent_background=True, dpi=200,
104
+ transparent_background=True, dpi=400,
103
105
  show_and_save=save_status, verbose=True)
104
106
 
105
107
 
@@ -149,7 +151,7 @@ def plot_hilbert(x, hilb, support=None, latex=False, save=False):
149
151
  save_filename = 'hilbert.pdf'
150
152
 
151
153
  texplot.show_or_save_plot(plt, default_filename=save_filename,
152
- transparent_background=True, dpi=200,
154
+ transparent_background=True, dpi=400,
153
155
  show_and_save=save_status, verbose=True)
154
156
 
155
157
 
@@ -327,7 +329,7 @@ def plot_stieltjes(x, y, m1, m2, support, latex=False, save=False):
327
329
  save_filename = 'stieltjes.pdf'
328
330
 
329
331
  texplot.show_or_save_plot(plt, default_filename=save_filename,
330
- transparent_background=True, dpi=200,
332
+ transparent_background=True, dpi=400,
331
333
  show_and_save=save_status, verbose=True)
332
334
 
333
335
 
@@ -456,7 +458,7 @@ def plot_stieltjes_on_disk(r, t, m1_D, m2_D, support, latex=False, save=False):
456
458
  save_filename = 'stieltjes_disk.pdf'
457
459
 
458
460
  texplot.show_or_save_plot(plt, default_filename=save_filename,
459
- transparent_background=True, dpi=200,
461
+ transparent_background=True, dpi=400,
460
462
  show_and_save=save_status, verbose=True)
461
463
 
462
464
 
@@ -495,5 +497,44 @@ def plot_glue_fit(x_supp, g_supp, g_supp_approx, support, latex=False,
495
497
  save_filename = 'glue_fit.pdf'
496
498
 
497
499
  texplot.show_or_save_plot(plt, default_filename=save_filename,
498
- transparent_background=True, dpi=200,
500
+ transparent_background=True, dpi=400,
501
+ show_and_save=save_status, verbose=True)
502
+
503
+
504
+ # ============
505
+ # plot samples
506
+ # ============
507
+
508
+ def plot_samples(x, rho, x_min, x_max, samples, latex=False, save=False):
509
+ """
510
+ """
511
+
512
+ with texplot.theme(use_latex=latex):
513
+
514
+ fig, ax = plt.subplots(figsize=(6, 3))
515
+
516
+ bins = numpy.linspace(x_min, x_max, samples.size // 10)
517
+ _ = ax.hist(samples, bins, density=True, color='silver',
518
+ label='Samples histogram')
519
+ ax.plot(x, rho, color='black', label='Exact density')
520
+ ax.legend(fontsize='small')
521
+ ax.set_ylim(bottom=0)
522
+ ax.set_xlim([x[0], x[-1]])
523
+ ax.set_xlabel(r'$\lambda$')
524
+ ax.set_ylabel(r'$\rho(\lambda)$''')
525
+ ax.set_title('Histogram of Samples from Distribution')
526
+
527
+ # Save
528
+ if save is False:
529
+ save_status = False
530
+ save_filename = ''
531
+ else:
532
+ save_status = True
533
+ if isinstance(save, str):
534
+ save_filename = save
535
+ else:
536
+ save_filename = 'samples.pdf'
537
+
538
+ texplot.show_or_save_plot(plt, default_filename=save_filename,
539
+ transparent_background=True, dpi=400,
499
540
  show_and_save=save_status, verbose=True)
@@ -14,7 +14,7 @@
14
14
  import numpy
15
15
  from scipy.interpolate import interp1d
16
16
  from .._plot_util import plot_density, plot_hilbert, plot_stieltjes, \
17
- plot_stieltjes_on_disk
17
+ plot_stieltjes_on_disk, plot_samples
18
18
 
19
19
  try:
20
20
  from scipy.integrate import cumtrapz
@@ -77,9 +77,7 @@ class MarchenkoPastur(object):
77
77
 
78
78
  .. [1] Marcenko, V. A., Pastur, L. A. (1967). Distribution of eigenvalues
79
79
  for some sets of random matrices. Mathematics of the USSR-Sbornik,
80
- 1(4), 457 (`DOI<
81
- https://iopscience.iop.org/article/10.1070/SM1967v001n04ABEH001994
82
- >`__)
80
+ 1(4), 457
83
81
 
84
82
  Examples
85
83
  --------
@@ -149,6 +147,10 @@ class MarchenkoPastur(object):
149
147
  >>> from freealg.distributions import MarchenkoPastur
150
148
  >>> mp = MarchenkoPastur(1/50)
151
149
  >>> rho = mp.density(plot=True)
150
+
151
+ .. image:: ../_static/images/plots/mp_density.png
152
+ :align: center
153
+ :class: custom-dark
152
154
  """
153
155
 
154
156
  # Create x if not given
@@ -167,8 +169,7 @@ class MarchenkoPastur(object):
167
169
  numpy.sqrt((self.lam_p - x[mask]) * (x[mask] - self.lam_m))
168
170
 
169
171
  if plot:
170
- plot_density(x, rho, support=self.support, label='', latex=latex,
171
- save=save)
172
+ plot_density(x, rho, label='', latex=latex, save=save)
172
173
 
173
174
  return rho
174
175
 
@@ -189,7 +190,7 @@ class MarchenkoPastur(object):
189
190
  spectral density is used.
190
191
 
191
192
  plot : bool, default=False
192
- If `True`, density is plotted.
193
+ If `True`, Hilbert transform is plotted.
193
194
 
194
195
  latex : bool, default=False
195
196
  If `True`, the plot is rendered using LaTeX. This option is
@@ -214,6 +215,10 @@ class MarchenkoPastur(object):
214
215
  >>> from freealg.distributions import MarchenkoPastur
215
216
  >>> mp = MarchenkoPastur(1/50)
216
217
  >>> hilb = mp.hilbert(plot=True)
218
+
219
+ .. image:: ../_static/images/plots/mp_hilbert.png
220
+ :align: center
221
+ :class: custom-dark
217
222
  """
218
223
 
219
224
  # Create x if not given
@@ -225,9 +230,18 @@ class MarchenkoPastur(object):
225
230
  x_max = numpy.ceil(center + radius * scale)
226
231
  x = numpy.linspace(x_min, x_max, 500)
227
232
 
228
- hilb = numpy.zeros_like(x)
229
- mask = numpy.logical_and(x >= self.lam_m, x <= self.lam_p)
230
- hilb[mask] = (x[mask] - 1 - self.lam) / (self.lam * x[mask])
233
+ def _P(x):
234
+ return x - 1 + self.lam
235
+
236
+ def _Q(x):
237
+ return self.lam * x
238
+
239
+ P = _P(x)
240
+ Q = _Q(x)
241
+ Delta2 = P**2 - 4.0 * Q
242
+ Delta = numpy.sqrt(numpy.maximum(Delta2, 0))
243
+ sign = numpy.sign(P)
244
+ hilb = (P - sign * Delta) / (2.0 * Q)
231
245
 
232
246
  # using negative sign convention
233
247
  hilb = -hilb
@@ -319,7 +333,7 @@ class MarchenkoPastur(object):
319
333
  If `None`, a grid on the interval ``[-1, 1]`` is used.
320
334
 
321
335
  plot : bool, default=False
322
- If `True`, density is plotted.
336
+ If `True`, Stieltjes transform is plotted.
323
337
 
324
338
  on_disk : bool, default=False
325
339
  If `True`, the Stieltjes transform is mapped on unit disk. This
@@ -346,12 +360,25 @@ class MarchenkoPastur(object):
346
360
  Examples
347
361
  --------
348
362
 
349
- .. code-block::python
363
+ .. code-block:: python
350
364
 
351
365
  >>> from freealg.distributions import MarchenkoPastur
352
366
  >>> mp = MarchenkoPastur(1/50)
353
367
  >>> m1, m2 = mp.stieltjes(plot=True)
354
368
 
369
+ .. image:: ../_static/images/plots/mp_stieltjes.png
370
+ :align: center
371
+ :class: custom-dark
372
+
373
+ Plot on unit disk using Cayley transform:
374
+
375
+ .. code-block:: python
376
+
377
+ >>> m1, m2 = mp.stieltjes(plot=True, on_disk=True)
378
+
379
+ .. image:: ../_static/images/plots/mp_stieltjes_disk.png
380
+ :align: center
381
+ :class: custom-dark
355
382
  """
356
383
 
357
384
  if (plot is True) and (on_disk is True):
@@ -407,7 +434,8 @@ class MarchenkoPastur(object):
407
434
  # sample
408
435
  # ======
409
436
 
410
- def sample(self, size, x_min=None, x_max=None):
437
+ def sample(self, size, x_min=None, x_max=None, plot=False, latex=False,
438
+ save=False):
411
439
  """
412
440
  Sample from distribution.
413
441
 
@@ -425,6 +453,18 @@ class MarchenkoPastur(object):
425
453
  Maximum of sample values. If `None`, the right edge of the support
426
454
  is used.
427
455
 
456
+ plot : bool, default=False
457
+ If `True`, samples histogram is plotted.
458
+
459
+ latex : bool, default=False
460
+ If `True`, the plot is rendered using LaTeX. This option is
461
+ relevant only if ``plot=True``.
462
+
463
+ save : bool, default=False
464
+ If not `False`, the plot is saved. If a string is given, it is
465
+ assumed to the save filename (with the file extension). This option
466
+ is relevant only if ``plot=True``.
467
+
428
468
  Returns
429
469
  -------
430
470
 
@@ -443,7 +483,11 @@ class MarchenkoPastur(object):
443
483
 
444
484
  >>> from freealg.distributions import MarchenkoPastur
445
485
  >>> mp = MarchenkoPastur(1/50)
446
- >>> s = mp.sample(2000)
486
+
487
+ >>> s = mp.sample(2000)
488
+ .. image:: ../_static/images/plots/mp_samples.png
489
+ :align: center
490
+ :class: custom-dark
447
491
  """
448
492
 
449
493
  if x_min is None:
@@ -466,7 +510,19 @@ class MarchenkoPastur(object):
466
510
 
467
511
  # Sample and map
468
512
  u = numpy.random.rand(size)
469
- return inv_cdf(u)
513
+ samples = inv_cdf(u)
514
+
515
+ if plot:
516
+ radius = 0.5 * (self.lam_p - self.lam_m)
517
+ center = 0.5 * (self.lam_p + self.lam_m)
518
+ scale = 1.25
519
+ x_min = numpy.floor(center - radius * scale)
520
+ x_max = numpy.ceil(center + radius * scale)
521
+ x = numpy.linspace(x_min, x_max, 500)
522
+ rho = self.density(x)
523
+ plot_samples(x, rho, x_min, x_max, samples, latex=latex, save=save)
524
+
525
+ return samples
470
526
 
471
527
  # ======
472
528
  # matrix
@@ -625,7 +625,7 @@ class FreeForm(object):
625
625
  --------
626
626
 
627
627
  density
628
- stiletjes
628
+ stieltjes
629
629
 
630
630
  Notes
631
631
  -----
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: freealg
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Free probability for large matrices
5
5
  Keywords: leaderboard bot chat
6
6
  Platform: Linux
@@ -1 +0,0 @@
1
- __version__ = "0.0.1"
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