Square Root (sqrt) in the Objective Function

2,007 views
Skip to first unread message

Nadja Herger

unread,
Apr 7, 2016, 7:37:26 PM4/7/16
to Pyomo Forum
Dear Community,

Is it possible to have a square root (sqrt() or math.sqrt() or ()**0.5 or ...) in the objective function of a Pyomo ConcreteModel? I assume that it depends on the solver and so far I have tried solver=glpk, cplex and gurobi. 

I obtain the following error message when using all three solvers: 
Cannot write legal LP file.  Objective 'OBJ' has nonlinear terms that are not quadratic.

Is there a Pyomo-compatible solver that can deal with nonlinear terms?

My goal is to minimize the root-mean-square error (RMSE). I formulate my Objective as follows:
model.OBJ = Objective(expr = sqrt( np.mean( [(error[i]**2)*model.x[i] for i in range(N_models)] ) ) )

I wonder if the sqrt() part is even necessary or if the optimization algorithm would end up with the same solution if I defined my Objective as the mean squared error (MSE) instead, as such:
model.OBJ = Objective(expr = np.mean( [(error[i]**2)*model.x[i] for i in range(N_models)] ))

Any ideas?

Thanks for your help!

Kind regards,
Nadja

Braulio Brunaud

unread,
Apr 7, 2016, 8:25:41 PM4/7/16
to Pyomo Forum

Hello

All the solvers you tried are linear. If you have a square root in the objective function the model is nonlinear and you would need to use a nonlinear solver such as ipopt. Also, when solving an NLP you  need to provide a starting point.

You can download the binaries from:
http://ampl.com/products/solvers/open-source/

regards

Braulio

Gabe Hackebeil

unread,
Apr 7, 2016, 9:17:52 PM4/7/16
to pyomo...@googlegroups.com
Also, your intuition is correct in that you do not need to take the square root.

Gabe
--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nadja Herger

unread,
Apr 7, 2016, 10:22:56 PM4/7/16
to Pyomo Forum
Hi Braulio and Gabe,

Thanks for your help!
Good to know that there are also solvers around which can deal with nonlinear objective functions. I'll stick to the linear solvers for now, as my problem becomes linear if I forget about the square root. 

Regards,
Nadja

William Hart

unread,
Apr 7, 2016, 10:36:12 PM4/7/16
to pyomo...@googlegroups.com
The derivative is linear, but the objective is quadratic...

--Bill

--
Reply all
Reply to author
Forward
0 new messages