1
1
"""
2
- network_basic
3
- ~~~~~~~~~~~~~~
2
+ network_basic
3
+ ~~~~~~~~~~~~~
4
4
5
5
A module to implement the stochastic gradient descent learning
6
6
algorithm for a feedforward neural network. Gradients are calculated
@@ -42,18 +42,16 @@ 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 = False , test_data = None ):
45
+ lmbda , 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
49
49
outputs. The other non-optional parameters are
50
- self-explanatory. Set ``test`` to ``True`` to evaluate the
51
- network against the test data after each epoch, and to print
52
- out partial progress. This is useful for tracking progress,
53
- but slows things down substantially. If ``test`` is set, then
54
- appropriate ``test_data`` must be supplied.
55
- """
56
- if test : n_test = len (test_data )
50
+ self-explanatory. If ``test_data`` is provided then the
51
+ network will be evaluated against the test data after each
52
+ epoch, and partial progress printed out. This is useful for
53
+ tracking progress, but slows things down substantially."""
54
+ if test_data : n_test = len (test_data )
57
55
n = len (training_data )
58
56
for j in xrange (epochs ):
59
57
random .shuffle (training_data )
@@ -62,7 +60,7 @@ def SGD(self, training_data, epochs, mini_batch_size, eta,
62
60
for k in xrange (0 , n , mini_batch_size )]
63
61
for mini_batch in mini_batches :
64
62
self .backprop (mini_batch , n , eta , lmbda )
65
- if test :
63
+ if test_data :
66
64
print "Epoch {}: {} / {}" .format (
67
65
j , self .evaluate (test_data ), n_test )
68
66
else :
0 commit comments