def test_inv_barrier_function(self, tol=1e-3, tol_const=1e-3): x0 = np.array([[0.1], [0.1]]) start = time.time() x_opt = opt.barrier_function(self.p, x0, mode='inv', hist=True) end = time.time() g = np.array( [np.linalg.norm(self.p.grad(x_opt[i])) for i in range(len(x_opt))]) c_e = np.array([ np.linalg.norm(self.p.eq_const(x_opt[i])) for i in range(len(x_opt)) ]) c_i = np.array([ np.linalg.norm(np.minimum(self.p.ineq_const(x_opt[i]), 0)) for i in range(len(x_opt)) ]) fig = plt.figure() plt.plot(np.arange(len(x_opt)), g, label='Gradient Norm') plt.plot(np.arange(len(x_opt)), c_e, label='Equality Constraint Norm') plt.plot(np.arange(len(x_opt)), c_i, label='Inequality Constraint Norm') plt.xticks(np.arange(len(x_opt))) plt.xlabel('Iteration') plt.legend() fig.savefig('./fig/ba-pD.eps', format='eps') print('\nProblem D, Barrier Function') print('arg min v(x) =\n', x_opt[-1]) print('time =\n', end - start, 's')
def test_log_barrier_function(self, tol=1e-4, tol_const=1e-4): x0 = np.array([[1], [1]]) x = opt.barrier_function(self.p, x0, mode='log')
def test_inv_barrier_function(self, tol=1e-4, tol_const=1e-4): x0 = np.array([[1], [1]]) x = opt.barrier_function(self.p, x0, mode='inv') print(x) print()
def test_log_barrier_function(self, tol=1e-3, tol_const=1e-3): x0 = np.array([[0.1], [0.1]]) x = opt.barrier_function(self.p, x0, mode='log') self.assertTrue(np.linalg.norm(x - self.x_opt) < 1e-3)