freealg 0.1.5__tar.gz → 0.1.6__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 (32) hide show
  1. {freealg-0.1.5/freealg.egg-info → freealg-0.1.6}/PKG-INFO +1 -1
  2. freealg-0.1.6/freealg/__version__.py +1 -0
  3. {freealg-0.1.5 → freealg-0.1.6}/freealg/_decompress.py +45 -1
  4. {freealg-0.1.5 → freealg-0.1.6}/freealg/_plot_util.py +37 -1
  5. {freealg-0.1.5 → freealg-0.1.6}/freealg/freeform.py +9 -2
  6. {freealg-0.1.5 → freealg-0.1.6/freealg.egg-info}/PKG-INFO +1 -1
  7. freealg-0.1.5/freealg/__version__.py +0 -1
  8. {freealg-0.1.5 → freealg-0.1.6}/CHANGELOG.rst +0 -0
  9. {freealg-0.1.5 → freealg-0.1.6}/LICENSE.txt +0 -0
  10. {freealg-0.1.5 → freealg-0.1.6}/MANIFEST.in +0 -0
  11. {freealg-0.1.5 → freealg-0.1.6}/README.rst +0 -0
  12. {freealg-0.1.5 → freealg-0.1.6}/freealg/__init__.py +0 -0
  13. {freealg-0.1.5 → freealg-0.1.6}/freealg/_chebyshev.py +0 -0
  14. {freealg-0.1.5 → freealg-0.1.6}/freealg/_damp.py +0 -0
  15. {freealg-0.1.5 → freealg-0.1.6}/freealg/_jacobi.py +0 -0
  16. {freealg-0.1.5 → freealg-0.1.6}/freealg/_pade.py +0 -0
  17. {freealg-0.1.5 → freealg-0.1.6}/freealg/_sample.py +0 -0
  18. {freealg-0.1.5 → freealg-0.1.6}/freealg/_util.py +0 -0
  19. {freealg-0.1.5 → freealg-0.1.6}/freealg/distributions/__init__.py +0 -0
  20. {freealg-0.1.5 → freealg-0.1.6}/freealg/distributions/kesten_mckay.py +0 -0
  21. {freealg-0.1.5 → freealg-0.1.6}/freealg/distributions/marchenko_pastur.py +0 -0
  22. {freealg-0.1.5 → freealg-0.1.6}/freealg/distributions/wachter.py +0 -0
  23. {freealg-0.1.5 → freealg-0.1.6}/freealg/distributions/wigner.py +0 -0
  24. {freealg-0.1.5 → freealg-0.1.6}/freealg.egg-info/SOURCES.txt +0 -0
  25. {freealg-0.1.5 → freealg-0.1.6}/freealg.egg-info/dependency_links.txt +0 -0
  26. {freealg-0.1.5 → freealg-0.1.6}/freealg.egg-info/not-zip-safe +0 -0
  27. {freealg-0.1.5 → freealg-0.1.6}/freealg.egg-info/requires.txt +0 -0
  28. {freealg-0.1.5 → freealg-0.1.6}/freealg.egg-info/top_level.txt +0 -0
  29. {freealg-0.1.5 → freealg-0.1.6}/pyproject.toml +0 -0
  30. {freealg-0.1.5 → freealg-0.1.6}/requirements.txt +0 -0
  31. {freealg-0.1.5 → freealg-0.1.6}/setup.cfg +0 -0
  32. {freealg-0.1.5 → freealg-0.1.6}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: freealg
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: Free probability for large matrices
5
5
  Keywords: leaderboard bot chat
6
6
  Platform: Linux
@@ -0,0 +1 @@
1
+ __version__ = "0.1.6"
@@ -11,8 +11,9 @@
11
11
  # =======
12
12
 
13
13
  import numpy
14
+ # from scipy.integrate import solve_ivp
14
15
 
15
- __all__ = ['decompress']
16
+ __all__ = ['decompress', 'reverse_characteristics']
16
17
 
17
18
 
18
19
  # ==========
@@ -134,3 +135,46 @@ def decompress(matrix, size, x=None, delta=1e-4, iterations=500, step_size=0.1,
134
135
  rho = rho.reshape(*x.shape)
135
136
 
136
137
  return rho, x, (lb, ub)
138
+
139
+
140
+ # =======================
141
+ # reverse characteristics
142
+ # =======================
143
+
144
+ def reverse_characteristics(matrix, z_inits, T, iterations=500, step_size=0.1,
145
+ tolerance=1e-8):
146
+ """
147
+ """
148
+
149
+ t_span = (0, T)
150
+ t_eval = numpy.linspace(t_span[0], t_span[1], 50)
151
+
152
+ m = matrix._eval_stieltjes
153
+
154
+ def _char_z(z, t):
155
+ return z + (1 / m(z)[1]) * (1 - numpy.exp(t))
156
+
157
+ target_z, target_t = numpy.meshgrid(z_inits, t_eval)
158
+
159
+ z = numpy.full(target_z.shape, numpy.mean(matrix.support) - .1j,
160
+ dtype=numpy.complex128)
161
+
162
+ # Broken Newton steps can produce a lot of warnings. Removing them for now.
163
+ with numpy.errstate(all='ignore'):
164
+ for _ in range(iterations):
165
+ objective = _char_z(z, target_t) - target_z
166
+ mask = numpy.abs(objective) >= tolerance
167
+ if not numpy.any(mask):
168
+ break
169
+ z_m = z[mask]
170
+ t_m = target_t[mask]
171
+
172
+ # Perform finite difference approximation
173
+ dfdz = _char_z(z_m+tolerance, t_m) - _char_z(z_m-tolerance, t_m)
174
+ dfdz /= 2*tolerance
175
+ dfdz[dfdz == 0] = 1.0
176
+
177
+ # Perform Newton step
178
+ z[mask] = z_m - step_size * objective[mask] / dfdz
179
+
180
+ return z
@@ -18,6 +18,7 @@ import matplotlib
18
18
  import colorsys
19
19
  import matplotlib.ticker as ticker
20
20
  import matplotlib.gridspec as gridspec
21
+ from ._decompress import reverse_characteristics
21
22
 
22
23
  __all__ = ['plot_fit', 'plot_density', 'plot_hilbert', 'plot_stieltjes',
23
24
  'plot_stieltjes_on_disk']
@@ -243,11 +244,42 @@ def _value_formatter(v, pos):
243
244
  return f"{m_val:.1f}"
244
245
 
245
246
 
247
+ # ================
248
+ # plot char curves
249
+ # ================
250
+ def _plot_char_curves(ax, char_curves):
251
+ """
252
+ """
253
+
254
+ curves = reverse_characteristics(char_curves['matrix'],
255
+ char_curves['z'], 4)
256
+ lw = 2
257
+ for idx in range(curves.shape[1]):
258
+
259
+ creal, cimag = curves[:, idx].real, curves[:, idx].imag
260
+
261
+ ax.plot(creal, cimag, ':', color='white', linewidth=lw,
262
+ alpha=0.75)
263
+
264
+ ax.annotate(
265
+ '', # no text
266
+ xy=(creal[-1], cimag[-1]), # arrow tip at final point
267
+ xytext=(creal[-2], cimag[-2]), # tail at penultimate point
268
+ arrowprops=dict(
269
+ arrowstyle='-|>', # simple arrow head
270
+ mutation_scale=5, # size of the head
271
+ color='white',
272
+ lw=lw, alpha=0.75, # arrow shaft line width
273
+ )
274
+ )
275
+
276
+
246
277
  # ==============
247
278
  # plot stieltjes
248
279
  # ==============
249
280
 
250
- def plot_stieltjes(x, y, m1, m2, support, latex=False, save=False):
281
+ def plot_stieltjes(x, y, m1, m2, support, latex=False, char_curves=None,
282
+ save=False):
251
283
  """
252
284
  """
253
285
 
@@ -297,6 +329,10 @@ def plot_stieltjes(x, y, m1, m2, support, latex=False, save=False):
297
329
  ax1.set_xlim([x_min, x_max])
298
330
  ax1.set_ylim([y_min, y_max])
299
331
 
332
+ # Plot characteristic curves
333
+ if char_curves is not None:
334
+ _plot_char_curves(ax1, char_curves)
335
+
300
336
  pos = ax1.get_position()
301
337
  cbar_width = 0.013
302
338
  pad = 0.013
@@ -631,7 +631,8 @@ class FreeForm(object):
631
631
  # stieltjes
632
632
  # =========
633
633
 
634
- def stieltjes(self, x, y, plot=False, latex=False, save=False):
634
+ def stieltjes(self, x, y, plot=False, latex=False, char_curves=None,
635
+ save=False):
635
636
  """
636
637
  Compute Stieltjes transform of the spectral density over a 2D Cartesian
637
638
  grid on the complex plane.
@@ -655,6 +656,10 @@ class FreeForm(object):
655
656
  If `True`, the plot is rendered using LaTeX. This option is
656
657
  relevant only if ``plot=True``.
657
658
 
659
+ char_curves : numpy.array, default=None
660
+ If ``plot=True``, also plot characteristic curves starting from
661
+ these locations.
662
+
658
663
  save : bool, default=False
659
664
  If not `False`, the plot is saved. If a string is given, it is
660
665
  assumed to the save filename (with the file extension). This option
@@ -742,7 +747,9 @@ class FreeForm(object):
742
747
  m2[mask_m, :] = -m1[mask_m, :] + self._glue(z[mask_m, :])
743
748
 
744
749
  if plot:
745
- plot_stieltjes(x, y, m1, m2, self.support, latex=latex, save=save)
750
+ plot_stieltjes(x, y, m1, m2, self.support, latex=latex,
751
+ char_curves={'matrix': self, 'z': char_curves},
752
+ save=save)
746
753
 
747
754
  return m1, m2
748
755
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: freealg
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: Free probability for large matrices
5
5
  Keywords: leaderboard bot chat
6
6
  Platform: Linux
@@ -1 +0,0 @@
1
- __version__ = "0.1.5"
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