Skip to content

Commit

Permalink
fixed computing gradient
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmarek committed Jun 19, 2012
1 parent cce90c8 commit c908ef8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sklearn/mlp/base_andreas.py
Expand Up @@ -136,12 +136,15 @@ def _backward(self, i, X, y, batch_slice, x_hidden, x_output, delta_o, delta_h):
else:
raise ValueError("Unknown combination of output function and error.")

delta_h[:] = np.dot(delta_o, self.weights2_.T)

self.weights2_ += self.lr / self.batch_size * np.dot(x_hidden.T, delta_o)
self.bias2_ += self.lr * np.mean(delta_o, axis=0)

if self.verbose > 0:
print(np.linalg.norm(delta_o / self.batch_size))
delta_h[:] = np.dot(delta_o, self.weights2_.T) * _dtanh(x_hidden)

delta_h[:] *= _dtanh(x_hidden)

# update weights
self.weights1_ += self.lr / self.batch_size * np.dot(X[batch_slice].T, delta_h)
Expand Down

0 comments on commit c908ef8

Please sign in to comment.