freealg 0.0.1__py3-none-any.whl → 0.0.2__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 +1 -1
- freealg/_plot_util.py +47 -6
- freealg/distributions/marchenko_pastur.py +71 -15
- freealg/freeform.py +1 -1
- {freealg-0.0.1.dist-info → freealg-0.0.2.dist-info}/METADATA +1 -21
- freealg-0.0.2.dist-info/RECORD +16 -0
- freealg-0.0.1.dist-info/RECORD +0 -16
- {freealg-0.0.1.dist-info → freealg-0.0.2.dist-info}/WHEEL +0 -0
- {freealg-0.0.1.dist-info → freealg-0.0.2.dist-info}/licenses/LICENSE.txt +0 -0
- {freealg-0.0.1.dist-info → freealg-0.0.2.dist-info}/top_level.txt +0 -0
freealg/__version__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.0.
|
|
1
|
+
__version__ = "0.0.2"
|
freealg/_plot_util.py
CHANGED
|
@@ -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=
|
|
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=
|
|
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=
|
|
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=
|
|
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=
|
|
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=
|
|
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
|
|
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,
|
|
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`,
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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`,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
freealg/freeform.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: freealg
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.2
|
|
4
4
|
Summary: Free probability for large matrices
|
|
5
5
|
Keywords: leaderboard bot chat
|
|
6
6
|
Platform: Linux
|
|
@@ -30,27 +30,7 @@ Requires-Dist: texplot
|
|
|
30
30
|
Requires-Dist: matplotlib
|
|
31
31
|
Requires-Dist: colorcet
|
|
32
32
|
Provides-Extra: test
|
|
33
|
-
Requires-Dist: tox; extra == "test"
|
|
34
|
-
Requires-Dist: pytest-cov; extra == "test"
|
|
35
|
-
Requires-Dist: codecov; extra == "test"
|
|
36
33
|
Provides-Extra: docs
|
|
37
|
-
Requires-Dist: sphinx; extra == "docs"
|
|
38
|
-
Requires-Dist: sphinx-math-dollar; extra == "docs"
|
|
39
|
-
Requires-Dist: sphinx-toggleprompt<0.4; extra == "docs"
|
|
40
|
-
Requires-Dist: pydata_sphinx_theme==0.9.0; extra == "docs"
|
|
41
|
-
Requires-Dist: graphviz; extra == "docs"
|
|
42
|
-
Requires-Dist: sphinx-automodapi; extra == "docs"
|
|
43
|
-
Requires-Dist: numpydoc; extra == "docs"
|
|
44
|
-
Requires-Dist: nbsphinx; extra == "docs"
|
|
45
|
-
Requires-Dist: sphinx_design; extra == "docs"
|
|
46
|
-
Requires-Dist: sphinx-multitoc-numbering; extra == "docs"
|
|
47
|
-
Requires-Dist: pandoc; extra == "docs"
|
|
48
|
-
Requires-Dist: sphinx-prompt; extra == "docs"
|
|
49
|
-
Requires-Dist: sphinx-copybutton; extra == "docs"
|
|
50
|
-
Requires-Dist: sphinx-gallery; extra == "docs"
|
|
51
|
-
Requires-Dist: sphinxcontrib-youtube; extra == "docs"
|
|
52
|
-
Requires-Dist: sphinxext-opengraph; extra == "docs"
|
|
53
|
-
Requires-Dist: sphinx-argparse; extra == "docs"
|
|
54
34
|
Dynamic: classifier
|
|
55
35
|
Dynamic: description
|
|
56
36
|
Dynamic: description-content-type
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
freealg/__init__.py,sha256=K92neXJZ9VE1U_j_pj28Qyq1MzlMXhOuYK2ZihgwCaU,463
|
|
2
|
+
freealg/__version__.py,sha256=QvlVh4JTl3JL7jQAja76yKtT-IvF4631ASjWY1wS6AQ,22
|
|
3
|
+
freealg/_chebyshev.py,sha256=Cw48gXF6kd3IAQuLTEWadySeKGnY9TynzX9MNmycMUU,4697
|
|
4
|
+
freealg/_damp.py,sha256=k2vtBtWOxQBf4qXaWu_En81lQBXbEO4QbxxWpvuVhdE,1802
|
|
5
|
+
freealg/_jacobi.py,sha256=F9K0IzbExpxGQY2OJQb-XT4Ee1zWTZvMXRUdU8cbwSE,4916
|
|
6
|
+
freealg/_pade.py,sha256=rWILLpEL910YdixC2c5Cw77HqogAYoxi2YZgRVXEELM,4022
|
|
7
|
+
freealg/_plot_util.py,sha256=OILqOqKdLGEabk41KnmxNftItzMMFHOL-LZ35yNvdyk,18653
|
|
8
|
+
freealg/_util.py,sha256=wJ-t8LMZZFEr2PsZEVqTJP_jQTQ3rHUf0dO27F6L7YQ,2310
|
|
9
|
+
freealg/freeform.py,sha256=LLkGoPLxvn8VMHuVQ1LGNkcAYZUi3GduFB8qlsr69qg,18595
|
|
10
|
+
freealg/distributions/__init__.py,sha256=7t4HbP_EofiFDYLH6jbD94AIumOdcHn1y_Qo54mpLFM,614
|
|
11
|
+
freealg/distributions/marchenko_pastur.py,sha256=k8SoEgB2DFXLqGF-Hyqm8Sfh1DlF3khMssuxak5Uaqw,15827
|
|
12
|
+
freealg-0.0.2.dist-info/licenses/LICENSE.txt,sha256=J-EEYEtxb3VVf_Bn1TYfWnpY5lMFIM15iLDDcnaDTPA,1443
|
|
13
|
+
freealg-0.0.2.dist-info/METADATA,sha256=lMjLvkUpPUAr_QPthjnrIfg9KTs8DLEpTG68w8Ak0rU,2888
|
|
14
|
+
freealg-0.0.2.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
|
15
|
+
freealg-0.0.2.dist-info/top_level.txt,sha256=eR2wrgYwDdnnJ9Zf5PruPqe4kQav0GMvRsqct6y00Q8,8
|
|
16
|
+
freealg-0.0.2.dist-info/RECORD,,
|
freealg-0.0.1.dist-info/RECORD
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
freealg/__init__.py,sha256=K92neXJZ9VE1U_j_pj28Qyq1MzlMXhOuYK2ZihgwCaU,463
|
|
2
|
-
freealg/__version__.py,sha256=sXLh7g3KC4QCFxcZGBTpG2scR7hmmBsMjq6LqRptkRg,22
|
|
3
|
-
freealg/_chebyshev.py,sha256=Cw48gXF6kd3IAQuLTEWadySeKGnY9TynzX9MNmycMUU,4697
|
|
4
|
-
freealg/_damp.py,sha256=k2vtBtWOxQBf4qXaWu_En81lQBXbEO4QbxxWpvuVhdE,1802
|
|
5
|
-
freealg/_jacobi.py,sha256=F9K0IzbExpxGQY2OJQb-XT4Ee1zWTZvMXRUdU8cbwSE,4916
|
|
6
|
-
freealg/_pade.py,sha256=rWILLpEL910YdixC2c5Cw77HqogAYoxi2YZgRVXEELM,4022
|
|
7
|
-
freealg/_plot_util.py,sha256=RfGBV25-tEkdoo-RzgSllQH80WV8tOeXmDr_0B8au0w,17347
|
|
8
|
-
freealg/_util.py,sha256=wJ-t8LMZZFEr2PsZEVqTJP_jQTQ3rHUf0dO27F6L7YQ,2310
|
|
9
|
-
freealg/freeform.py,sha256=4njw6OZw5pH9omm18ioLx3WHP0L0-Y663A7bleZWC0o,18595
|
|
10
|
-
freealg/distributions/__init__.py,sha256=7t4HbP_EofiFDYLH6jbD94AIumOdcHn1y_Qo54mpLFM,614
|
|
11
|
-
freealg/distributions/marchenko_pastur.py,sha256=eAH1qlHgxCPPqOh8WucJgYnrHDqV4x4mif1rTKIBFDE,14079
|
|
12
|
-
freealg-0.0.1.dist-info/licenses/LICENSE.txt,sha256=J-EEYEtxb3VVf_Bn1TYfWnpY5lMFIM15iLDDcnaDTPA,1443
|
|
13
|
-
freealg-0.0.1.dist-info/METADATA,sha256=nm9YVJz4d-3BBPowFGbfSXkGFctl9sEvqEUI-sOf1JE,3825
|
|
14
|
-
freealg-0.0.1.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
|
15
|
-
freealg-0.0.1.dist-info/top_level.txt,sha256=eR2wrgYwDdnnJ9Zf5PruPqe4kQav0GMvRsqct6y00Q8,8
|
|
16
|
-
freealg-0.0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|