Skip to main content

Piecewise linear approximation to sigmoid function

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    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?.
  • Richard Oberdieck
    Gurobi Staff Gurobi Staff

    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 exact

    This functionality is also available in the MATLAB API.

    0

Post is closed for comments.