12345678910111213141516171819202122232425262728293031323334 |
- # Measure performance
- import numpy as np
- from lab import neural, io_mnist
- def computePrecision(net):
- """
- Test performance of provided network.
- net : the network to be assessed
- return : ratio of good answers in [0.0 ; 1.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)
- # Verify index of highest probability
- if (np.argmax(a2) == np.argmax(np_expected[:,k])):
- nbSuccess += 1
- return nbSuccess / nbSamples
|