-
Notifications
You must be signed in to change notification settings - Fork 912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to compute partial derivative? #66
Comments
By the way, both x and y are vectors with float values |
Note that your function import autograd.numpy as np
from autograd import jacobian
def f(x, y):
return np.abs(x - y)
jacobian_f_wrt_x = jacobian(f, 0) # 0 indicates first input element in f(x, y)
jacobian_f_wrt_y = jacobian(f, 1) # 1 indicates second input element in f(x, y)
x = np.arange(-4, 6, 2, dtype=float)
y = np.zeros(5) + 1.5
print(jacobian_f_wrt_x(x, y))
print(jacobian_f_wrt_y(x, y)) Here Likewise, I hope this helps. |
Thank you very much! So I think element wise_grad satisfy my need. Am I correct? |
Yes and no. The Again, I can probably best illustrate this with an example, by adding an interaction between import autograd.numpy as np
from autograd import jacobian
def f(x, y):
return np.abs(x - y + np.dot(x,y))
jacobian_f_wrt_x = jacobian(f, 0) # 0 indicates first input element in f(x, y)
jacobian_f_wrt_y = jacobian(f, 1) # 1 indicates second input element in f(x, y)
x = np.arange(-4, 6, 2, dtype=float)
y = np.zeros(5) + 1.5
print(jacobian_f_wrt_x(x, y))
print(jacobian_f_wrt_y(x, y)) Now the output has changed to
Hope this helps. |
Thanks for you greatful explanations. Now I know what should I do in my project. |
Thanks for the explanations, @brunojacobs! Indeed as pointed out, I thought I'd chime in with one more idea: you might try gluing import autograd.numpy as np
from autograd import grad, elementwise_grad
def f((x, y)):
return np.abs(x - y)
x = np.arange(-4, 6, 2, dtype=float)
y = np.zeros(5) + 1.5
print elementwise_grad(f)((x, y))
In Python 3 you might have to do something like def f(xy):
x, y = xy
return np.abs(x - y) |
Hi All,
I need to compute partial derivative for function like below,
def func(x,y):
return np.abs (x - y)
I need the derivative of x, the derivate of y.
Thanks, Any suggestions will help
The text was updated successfully, but these errors were encountered: