Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. from __future__ import division
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4.  
  5. strassen_leaf=2
  6.  
  7. def naive_algorithm_performance(n):
  8. multiplication=n**3
  9. return multiplication
  10.  
  11. def strassen_performance(n,strassen_leaf):
  12. multiplication=1
  13. check=n/2
  14. while (check >= strassen_leaf):
  15. multiplication=multiplication*7
  16. check=check/2
  17. if(n!=2):
  18. multiplication=multiplication*strassen_leaf**3
  19. return multiplication
  20.  
  21.  
  22. print "Scalar multiplication with Strassen: "+str(strassen_performance(16,strassen_leaf))
  23. print "Scalar multiplication with Naive: "+str(naive_algorithm_performance(13))
  24.  
  25.  
  26. x0 = np.linspace(2, 32, 31)
  27. x1 = [4,8,16,32]
  28. y0=[]
  29. y1=[]
  30. for el1 in x1:
  31. y1=y1 +[strassen_performance(el1,strassen_leaf)]
  32.  
  33. for el0 in x0:
  34. y0=y0 +[naive_algorithm_performance(el0)]
  35.  
  36.  
  37. plt.scatter(x0, y0,color='red', label='Naive Method')
  38. plt.scatter(x1, y1,color='blue', label='Strassen, Leaf=2')
  39. plt.yscale('log')
  40. plt.ylabel('Number of scalar multiplication')
  41. plt.xlabel('Dimension of Square Matrices')
  42. plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
  43. plt.grid()
  44. #plt.xticks(np.arange(2, 33, step=1))
  45. plt.savefig('samplefigure.pdf', bbox_inches='tight')
  46. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement