flâneur

Gradients, Backprop, and Derivatives in Tensorflow [Draft]

blog.sdan.net · 479 words · saved by 1 readers

Finding the gradient of f(x,y)=cos⁡x∗sin⁡y+xyf(x,y) = \cos{x}*\sin{y} + \frac{x}{y} Using Numpy, Autograd, and Tensorflow In [76]: #Dependencies import tensorflow as tf from mpl_toolkits import mplot3d import numpy as np import matplotlib.pyplot as plt %matplotlib inline In [126]: import autograd.numpy as np # Thinly wrapped version of numpy from autograd import grad def f(x, y): return np.

Finding the gradient of f(x,y)=cos⁡x∗sin⁡y+xyf(x,y) = \cos{x}*\sin{y} + \frac{x}{y} Using Numpy, Autograd, and Tensorflow In [76]: #Dependencies import tensorflow as tf from mpl_toolkits import mplot3d import numpy as np import matplotlib.pyplot as plt %matplotlib inline In [126]: import autograd.numpy as np # Thinly wrapped version of numpy from autograd import grad def f(x, y): return np.sin(np.sqrt(x ** 2 + y ** 2)) f_grad = grad(f) # magic: returns a function that computes the gradient of f x = 2. y = 0. print (f(x, y)) print (f_grad(x, y)) 0.9092974268256817…

related reading