solver
def fun(x):
return x**2 - 16
def double_fun(x):
return 3*np.exp(x[0]) + x[1]**2 - 16
sample_point = rotated_point[sorted(np.random.choice(rotated_point.shape[0], 20, replace=False)), :]
def icp_fun(x):
R = icp(originate_point, sample_point, x, 2)
rotated_fit_point = cv2.transform(originate_point[None, :], R)[0]
return cost(rotated_fit_point, rotated_point)
def derivative(f, x):
delta = 1E-6 * np.eye(len(x))
de = []
for i in range(len(x)):
de.append((f(x + delta[i]) - f(x - delta[i])) / (2 * 1E-6))
return np.array(de)
def solve(f, param_size):
history = []
cost = 1E6
param = np.ones(param_size)
print(cost)
bar = tqdm(range(1000))
postfix = {"cost": cost}
for i in bar:
cost = f(param)
postfix = {"cost": cost}
bar.set_postfix(postfix)
f_p = derivative(f, param)
param = param - 0.005 * cost / f_p
history.append([*param, cost])
if np.abs(cost) < 1E-6:
break
return history
Code
jupyter
Traning
Animation