|
40 | 40 | Parameters.convert to transform the parameters from one parametrization |
41 | 41 | to another. The module uses internally parametrization 0. |
42 | 42 |
|
43 | | -- pylevy does not support alpha values less than 0.5. |
| 43 | +- pylevy does not support alpha values lower than 0.5. |
44 | 44 | """ |
45 | 45 |
|
46 | 46 | import sys |
@@ -305,11 +305,14 @@ def _calculate_levy(x, alpha, beta, cdf=False): |
305 | 305 | if alpha == 1: |
306 | 306 | li = 1e-10 |
307 | 307 |
|
| 308 | + # These functions need a correction, since the distribution is displaced, probably get rid of "-u" at the end |
308 | 309 | def func_cos(u): |
309 | | - return np.exp(-u) * np.cos(-beta * 2 / np.pi * (u * np.log(u) - u)) |
| 310 | + # return np.exp(-u) * np.cos(-beta * 2 / np.pi * (u * np.log(u) - u)) |
| 311 | + return np.exp(-u) * np.cos(-beta * 2 / np.pi * u * np.log(u)) |
310 | 312 |
|
311 | 313 | def func_sin(u): |
312 | | - return np.exp(-u) * np.sin(-beta * 2 / np.pi * (u * np.log(u) - u)) |
| 314 | + # return np.exp(-u) * np.sin(-beta * 2 / np.pi * (u * np.log(u) - u)) |
| 315 | + return np.exp(-u) * np.sin(-beta * 2 / np.pi * u * np.log(u)) |
313 | 316 |
|
314 | 317 | else: |
315 | 318 | li = 0 |
@@ -342,7 +345,9 @@ def _approximate(x, alpha, beta, cdf=False): |
342 | 345 | values[mask] *= (1.0 + beta) |
343 | 346 | values[~mask] *= (1.0 - beta) |
344 | 347 | if cdf: |
345 | | - return 1.0 - values * x |
| 348 | + values[mask] = 1.0 - values[mask] * x[mask] |
| 349 | + values[~mask] = values[~mask] * (-x[~mask]) |
| 350 | + return values |
346 | 351 | else: |
347 | 352 | return values * alpha |
348 | 353 |
|
@@ -603,7 +608,7 @@ def random(alpha, beta, mu=0.0, sigma=1.0, shape=()): |
603 | 608 | return np.random.standard_normal(shape) * np.sqrt(2.0) |
604 | 609 |
|
605 | 610 | # Fails for alpha exactly equal to 1.0 |
606 | | - # but works fine for alpha infinitesimally greater or less than 1.0 |
| 611 | + # but works fine for alpha infinitesimally greater or lower than 1.0 |
607 | 612 | radius = 1e-15 # <<< this number is *very* small |
608 | 613 | if np.absolute(alpha - 1.0) < radius: |
609 | 614 | # So doing this will make almost exactly no difference at all |
|
0 commit comments