3

I want to solve a nonlinear programming problem. The objective function is nonlinear and the constraints are linear. Given a vector α(dim is n*1), I want to find another vector θ( dim also is n*1) make cos(α, θ) minimize. Meanwhile the θ has some constraints. the constraint is A.dot(θ) < 0(zero is a column vector),A dim is m*nm < n.

The problem is, Given α(dim is n*1),A dim is m*nm < n

minimize   cos(α, θ) = α^T.dot(θ) /(|α||θ|)
subject to 
           A.dot(θ) < 0  (zero dim m*1)

I have tried to use scipy.optimize.minimize to solve the problem and input the constraints. like

scipy.optimize.minimize(method='SLSQP', constraints=cons)
scipy.optimize.minimize(method='COBYLA', constraints=cons)

The result of the methods are depending on the initial value. I don't know how to get a reasonable initial value so I set initial value is random. As expected, the method gives a wrong result, the results don't meet the constraints.

hinanmu
  • 151
  • 8
  • 2
    this isn't really a Python programming problem at the moment, could you modify the question to include your code that gives the wrong answer? the closer this is to a [MCVE](https://stackoverflow.com/help/mcve) the more help you're likely to get! – Sam Mason Nov 01 '19 at 12:28

2 Answers2

0

You need to define your inequality constraint

def constraint1(A,θ):
    return np.dot(A,θ)

The steps are described optimization with scipy

Then you go for sequential least-square quadratic programming. You will see that a non-convex optimization problem has no mathematical guarantee to be solved.

alec_djinn
  • 10,104
  • 8
  • 46
  • 71
Richard Rublev
  • 7,718
  • 16
  • 77
  • 121
  • I had added the contraints to the algorithm. but it is no use. I konw it can't find global optimum solution. but I only want to get a local optimum solution meet the constraints. – hinanmu Nov 01 '19 at 12:46
0

Here is a minimal code solved with a nonlinear programming solver in gekko:

import numpy as np
from gekko import GEKKO
g = GEKKO()

# dimensions
m=3; n=4

# constants
A = np.ones((m,n))

# variables
θ = g.Array(g.Var,n,lb=-10,ub=-1e-3)
α = g.Array(g.Var,n,lb=1e-3,ub=10)

# objective
g.Minimize(α.dot(θ))

# constraint
Aθ = A.dot(θ)
g.Equations([x<0 for x in Aθ])

# solve and print solution
g.solve(disp=True)
print(α); print(θ)

There are many good nonlinear programming options as discussed in High Quality Nonlinear Programming Solvers for Python

John Hedengren
  • 12,068
  • 1
  • 21
  • 25