@@ -42,7 +42,7 @@ def feedforward(self, a):
42
42
return a
43
43
44
44
def SGD (self , training_data , epochs , mini_batch_size , eta ,
45
- lmbda , test_data = None ):
45
+ test_data = None ):
46
46
"""Train the neural network using mini-batch stochastic
47
47
gradient descent. The ``training_data`` is a list of tuples
48
48
``(x, y)`` representing the training inputs and the desired
@@ -59,14 +59,14 @@ def SGD(self, training_data, epochs, mini_batch_size, eta,
59
59
training_data [k :k + mini_batch_size ]
60
60
for k in xrange (0 , n , mini_batch_size )]
61
61
for mini_batch in mini_batches :
62
- self .backprop (mini_batch , n , eta , lmbda )
62
+ self .backprop (mini_batch , n , eta )
63
63
if test_data :
64
64
print "Epoch {}: {} / {}" .format (
65
65
j , self .evaluate (test_data ), n_test )
66
66
else :
67
67
print "Epoch %s complete" % j
68
68
69
- def backprop (self , training_data , n , eta , lmbda ):
69
+ def backprop (self , training_data , n , eta ):
70
70
"""Update the network's weights and biases by applying a
71
71
single iteration of gradient descent using backpropagation.
72
72
The ``training_data`` is a list of tuples ``(x, y)``. It need
@@ -77,7 +77,6 @@ def backprop(self, training_data, n, eta, lmbda):
77
77
self-explanatory."""
78
78
nabla_b = [np .zeros (b .shape ) for b in self .biases ]
79
79
nabla_w = [np .zeros (w .shape ) for w in self .weights ]
80
- B = len (training_data )
81
80
for x , y in training_data :
82
81
# feedforward
83
82
activation = x
@@ -105,8 +104,6 @@ def backprop(self, training_data, n, eta, lmbda):
105
104
delta = np .dot (self .weights [- l + 1 ].transpose (), delta ) * spv
106
105
nabla_b [- l ] += delta
107
106
nabla_w [- l ] += np .dot (delta , activations [- l - 1 ].transpose ())
108
- # Add the regularization terms to the gradient for the weights
109
- nabla_w = [nw + (lmbda * B / n )* w for nw , w in zip (nabla_w , self .weights )]
110
107
self .weights = [w - eta * nw for w , nw in zip (self .weights , nabla_w )]
111
108
self .biases = [b - eta * nb for b , nb in zip (self .biases , nabla_b )]
112
109
@@ -121,15 +118,12 @@ def evaluate(self, test_data):
121
118
122
119
def cost (self , x , y ):
123
120
"""Return the quadratic cost associated to the network, with
124
- input ``x`` and desired output ``y``. Note that there is no
125
- regularization."""
121
+ input ``x`` and desired output ``y``."""
126
122
return np .sum ((self .feedforward (x )- y )** 2 )/ 2.0
127
123
128
124
def cost_derivative (self , output_activations , y ):
129
125
"""Return the vector of partial derivatives \partial C_x /
130
- \partial a for the output activations, ``a``. For the
131
- unregularized quadratic cost this is just the difference
132
- between the output activations and the desired output, ``y``."""
126
+ \partial a for the output activations, ``a``."""
133
127
return (output_activations - y )
134
128
135
129
#### Miscellaneous functions
0 commit comments