Advertisement
toweber

optimization test

Sep 12th, 2022
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. import os
  2. import ipdb;
  3. import numpy as np
  4. from my_optimization import *
  5.  
  6. def tb_simple(x):
  7.     f = np.sum(np.abs(x[1:]))+x[0]
  8.     return f
  9.  
  10.  
  11.  
  12. # OPTIMIZATION
  13.  
  14. size_x = 3
  15. bound_i = (-5.12,5.12)
  16. bounds = []
  17. for i in range (0, size_x):
  18.       bounds.append(bound_i)
  19.  
  20. x0 = 5*np.ones(size_x)
  21.  
  22. maxiter = 2000
  23. step = 0.1
  24. args = []
  25.  
  26.  
  27. res = my_hillclimbing(tb_simple, x0, bounds, maxiter, step, args)
  28. print("Final x: [",)
  29. print("%f" % res.x[0],)
  30. for i in range(1,len(res.x)):
  31.     print(", %f" % res.x[i],)
  32.  
  33. print("]\n",)
  34. #print res.x
  35. print("Final cost: %f \n" % res.cost)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement