Skip to content

Instantly share code, notes, and snippets.

@saisumit
Created September 13, 2017 15:35
Show Gist options
  • Select an option

  • Save saisumit/1fd38d8fb6b5a32b87297273ccb3ebd3 to your computer and use it in GitHub Desktop.

Select an option

Save saisumit/1fd38d8fb6b5a32b87297273ccb3ebd3 to your computer and use it in GitHub Desktop.
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