fix: slight modification to MLP mapping to reduce potential for numpy overflows and unnecessary computation

This commit is contained in:
Chris Tomaszewski 2017-09-12 18:04:18 -04:00
parent 5e4f9c69c3
commit cb4f05296f

View file

@ -35,7 +35,7 @@ class MLP(Mapping):
# Backpropagation to hidden layer.
dL_dact = np.dot(dL_dF, self.W2.T)
dL_dlayer1 = dL_dact / np.square(np.cosh(layer1))
dL_dlayer1 = dL_dact * (1 - np.power(activations, 2))
# Finally, evaluate the first-layer gradients.
self.W1.gradient = np.dot(X.T,dL_dlayer1)
@ -47,7 +47,7 @@ class MLP(Mapping):
# Backpropagation to hidden layer.
dL_dact = np.dot(dL_dF, self.W2.T)
dL_dlayer1 = dL_dact / np.square(np.cosh(layer1))
dL_dlayer1 = dL_dact * (1 - np.power(activations, 2))
return np.dot(dL_dlayer1, self.W1.T)