Skip to content

Instantly share code, notes, and snippets.

@shamdasani
Created August 5, 2017 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamdasani/ec74fa2f08a0b886be16612631e2a372 to your computer and use it in GitHub Desktop.
Save shamdasani/ec74fa2f08a0b886be16612631e2a372 to your computer and use it in GitHub Desktop.
def backward(self, X, y, o):
# backward propgate through the network
self.o_error = y - o # error in output
self.o_delta = self.o_error*self.sigmoidPrime(o) # applying derivative of sigmoid to error
self.z2_error = self.o_delta.dot(self.W2.T) # z2 error: how much our hidden layer weights contributed to output error
self.z2_delta = self.z2_error*self.sigmoidPrime(self.z2) # applying derivative of sigmoid to z2 error
self.W1 += X.T.dot(self.z2_delta) # adjusting first set (input --> hidden) weights
self.W2 += self.z2.T.dot(self.o_delta) # adjusting second set (hidden --> output) weights
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment