josemiotto / pylevy

Levy distributions for Python
GNU General Public License v3.0
34 stars 18 forks source link

Numerical Differentiation of stable distributions #6

Closed AntixK closed 5 years ago

AntixK commented 6 years ago

I wish to obtain the numerical derivative of the levy-stable distributions. Here is my sample code -

import levy
from sympy import diff
import numpy as np

alpha = 1.25
x = np.linspace(-2,2,50)
f = lambda z: levy.levy(z, alpha, 0,0,1)
df = lambda x: diff(f, x, 1)
print(f(x))
print(df(x))

But I am not able to compute the derivative. I get the following error

SympifyError: Sympify of expression 'could not parse '<function <lambda> at 0x7f55a4d27158>'' failed, because of exception being raised:
SyntaxError: invalid syntax (<string>, line 1)

Kindly help me with this. Thank you.

AntixK commented 6 years ago

Update : Resolved the problem Since sympy could now parse the lambda function, I used the numdifftools package and it works perfectly.

josemiotto commented 5 years ago

Glad it worked!