Piecewise linear approximation to sigmoid function
AnsweredI am new to Gurobi, I'm trying to solve a problem with the following function as objective function: log(1+exp(-x)). I know that I should use piecewise linear approximation to solve the problem.
How can I do it using matlab?
Regards
0
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Jammal,
you can solve your problem by using functional constraints that were introduced in v9 of Gurobi. In Python, this can look as follows:
m = gp.Model()
# Add the first part
x = m.addVar(lb=-np.inf)
xNegative = m.addVar(lb=-np.inf)
m.addConstr(xNegative == -x)
# Now add the exponential
y = m.addVar(lb=-np.inf)
m.addGenConstrExp(xNegative, y)
# Now the expression
z = m.addVar()
m.addConstr(z == 1+y)
# The logarithm general constraint
q = m.addVar(lb=-np.inf)
m.addGenConstrLog(z, q, options="FuncPieces=-1 FuncPieceError=0.001") # This setting will make the approximation more exactThis functionality is also available in the MATLAB API.
0
Post is closed for comments.
Comments
2 comments