Created
September 13, 2017 15:35
-
-
Save saisumit/1fd38d8fb6b5a32b87297273ccb3ebd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| w = [2,-3,-3] # assume some random weights and data | |
| x = [-1, -2] | |
| # forward pass | |
| dot = w[0]*x[0] + w[1]*x[1] + w[2] | |
| f = 1.0 / (1 + math.exp(-dot)) # sigmoid function | |
| # backward pass through the neuron (backpropagation) | |
| ddot = (1 - f) * f # gradient on dot variable, using the sigmoid gradient derivation | |
| dx = [w[0] * ddot, w[1] * ddot] # backprop into x | |
| dw = [x[0] * ddot, x[1] * ddot, 1.0 * ddot] # backprop into w | |
| # we're done! we have the gradients on the inputs to the circuit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment