Exemplo n.º 1
0
    def test_lag_new(self):

        P = np.array([[1, 0], [0, 2]])
        v = lambda x: 0.5 * x.T @ P @ x
        c = [lambda x: x[0, 0]**2 + x[1, 0]**2 - 25]
        p = opt.Problem(v, eq_const=c)

        x0 = np.array([[1], [1]])
        x = opt.lagrange_newton(p, x0, tol=1e-2)
        print(x)
Exemplo n.º 2
0
Arquivo: demo.py Projeto: sdahdah/opt
 def test_lag_new(self):
     x0 = np.array([[0.7], [0.7]])
     start = time.time()
     x_opt = opt.lagrange_newton(self.p, x0, tol=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/ln-pEEq.eps', format='eps')
     print('\nProblem E-Eq, Lagrange-Newton')
     print('arg min v(x) =\n', x_opt[-1])
     print('time =\n', end - start, 's')
Exemplo n.º 3
0
Arquivo: demo.py Projeto: sdahdah/opt
 def test_lag_new(self):
     x0 = np.array([[0.7], [0.7]])
     x_opt = opt.lagrange_newton(self.p, x0, tol=1e-4)
     print(x_opt)
Exemplo n.º 4
0
Arquivo: demo.py Projeto: sdahdah/opt
 def test_lag_new(self):
     x0 = np.array([[0.7], [0.7]])
     start = time.time()
     x_opt = opt.lagrange_newton(self.p, x0, tol=1e-4)
     end = time.time()
     print(x_opt)