Exemplo n.º 1
0
Arquivo: demo.py Projeto: sdahdah/opt
 def test_aug_lag(self):
     x0 = np.array([[1], [1]])
     start = time.time()
     x_opt = opt.augmented_lagrange(self.p,
                                    x0,
                                    tol=1e-4,
                                    tol_const=1e-4,
                                    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(np.minimum(self.p.eq_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.xticks(np.arange(len(x_opt)))
     plt.xlabel('Iteration')
     plt.legend()
     fig.savefig('./fig/al-pEEq.eps', format='eps')
     print('\nProblem E-Eq, Augmented Lagrange')
     print('arg min v(x) =\n', x_opt[-1])
     print('time =\n', end - start, 's')
Exemplo n.º 2
0
 def test_eq_const_al(self):
     x0 = np.array([[1], [0]])
     x = opt.augmented_lagrange(self.p, x0, tol=1e-4, tol_const=1e-4)
     x_opt = np.array([[0.7071318], [0.7071093]])
     self.assertTrue(np.linalg.norm(x_opt - x) < 1e-4)
Exemplo n.º 3
0
Arquivo: demo.py Projeto: sdahdah/opt
 def test_aug_lag(self):
     x0 = np.array([[2.1], [0.1]])
     x = opt.augmented_lagrange(self.p, x0, tol=1e-4, tol_const=1e-4)
Exemplo n.º 4
0
 def test_aug_lag(self):
     x0 = np.array([[10], [1]])
     x = opt.augmented_lagrange(self.p, x0, tol=1e-4, tol_const=1e-4)
     print(x)