# [ADOL-C] Evaluating Hessian of Lagrangian

Ingrid Hallen ingridhallen at hotmail.com
Fri May 3 01:43:09 EDT 2013

```Hi,

Thanks for the quick reply! The problem turned out to be my function for evaluating
the Lagrangian. A bit simplified, the following is the original code:

for (unsigned int i=0; i<nconstr; i++)
L += lambda[i]*constr[i];

This code worked fine with lambda as doubles, but when using lambda as adoubles,
i.e. as variables, additional non-zeros appeared in H_{xx}. However, when changing
the code to

for (unsigned int i=0; i<nconstr; i++)
L = L + lambda[i]*constr[i];

everything worked fine, with all additional non-zeros ending up in columns>dim(x).
Not sure why though, perhaps someone could explain?

Kind regards

Ingrid

> Date: Thu, 2 May 2013 15:54:28 +0200
> From: kshitij at math.upb.de
> To: ingridhallen at hotmail.com
> Subject: Re: [ADOL-C] Evaluating Hessian of Lagrangian
>
> Hello,
>
> the sequence of rows or columns in the hessian is exactly the same as of
> the execution of the <<= operators that define independents between
> trace_on() and trace_off(). So as long as the <<= operator was executed
> for all x variables before all lagrange multipliers, the H_{xl}
> components should have column indices larger than dim(x).
>
> Sincerely
> Kshitij Kulshrestha.
>
> As on 2013-05-02 15:28h, Ingrid Hallen did write:
> > Hi,
> >
> > I finally got time to start implementing the alternative method for
> > computing the Hessian of
> > the Lagrangian to do some benchmarking. However, I have come across the
> > following difficulty:
> >
> > Using also the Lagrange multipliers as variables yields an Hessian of
> > the Lagrangian in the
> > form of a block matrix:
> >
> > H = / H_{xx}         H_{xl} \
> >        \ H_{xl}                0    /
> >
> > Here H_{xx} is the Hessian wrt to the original variables x\inR^n that we
> > are interested in. After calling
> > sparse_hess(tag,n,repeat,x,&nnz,&rind,&cind,&values,&options) I thought
> > that it should be
> > straightforward to identify the parts of rind, cind and values
> > pertaining to H_{xx}. For instance,
> > say we want to count the non-zeros in the first row of H_{xx}, nnz_xx,
> > using the following code:
> >
> > int k = 0
> > int nnz_xx = 0
> > while rind[k]==0
> >     if cind[k]<n
> >           nnz_xx++;
> >     end
> >     k++;
> > end
> >
> > This of course only works provided the non-zeros of H_{xl} are found in
> > the columns>n, but that
> > appears not to be the case.
> >
> > Am I missing something really simple here, or how can I extract H_{xx}?.
> >
> > Kind regards
> > Ingrid
> >
> >
> >
> >
> > ------------------------------------------------------------------------
> > From: ingridhallen at hotmail.com
> > To: awalther at math.uni-paderborn.de
> > Date: Thu, 11 Apr 2013 09:26:23 +0200
> > CC: adol-c at list.coin-or.org
> > Subject: Re: [ADOL-C] Evaluating Hessian of Lagrangian
> >
> >
> > I think I will do some benchmarking then, to see which
> > of the two approaches works best for my problem.
> >
> > The approach suggested by Norm is certainly interesting,
> > but I think I have to little experience with optimization
> > to implement it successfully. At least for the moment.
> >
> > Sincerely,
> >
> > Ingrid
> >
> >
> >> Date: Wed, 10 Apr 2013 22:51:22 +0200
> >> From: awalther at math.uni-paderborn.de
> >> To: ingridhallen at hotmail.com
> >> CC: normvcr at telus.net; adol-c at list.coin-or.org
> >> Subject: Re: [ADOL-C] Evaluating Hessian of Lagrangian
> >>
> >> Hi
> >>
> >> sorry for entering the discussion so late but I was on travel
> >> the last days and most of the time offline.
> >>
> >> If you can exploit the minor size of the reduced Hessian
> >> the approach proposed by Norm is certainly the best way to go
> >> since it requires the least number of Hessian vector product
> >> which determines the cost of the derivative calculation.
> >>
> >> However, I am not sure whether Ipopt can really exploit this.
> >> Regarding the other approaches discussed so far:
> >>
> >> We made the experience that it really depends on the application
> >> whether
> >>
> >> * tracing the Lagrangian once with x and lambda as inputs
> >> and evaluating only a part of the Hessian reusing the trace
> >> in all iterations
> >>
> >> or
> >>
> >> * retracing the Lagrangian with x as adoubles and lambda as doubles
> >> in each iteration and computing then the whole Hessian
> >>
> >> performs better in terms of runtime. You could give both approaches
> >> a try and see what works better for you. Both approaches have their
> >> pros and cons with respect to efficiency.
> >>
> >> Best regards
> >>
> >> Andrea
> >>
> >> --
> >> Prof. Dr. Andrea Walther
> >> Lehrstuhl fuer Mathematik und ihre Anwendungen
> >> Institut fuer Mathematik
> >> Warburger Str. 100
> >>
> >> Email: andrea.walther at uni-paderborn.de
> >> Phone: ++49 5251 602721
> >> ++49 5251 602724 (sekr.)
> >> Fax: ++49 5251 603728
> >>
> >> **********
> >>
> >>
> >>
> >
> > _______________________________________________ ADOL-C mailing list
> >
> >
> > _______________________________________________
> >
>
> --
> Dr. Kshitij Kulshreshtha
>
> Institut für Mathematik,
> Warburger Straße 100,
>
> Büro: A3.235
>
> Privatanschrift:
> Arnikaweg 62