Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ def SGD(self, training_data, epochs, mini_batch_size, eta,
network will be evaluated against the test data after each
epoch, and partial progress printed out. This is useful for
tracking progress, but slows things down substantially."""
if test_data: n_test = len(test_data)
n = len(training_data)
for j in xrange(epochs):
random.shuffle(training_data)
mini_batches = [
training_data[k:k+mini_batch_size]
for k in xrange(0, n, mini_batch_size)]
temp_test_data = copy.deepcopy(test_data)
test_data_list = list(temp_test_data)
n_test= len(test_data_list)

temp_training_data = copy.deepcopy(training_data)
training_data_list = list(temp_training_data)
n_training = len(training_data_list)

for j in range(epochs):
random.shuffle(training_data_list)
mini_batches = [training_data_list[k:k+mini_batch_size] for k in range(0, n_training, mini_batch_size)]
for mini_batch in mini_batches:
self.update_mini_batch(mini_batch, eta)
if test_data:
print "Epoch {0}: {1} / {2}".format(
j, self.evaluate(test_data), n_test)
else:
print "Epoch {0} complete".format(j)
self.update_mini_batch(mini_batch, mini_batch_size,eta)
print ("Epoch {0}: {1} / {2}".format(j, self.evaluate(test_data_list), n_test))

def update_mini_batch(self, mini_batch, eta):
"""Update the network's weights and biases by applying
Expand Down