benchmark.py 603 B

12345678910111213141516171819202122232425262728293031
  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. return : ratio of good answers in [0.0 ; 1.0]
  8. """
  9. np_images, np_expected = io_mnist.load_testing_samples()
  10. nbSamples = np_images.shape[1]
  11. nbSuccess = 0
  12. for k in range(nbSamples):
  13. a0 = np_images[:, k]
  14. z1 = net.layer1 @ a0 + net.bias1
  15. a1 = net.activationFunction(z1)
  16. z2 = net.layer2 @ a1 + net.bias2
  17. a2 = net.activationFunction(z2)
  18. if (np.argmax(a2) == np.argmax(np_expected[:,k])):
  19. nbSuccess += 1
  20. return nbSuccess / nbSamples