|
@@ -1,12 +1,31 @@
|
|
|
# Measure performance
|
|
|
|
|
|
-from lab import neural
|
|
|
+import numpy as np
|
|
|
+from lab import neural, io_mnist
|
|
|
|
|
|
-def computePrecision(network):
|
|
|
+def computePrecision(net):
|
|
|
"""
|
|
|
Test performance of provided network.
|
|
|
|
|
|
return : ratio of good answers in [0.0 ; 1.0]
|
|
|
"""
|
|
|
- # TODO
|
|
|
- return 0.0
|
|
|
+
|
|
|
+ np_images, np_expected = io_mnist.load_testing_samples()
|
|
|
+
|
|
|
+ nbSamples = np_images.shape[1]
|
|
|
+
|
|
|
+ nbSuccess = 0
|
|
|
+
|
|
|
+ for k in range(nbSamples):
|
|
|
+ a0 = np_images[:, k]
|
|
|
+
|
|
|
+ z1 = net.layer1 @ a0 + net.bias1
|
|
|
+ a1 = net.activationFunction(z1)
|
|
|
+
|
|
|
+ z2 = net.layer2 @ a1 + net.bias2
|
|
|
+ a2 = net.activationFunction(z2)
|
|
|
+
|
|
|
+ if (np.argmax(a2) == np.argmax(np_expected[:,k])):
|
|
|
+ nbSuccess += 1
|
|
|
+
|
|
|
+ return nbSuccess / nmSamples
|