benchmark.py 678 B

12345678910111213141516171819202122232425262728293031323334
  1. # Measure performance
  2. import numpy as np
  3. from lab import neural, io_mnist
  4. def computePrecision(net):
  5. """
  6. Test performance of provided network.
  7. net : the network to be assessed
  8. return : ratio of good answers in [0.0 ; 1.0]
  9. """
  10. np_images, np_expected = io_mnist.load_testing_samples()
  11. nbSamples = np_images.shape[1]
  12. nbSuccess = 0
  13. for k in range(nbSamples):
  14. a0 = np_images[:, k]
  15. z1 = net.layer1 @ a0 + net.bias1
  16. a1 = net.activationFunction(z1)
  17. z2 = net.layer2 @ a1 + net.bias2
  18. a2 = net.activationFunction(z2)
  19. # Verify index of highest probability
  20. if (np.argmax(a2) == np.argmax(np_expected[:,k])):
  21. nbSuccess += 1
  22. return nbSuccess / nbSamples