Advertisement
Dmitrey15

PyPy - FD - nsp - 150

May 25th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. from numpy import arange
  2. from FuncDesigner import *
  3. from openopt import NSP
  4.  
  5. y = oovar('y')
  6.  
  7. N = 150
  8. x = [oovar() for i in range(N)]
  9. koeffs = 1.07 ** arange(1, N+1) #
  10.  
  11. objective = sum([abs(x[i]) * koeffs[i] for i in range(N)]) + abs(y-15) + abs(y+15) + y**2
  12.  
  13. startPoint = {y:80}
  14. for i in range(N):
  15.     startPoint[x[i]] = cos(1+i)
  16.  
  17. p = NSP(objective, startPoint, maxIter = 1e5)
  18.  
  19. r = p.solve('ralg')
  20.  
  21. '''
  22. PyPy 1.8 time: 118 sec
  23. CPython 2.7 time: 267 sec
  24. for nVars ~1-40 performance is almost same,
  25. for nVars 50-150 PyPy performance is 1.5-2 times better
  26. for vectorized problems
  27. x = oovar()
  28. objective = sum(abs(x) * koeffs) + abs(y-15) + abs(y+15) + y**2
  29. startPoint = {x: cos(1+arange(N)), y:80}
  30. PyPy performance is some percents slower than CPython
  31. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement