예제 #1
0
파일: demo.py 프로젝트: sdahdah/opt
 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')
예제 #2
0
파일: demo.py 프로젝트: sdahdah/opt
 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')
예제 #3
0
 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()
예제 #4
0
 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)