|
@@ -42,16 +42,20 @@ def train(inputNetwork, learnRate, epochs, batchSize = 10):
|
|
|
d2 = np.empty(a2.shape)
|
|
|
d1 = np.empty(a1.shape)
|
|
|
|
|
|
+ permut = np.arange(nbSamples)
|
|
|
+
|
|
|
for epoch in range(epochs):
|
|
|
# Create mini batches
|
|
|
- # TODO Shuffle samples
|
|
|
+ np.random.shuffle(permut)
|
|
|
|
|
|
# Iterate over batches
|
|
|
for batchIndex in range(0, nbSamples, batchSize):
|
|
|
# Capture batch
|
|
|
batchEndIndex = batchIndex + batchSize
|
|
|
- a0 = np_images[:, batchIndex:batchEndIndex]
|
|
|
- y = np_expected[:, batchIndex:batchEndIndex]
|
|
|
+ batchSelection = permut[batchIndex : batchEndIndex]
|
|
|
+
|
|
|
+ a0 = np_images[:, batchSelection]
|
|
|
+ y = np_expected[:, batchSelection]
|
|
|
|
|
|
# Forward computation
|
|
|
z1 = w1 @ a0 + b1
|