Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import ipdb;
- import numpy as np
- from my_optimization import *
- # ROSENBROCK TESTBENCH
- def tb_rosenbrock(x):
- #traditional bounds on x_i values are between
- #-5.12 and +5.12 inclusive
- temp = 0
- n = len(x)
- f = 0
- find = []
- for i in range(0,n-1):
- find.append(abs((1-x[i])**2 + 100*(x[i+1]-x[i]**2)**2))
- f = f + find[i]
- f = abs(f)
- find = np.abs(find)
- return f
- def tb_simple(x):
- f = np.sum(np.abs(x[1:]))+x[0]
- return f
- # OPTIMIZATION
- size_x = 3
- bound_i = (-5.12,5.12)
- bounds = []
- for i in range (0, size_x):
- bounds.append(bound_i)
- x0 = 5*np.ones(size_x)
- maxiter = 2000
- step = 0.1
- args = []
- res = my_hillclimbing(tb_rosenbrock, x0, bounds, maxiter, step, args)
- print("Final x: [",)
- print("%f" % res.x[0],)
- for i in range(1,len(res.x)):
- print(", %f" % res.x[i],)
- print("]\n",)
- print("Final cost: %f \n" % res.cost)
Advertisement
Add Comment
Please, Sign In to add comment