Skip to content

Commit 19fa983

Browse files
committed
Correction to alpha=1 formula. Fixes #15.
1 parent 64c525f commit 19fa983

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

levy/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
Parameters.convert to transform the parameters from one parametrization
4141
to another. The module uses internally parametrization 0.
4242
43-
- pylevy does not support alpha values less than 0.5.
43+
- pylevy does not support alpha values lower than 0.5.
4444
"""
4545

4646
import sys
@@ -305,11 +305,14 @@ def _calculate_levy(x, alpha, beta, cdf=False):
305305
if alpha == 1:
306306
li = 1e-10
307307

308+
# These functions need a correction, since the distribution is displaced, probably get rid of "-u" at the end
308309
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))
310312

311313
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))
313316

314317
else:
315318
li = 0
@@ -342,7 +345,9 @@ def _approximate(x, alpha, beta, cdf=False):
342345
values[mask] *= (1.0 + beta)
343346
values[~mask] *= (1.0 - beta)
344347
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
346351
else:
347352
return values * alpha
348353

@@ -603,7 +608,7 @@ def random(alpha, beta, mu=0.0, sigma=1.0, shape=()):
603608
return np.random.standard_normal(shape) * np.sqrt(2.0)
604609

605610
# 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
607612
radius = 1e-15 # <<< this number is *very* small
608613
if np.absolute(alpha - 1.0) < radius:
609614
# So doing this will make almost exactly no difference at all

levy/cdf.npz

0 Bytes
Binary file not shown.

levy/lower_limit.npz

0 Bytes
Binary file not shown.

levy/pdf.npz

0 Bytes
Binary file not shown.

levy/upper_limit.npz

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)