freealg 0.2.0__py3-none-any.whl → 0.3.0__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/__init__.py +3 -2
- freealg/__version__.py +1 -1
- freealg/eigh.py +234 -2
- freealg/freeform.py +4 -3
- {freealg-0.2.0.dist-info → freealg-0.3.0.dist-info}/METADATA +1 -1
- {freealg-0.2.0.dist-info → freealg-0.3.0.dist-info}/RECORD +10 -10
- {freealg-0.2.0.dist-info → freealg-0.3.0.dist-info}/WHEEL +0 -0
- {freealg-0.2.0.dist-info → freealg-0.3.0.dist-info}/licenses/AUTHORS.txt +0 -0
- {freealg-0.2.0.dist-info → freealg-0.3.0.dist-info}/licenses/LICENSE.txt +0 -0
- {freealg-0.2.0.dist-info → freealg-0.3.0.dist-info}/top_level.txt +0 -0
freealg/__init__.py
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
# directory of this source tree.
|
|
8
8
|
|
|
9
9
|
from .freeform import FreeForm
|
|
10
|
-
from .eigh import eigh, cond
|
|
10
|
+
from .eigh import eigh, cond, norm, trace, slogdet
|
|
11
11
|
from . import distributions
|
|
12
12
|
|
|
13
|
-
__all__ = ['FreeForm', 'distributions', 'eigh', 'cond'
|
|
13
|
+
__all__ = ['FreeForm', 'distributions', 'eigh', 'cond', 'norm', 'trace',
|
|
14
|
+
'slogdet']
|
|
14
15
|
|
|
15
16
|
from .__version__ import __version__ # noqa: F401 E402
|
freealg/__version__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.3.0"
|
freealg/eigh.py
CHANGED
|
@@ -14,7 +14,7 @@ import numpy
|
|
|
14
14
|
from ._util import compute_eig
|
|
15
15
|
from .freeform import FreeForm
|
|
16
16
|
|
|
17
|
-
__all__ = ['eigh', 'cond']
|
|
17
|
+
__all__ = ['eigh', 'cond', 'norm', 'trace', 'slogdet']
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
# ====
|
|
@@ -141,7 +141,7 @@ def eigh(A, N=None, psd=None, plots=False):
|
|
|
141
141
|
|
|
142
142
|
def cond(A, N=None):
|
|
143
143
|
"""
|
|
144
|
-
Estimate the condition number of a positive-definite matrix.
|
|
144
|
+
Estimate the condition number of a Hermitian positive-definite matrix.
|
|
145
145
|
|
|
146
146
|
This function estimates the condition number of the matrix
|
|
147
147
|
:math:`\\mathbf{A}` or a larger matrix containing :math:`\\mathbf{A}`
|
|
@@ -170,6 +170,9 @@ def cond(A, N=None):
|
|
|
170
170
|
--------
|
|
171
171
|
|
|
172
172
|
eigh
|
|
173
|
+
norm
|
|
174
|
+
slogdet
|
|
175
|
+
trace
|
|
173
176
|
|
|
174
177
|
Notes
|
|
175
178
|
-----
|
|
@@ -192,3 +195,232 @@ def cond(A, N=None):
|
|
|
192
195
|
|
|
193
196
|
eigs = eigh(A, N)
|
|
194
197
|
return eigs.max() / eigs.min()
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
# ====
|
|
201
|
+
# norm
|
|
202
|
+
# ====
|
|
203
|
+
|
|
204
|
+
def norm(A, N=None, order=None):
|
|
205
|
+
"""
|
|
206
|
+
Estimate the Schatten norm of a Hermitian matrix.
|
|
207
|
+
|
|
208
|
+
This function estimates the norm of the matrix :math:`\\mathbf{A}` or a
|
|
209
|
+
larger matrix containing :math:`\\mathbf{A}` using free decompression.
|
|
210
|
+
|
|
211
|
+
Parameters
|
|
212
|
+
----------
|
|
213
|
+
|
|
214
|
+
A : numpy.ndarray
|
|
215
|
+
The symmetric real-valued matrix :math:`\\mathbf{A}` whose condition
|
|
216
|
+
number (or that of a matrix containing :math:`\\mathbf{A}`) are to be
|
|
217
|
+
computed.
|
|
218
|
+
|
|
219
|
+
N : int, default=None
|
|
220
|
+
The size of the matrix containing :math:`\\mathbf{A}` to estimate
|
|
221
|
+
eigenvalues of. If None, returns estimates of the eigenvalues of
|
|
222
|
+
:math:`\\mathbf{A}` itself.
|
|
223
|
+
|
|
224
|
+
order : {float, ``''inf``, ``'-inf'``, ``'fro'``, ``'nuc'``}, default=2
|
|
225
|
+
Order of the norm.
|
|
226
|
+
|
|
227
|
+
* float :math:`p`: Schtten p-norm.
|
|
228
|
+
* ``'inf'``: Largest absolute eigenvalue
|
|
229
|
+
:math:`\\max \\vert \\lambda_i \\vert)`
|
|
230
|
+
* ``'-inf'``: Smallest absolute eigenvalue
|
|
231
|
+
:math:`\\min \\vert \\lambda_i \\vert)`
|
|
232
|
+
* ``'fro'``: Frobenius norm corresponding to :math:`p=2`
|
|
233
|
+
* ``'nuc'``: Nuclear (or trace) norm corresponding to :math:`p=1`
|
|
234
|
+
|
|
235
|
+
Returns
|
|
236
|
+
-------
|
|
237
|
+
|
|
238
|
+
norm : float
|
|
239
|
+
matrix norm
|
|
240
|
+
|
|
241
|
+
See Also
|
|
242
|
+
--------
|
|
243
|
+
|
|
244
|
+
eigh
|
|
245
|
+
cond
|
|
246
|
+
slogdet
|
|
247
|
+
trace
|
|
248
|
+
|
|
249
|
+
Notes
|
|
250
|
+
-----
|
|
251
|
+
|
|
252
|
+
Thes Schatten :math:`p`-norm is defined by
|
|
253
|
+
|
|
254
|
+
.. math::
|
|
255
|
+
|
|
256
|
+
\\Vert \\mathbf{A} \\Vert_p = \\left(
|
|
257
|
+
\\sum_{i=1}^N \\vert \\lambda_i \\vert^p \\right)^{1/p}.
|
|
258
|
+
|
|
259
|
+
Examples
|
|
260
|
+
--------
|
|
261
|
+
|
|
262
|
+
.. code-block:: python
|
|
263
|
+
:emphasize-lines: 6
|
|
264
|
+
|
|
265
|
+
>>> from freealg import norm
|
|
266
|
+
>>> from freealg.distributions import MarchenkoPastur
|
|
267
|
+
|
|
268
|
+
>>> mp = MarchenkoPastur(1/50)
|
|
269
|
+
>>> A = mp.matrix(3000)
|
|
270
|
+
>>> norm(A, 100_000, order='fro')
|
|
271
|
+
"""
|
|
272
|
+
|
|
273
|
+
eigs = eigh(A, N)
|
|
274
|
+
|
|
275
|
+
if (order == 'inf') or numpy.isinf(order):
|
|
276
|
+
norm_ = max(numpy.abs(eigs))
|
|
277
|
+
|
|
278
|
+
elif (order == '-inf') or numpy.isneginf(order):
|
|
279
|
+
norm_ = min(numpy.abs(eigs))
|
|
280
|
+
|
|
281
|
+
elif (order == 'nuc') or (order == 1.0):
|
|
282
|
+
norm_ = numpy.sum(numpy.abs(eigs))
|
|
283
|
+
|
|
284
|
+
elif (order == 'fro') or (order == 2.0):
|
|
285
|
+
norm_2 = numpy.sum(numpy.abs(eigs)**2)
|
|
286
|
+
norm_ = numpy.sqrt(norm_2)
|
|
287
|
+
|
|
288
|
+
elif isinstance(order, (int, float, numpy.integer, numpy.floating)) and \
|
|
289
|
+
not isinstance(order, (bool, numpy.bool_)):
|
|
290
|
+
norm_q = numpy.sum(numpy.abs(eigs)**order)
|
|
291
|
+
norm_ = norm_q**(1.0 / order)
|
|
292
|
+
|
|
293
|
+
else:
|
|
294
|
+
raise ValueError('"order" is invalid.')
|
|
295
|
+
|
|
296
|
+
return norm_
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
# =====
|
|
300
|
+
# trace
|
|
301
|
+
# =====
|
|
302
|
+
|
|
303
|
+
def trace(A, N=None):
|
|
304
|
+
"""
|
|
305
|
+
Estimate the trace of a Hermitian matrix.
|
|
306
|
+
|
|
307
|
+
This function estimates the trace of the matrix :math:`\\mathbf{A}` or a
|
|
308
|
+
larger matrix containing :math:`\\mathbf{A}` using free decompression.
|
|
309
|
+
|
|
310
|
+
Parameters
|
|
311
|
+
----------
|
|
312
|
+
|
|
313
|
+
A : numpy.ndarray
|
|
314
|
+
The symmetric real-valued matrix :math:`\\mathbf{A}` whose condition
|
|
315
|
+
number (or that of a matrix containing :math:`\\mathbf{A}`) are to be
|
|
316
|
+
computed.
|
|
317
|
+
|
|
318
|
+
N : int, default=None
|
|
319
|
+
The size of the matrix containing :math:`\\mathbf{A}` to estimate
|
|
320
|
+
eigenvalues of. If None, returns estimates of the eigenvalues of
|
|
321
|
+
:math:`\\mathbf{A}` itself.
|
|
322
|
+
|
|
323
|
+
Returns
|
|
324
|
+
-------
|
|
325
|
+
|
|
326
|
+
trace : float
|
|
327
|
+
matrix trace
|
|
328
|
+
|
|
329
|
+
See Also
|
|
330
|
+
--------
|
|
331
|
+
|
|
332
|
+
eigh
|
|
333
|
+
cond
|
|
334
|
+
slogdet
|
|
335
|
+
norm
|
|
336
|
+
|
|
337
|
+
Notes
|
|
338
|
+
-----
|
|
339
|
+
|
|
340
|
+
This is a convenience function using :func:`freealg.eigh`.
|
|
341
|
+
|
|
342
|
+
Examples
|
|
343
|
+
--------
|
|
344
|
+
|
|
345
|
+
.. code-block:: python
|
|
346
|
+
:emphasize-lines: 6
|
|
347
|
+
|
|
348
|
+
>>> from freealg import norm
|
|
349
|
+
>>> from freealg.distributions import MarchenkoPastur
|
|
350
|
+
|
|
351
|
+
>>> mp = MarchenkoPastur(1/50)
|
|
352
|
+
>>> A = mp.matrix(3000)
|
|
353
|
+
>>> trace(A, 100_000)
|
|
354
|
+
"""
|
|
355
|
+
|
|
356
|
+
eigs = eigh(A, N)
|
|
357
|
+
trace_ = numpy.sum(eigs)
|
|
358
|
+
|
|
359
|
+
return trace_
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
# =======
|
|
363
|
+
# slogdet
|
|
364
|
+
# =======
|
|
365
|
+
|
|
366
|
+
def slogdet(A, N=None):
|
|
367
|
+
"""
|
|
368
|
+
Estimate the sign and logarithm of the determinant of a Hermitian matrix.
|
|
369
|
+
|
|
370
|
+
This function estimates the *slogdet* of the matrix :math:`\\mathbf{A}` or
|
|
371
|
+
a larger matrix containing :math:`\\mathbf{A}` using free decompression.
|
|
372
|
+
|
|
373
|
+
Parameters
|
|
374
|
+
----------
|
|
375
|
+
|
|
376
|
+
A : numpy.ndarray
|
|
377
|
+
The symmetric real-valued matrix :math:`\\mathbf{A}` whose condition
|
|
378
|
+
number (or that of a matrix containing :math:`\\mathbf{A}`) are to be
|
|
379
|
+
computed.
|
|
380
|
+
|
|
381
|
+
N : int, default=None
|
|
382
|
+
The size of the matrix containing :math:`\\mathbf{A}` to estimate
|
|
383
|
+
eigenvalues of. If None, returns estimates of the eigenvalues of
|
|
384
|
+
:math:`\\mathbf{A}` itself.
|
|
385
|
+
|
|
386
|
+
Returns
|
|
387
|
+
-------
|
|
388
|
+
|
|
389
|
+
sign : float
|
|
390
|
+
Sign of determinant
|
|
391
|
+
|
|
392
|
+
ld : float
|
|
393
|
+
natural logarithm of the absolute value of the determinant
|
|
394
|
+
|
|
395
|
+
See Also
|
|
396
|
+
--------
|
|
397
|
+
|
|
398
|
+
eigh
|
|
399
|
+
cond
|
|
400
|
+
trace
|
|
401
|
+
norm
|
|
402
|
+
|
|
403
|
+
Notes
|
|
404
|
+
-----
|
|
405
|
+
|
|
406
|
+
This is a convenience function using :func:`freealg.eigh`.
|
|
407
|
+
|
|
408
|
+
Examples
|
|
409
|
+
--------
|
|
410
|
+
|
|
411
|
+
.. code-block:: python
|
|
412
|
+
:emphasize-lines: 6
|
|
413
|
+
|
|
414
|
+
>>> from freealg import norm
|
|
415
|
+
>>> from freealg.distributions import MarchenkoPastur
|
|
416
|
+
|
|
417
|
+
>>> mp = MarchenkoPastur(1/50)
|
|
418
|
+
>>> A = mp.matrix(3000)
|
|
419
|
+
>>> sign, ld = slogdet(A, 100_000)
|
|
420
|
+
"""
|
|
421
|
+
|
|
422
|
+
eigs = eigh(A, N)
|
|
423
|
+
sign = numpy.prod(numpy.sign(eigs))
|
|
424
|
+
ld = numpy.sum(numpy.log(numpy.abs(eigs)))
|
|
425
|
+
|
|
426
|
+
return sign, ld
|
freealg/freeform.py
CHANGED
|
@@ -59,13 +59,14 @@ class FreeForm(object):
|
|
|
59
59
|
Size of perturbations into the upper half plane for Plemelj's
|
|
60
60
|
formula.
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
**kwargs : dict, optional
|
|
63
|
+
Parameters for the ``detect_support`` function can also be prescribed
|
|
64
|
+
here when ``support=None``.
|
|
64
65
|
|
|
65
66
|
Notes
|
|
66
67
|
-----
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
TBD
|
|
69
70
|
|
|
70
71
|
References
|
|
71
72
|
----------
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
freealg/__init__.py,sha256=
|
|
2
|
-
freealg/__version__.py,sha256=
|
|
1
|
+
freealg/__init__.py,sha256=AM0G2tX7sBgzCTcOVbWynA9NFkQZKyphL9IR1tKOoK4,614
|
|
2
|
+
freealg/__version__.py,sha256=VrXpHDu3erkzwl_WXrqINBm9xWkcyUy53IQOj042dOs,22
|
|
3
3
|
freealg/_chebyshev.py,sha256=dsAj3YEpmkzB65smluZ0Fi5IZSdpnQXBSIuKMg19grA,5523
|
|
4
4
|
freealg/_damp.py,sha256=k2vtBtWOxQBf4qXaWu_En81lQBXbEO4QbxxWpvuVhdE,1802
|
|
5
5
|
freealg/_decompress.py,sha256=0MYoO3lqwMgNYlVriaRNUqUwY3XYyZZsDAtNRBq6rhE,10470
|
|
@@ -9,17 +9,17 @@ freealg/_plot_util.py,sha256=U4alp7Pzg315_7jJdu1UB0tIUcxUovQgHDHsUYoa2Z0,19728
|
|
|
9
9
|
freealg/_sample.py,sha256=ckC75eqv-mRP1F5BnhvsjfLTaoAzHK8bebl9bCRZYDo,2561
|
|
10
10
|
freealg/_support.py,sha256=sxp867DxfmvYqyQNOyla3zlcVyxm7KL0M-fxZaRIw8E,6299
|
|
11
11
|
freealg/_util.py,sha256=8Tvz-XODtKYoU76ODmF1TBaIYLlr6-AXiyoMDwDSxVg,3779
|
|
12
|
-
freealg/eigh.py,sha256=
|
|
13
|
-
freealg/freeform.py,sha256=
|
|
12
|
+
freealg/eigh.py,sha256=Vm9kLiksmOhsbsxUH7vBtAAKEtwR_RHeEDJCH4Qkr28,10109
|
|
13
|
+
freealg/freeform.py,sha256=8emyCQ6AUjp_HB1gWQ-ecddlDgfxHGr3PqXSyoPxeMo,28593
|
|
14
14
|
freealg/distributions/__init__.py,sha256=t_yZyEkW_W_tSV9IvgYXtVASxD2BEdiNVXcV2ebMy8M,579
|
|
15
15
|
freealg/distributions/_kesten_mckay.py,sha256=210RF2OQEYLZBeLB6wmbdHnZPs_9ldDNHm_FMlg5tis,19881
|
|
16
16
|
freealg/distributions/_marchenko_pastur.py,sha256=kchFccRMuVF2Cus_99vdEwuRimkHzEUV8xt5kZFg7ZI,16994
|
|
17
17
|
freealg/distributions/_meixner.py,sha256=ws7t_EUa7V0s97dgMQIJLv1b6qMLqf9fLLbTJQudf_8,17512
|
|
18
18
|
freealg/distributions/_wachter.py,sha256=Hna_MXqAPjuRkeilLPMf4Xg_3C6tTu5oZLEQnA-RuE4,16897
|
|
19
19
|
freealg/distributions/_wigner.py,sha256=SxgPLtvIVBi9m4De-oBD0x6-2Je_eBqpDrpDYcoLuis,15871
|
|
20
|
-
freealg-0.
|
|
21
|
-
freealg-0.
|
|
22
|
-
freealg-0.
|
|
23
|
-
freealg-0.
|
|
24
|
-
freealg-0.
|
|
25
|
-
freealg-0.
|
|
20
|
+
freealg-0.3.0.dist-info/licenses/AUTHORS.txt,sha256=0b67Nz4_JgIzUupHJTAZxu5QdSUM_HRM_X_w4xCb17o,30
|
|
21
|
+
freealg-0.3.0.dist-info/licenses/LICENSE.txt,sha256=J-EEYEtxb3VVf_Bn1TYfWnpY5lMFIM15iLDDcnaDTPA,1443
|
|
22
|
+
freealg-0.3.0.dist-info/METADATA,sha256=Z9HFCclNCRzFORlR2dQ6pzvPmAJfa5-Dxpee67QxqdM,4496
|
|
23
|
+
freealg-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
24
|
+
freealg-0.3.0.dist-info/top_level.txt,sha256=eR2wrgYwDdnnJ9Zf5PruPqe4kQav0GMvRsqct6y00Q8,8
|
|
25
|
+
freealg-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|