To implement the primal-dual interior-point method with Nesterov-Todd scaling, we first need to define a few functions that will be used throughout the algorithm. These functions include the barrier function, the Newton's method for solving KKT systems, and the line search. Here is the Python code for the primal-dual interior-point method:
import numpy as np
def barrier_function(G, x, t):
return -np.sum(np.log(-G @ x)) / t
def newton_step(G, A, x, t, solve_kkt):
m, n = G.shape
p, _ = A.shape
# Evaluate the gradient and Hessian of the barrier function
grad_barrier = G.T @ (1 / (G @ x))
hess_barrier = G.T @ np.diag(1 / (G @ x) ** 2) @ G
# Form the KKT matrix
KKT = np.vstack([
np.hstack([t * hess_barrier, A.T]),
np.hstack([A, np.zeros((p, p))])
])
# Form the KKT right-hand side
rhs = np.zeros(n + p)
rhs[:n] = -t * grad_barrier - A.T @ x
# Solve the KKT system
dy = solve_kkt(KKT, rhs)
dx = dy[:n]
dl = dy[n:]
return dx, dl
def line_search(G, A, x, dx, t, alpha=0.01, beta=0.5):
s = 1
while np.any(G @ (x + s * dx) >= 0) or np.any(A @ (x + s * dx) != 0):
s *= beta
while barrier_function(G, x + s * dx, t) > barrier_function(G, x, t) + alpha * s * (G @ dx).T @ (1 / (G @ x)):
s *= beta
return s
def primal_dual_interior_point(G, A, x0, solve_kkt, mu=10, tol=1e-6, max_iter=100):
m, n = G.shape
p, _ = A.shape
x = x0.copy()
# Ensure the initial point is feasible
assert np.all(G @ x < 0) and np.all(np.abs(A @ x) < tol