Created
June 29, 2017 11:56
-
-
Save antonior92/914e3d3eb056fd5f3c640ab37ced04cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from numpy.linalg import norm | |
from ipsolver import equality_constrained_sqp | |
def fun(x): | |
return 2*(x[0]**2 + x[1]**2 - 1) - x[0] | |
def grad(x): | |
return np.array([4*x[0]-1, 4*x[1]]) | |
def hess(x, v): | |
hess_fun = 4*np.eye(2) | |
hess_constr = 2*np.eye(2) | |
return hess_fun + v*hess_constr | |
def constr(x): | |
return np.array([x[0]**2 + x[1]**2 - 1]) | |
def jac(x): | |
return np.array([[4*x[0]-1, 4*x[1]]]) | |
x0 = np.array([0.7, 0.7]) | |
x, info = equality_constrained_sqp(fun, grad, hess, | |
constr, jac, x0, | |
initial_trust_radius=1, | |
initial_penalty=10, | |
return_all=True) | |
print('f = '+ str(info["fun"])) | |
print('optimality = ' + str(info["opt"])) | |
print('c violation = ' + str(info["constr_violation"])) | |
print('niter = ' + str(info["niter"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment