Prechádzať zdrojové kódy

Implement minibatch shuffle

DricomDragon 5 rokov pred
rodič
commit
b5ac958003
2 zmenil súbory, kde vykonal 8 pridanie a 4 odobranie
  1. 7 3
      python/lab/trainer.py
  2. 1 1
      python/start_session.py

+ 7 - 3
python/lab/trainer.py

@@ -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

+ 1 - 1
python/start_session.py

@@ -13,7 +13,7 @@ from lab import generator, trainer, benchmark
 learnRate = 0.05
 activation = expit
 activationDerivative = lambda x : expit(x) * (1 - expit(x))
-epochs = 1
+epochs = 10
 
 # Session
 network = generator.generate(activation, activationDerivative, generator.gaussAdaptedDev)