# [Ipopt] Gradient estimation in IPOPT

Stefan Vigerske stefan at math.hu-berlin.de
Sat Aug 25 14:02:53 EDT 2012

Hi,

I don't know why you want to implement an own approximation for the
jacobian if the one in Ipopt is working for you.
If you implement own approximations, you could enable the derivative
checker in Ipopt to check that the errors you get are sufficiently small.

Stefan

On 08/24/2012 11:06 AM, Martijn Disse wrote:
> Dear all,
>
> I am working on the HS071 optimization problem. I want to replace the explicit expressions for the Gradient, Hessian and Jocabian with a finite-difference approxiamation. Once I know how to do this, I will implement this on a more complex problem.
>
> I am running Ipopt 3.9stable with the default ma27 solver and the C interface IpStdCInterface.h. I have no problems with setting the Hessian and the Jacobian approximation (see below). Allthough I was not expecting I could use the Jacobian approximation with the ma27 solver, especially since it is not mentioned as an IPOPT option in the online documentation. (Documentation online is not clear and I can only find info on jacobian approximation at http://www.coin-or.org/Bonmin/option_pages/options_list_ipopt.html)
>
> Hence 2 questions remain:
>
>    1.  How can I implement a gradient estimation using finite-differences?
>    2.  How can I be sure that my jacobian estimation actually is correct? I can solve the HS071 problem with finite-differences jacobian, and get good results. Is this enough proof?
>
> Your help will be greatly appreciated!
>
> Best regards,
>
> -Martijn Disse
>
> ======================================================
> Jacobian approximation (WORKS!)
>
> Bool eval_jac_g(Index n, Number *x, Bool new_x,
>                  Index m, Index nele_jac,
>                  Index *iRow, Index *jCol, Number *values,
>                  UserDataPtr user_data)
> {
>    if (values == NULL) {
>      // return the structure of the Jacobian
>      // this particular Jacobian is dense
>      iRow[0] = 0; jCol[0] = 0;
>      iRow[1] = 0; jCol[1] = 1;
>      iRow[2] = 0; jCol[2] = 2;
>      iRow[3] = 0; jCol[3] = 3;
>      iRow[4] = 1; jCol[4] = 0;
>      iRow[5] = 1; jCol[5] = 1;
>      iRow[6] = 1; jCol[6] = 2;
>      iRow[7] = 1; jCol[7] = 3;
>    }
>    return FALSE;
> }
>
>
>
> Hessian approximation (WORKS!)
>
> I define the function as:
> Bool eval_h(Index n, Number *x, Bool new_x, Number obj_factor,
>              Index m, Number *lambda, Bool new_lambda,
>              Index nele_hess, Index *iRow, Index *jCol,
>              Number *values, UserDataPtr user_data)
> {
>    return FALSE;
> }
>
> ======================================================
>
>
>
>
>
>
> _______________________________________________
> Ipopt mailing list
> Ipopt at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/ipopt
>