Skip to content

Commit ade2413

Browse files
committed
Bug fixes
1 parent fd86608 commit ade2413

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

code/backprop2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def feedforward(self, a, start=0, end=None):
4242
"""Return the result from feeding forward the activation ``a``
4343
from layer ``start`` through to layer ``end``. Note that if
4444
``end`` is ``None`` then this is interpreted as ``end =
45-
self.num_layers``, i.e., the default behaviour is to propagate
45+
self.num_layers-1``, i.e., the default behaviour is to propagate
4646
through to the end of the network."""
47-
if end == None: end = self.num_layers
47+
if end == None: end = self.num_layers-1
4848
for b, w in zip(self.biases, self.weights)[start:end]:
4949
a = sigmoid_vec(np.dot(w, a)+b)
5050
return a

code/deep_learning.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,21 @@ def add_classifier_layer(net, num_outputs):
3030
return net_classifier
3131

3232
def SGD_final_layer(
33-
self, training_data, epochs, mini_batch_size, eta, lmbda,
34-
test=False, test_inputs=None, actual_test_results=None):
33+
self, training_data, epochs, mini_batch_size, eta, lmbda):
3534
"""
3635
Run SGD on the final layer of the Network ``self``. Note that
3736
``training_data`` is the input to the whole Network, not the
3837
encoded training data input to the final layer.
3938
"""
4039
encoded_training_data = [
41-
(self.feedforward(x, start=0, end=-1), y) for x, y in training_data]
42-
net = Network([self.sizes[-2], self.sizes[-1]])
43-
net.biases[-1] = self.biases[-1]
44-
net.weights[-1] = self.weights[-1]
45-
net.SGD(encoded_training_data, epochs, mini_batch_size, eta,
46-
lmbda, test, test_inputs, actual_test_results)
47-
self.biases[-1] = net.biases[-1]
48-
self.weights[-1] = net.weights[-1]
40+
(self.feedforward(x, start=0, end=self.num_layers-2), y)
41+
for x, y in training_data]
42+
net = Network(self.sizes[-2:])
43+
net.biases[0] = self.biases[-1]
44+
net.weights[0] = self.weights[-1]
45+
net.SGD(encoded_training_data, epochs, mini_batch_size, eta, lmbda)
46+
self.biases[-1] = net.biases[0]
47+
self.weights[-1] = net.weights[0]
4948

5049

5150
# Add the SGD_final_layer method to the Network class

0 commit comments

Comments
 (0)