[ADOL-C] sparse hessian & parameters & operator +=

João Leal joaoruileal at gmail.com
Thu Jun 23 13:22:45 EDT 2016


Hello,

I have a small program using Adol-c (adapted from the examples) to
determine a sparse Hessian of a linear function using parameters with the
new mkparam function.

I have notice that if I use the operator += in my model then my program
will produce an incorrect sparsity pattern for the hessian.
If that operation is replaced with "x = x + ..." then it produces the
correct result.
I've checked my program with valgrind and nothing came up.

I'm using adolc 2.6.0 in ubuntu 15.10.

Here is the example program:
//*************************************************************************************************

#include <adolc/adolc.h>
#include <adolc/sparse/sparsedrivers.h>

using namespace std;

#define tag 1

adouble feval_ad(adouble *x) {
    adouble res;

    res = 0;
    res += x[2] * x[0];
    res += x[3] * x[1];

    return res;
}

int main(int argc, char **argv) {
    int n = 2;
    std::vector<double> pars(2);
    int nx = n + pars.size();

    double f, x[nx];
    adouble fad, xad[nx];
    //double f, x[n];
    //adouble fad, xad[n];

    int i;

/****************************************************************************/
/*******                function evaluation
***************/
/****************************************************************************/

    for(i=0;i<n;i++)
        x[i] = log(1.0+i);

    /* Tracing of function f(x) */

    trace_on(tag);
    for(i=0;i<n;i++)
        xad[i] <<= x[i];

    for (i = n; i < nx; ++i) {
       xad[i] = ::mkparam(pars[i - n]);
    }

    fad = feval_ad(xad);

    fad >>= f;
    trace_off();

    printf("\n f = %e\n\n\n",f);


/****************************************************************************/
/*******       sparse Hessians, complete driver
***************/
/****************************************************************************/

    /* coordinate format for Hessian */
    unsigned int    *rind  = NULL;
    unsigned int    *cind  = NULL;
    double *values = NULL;
    int nnz;
    int options[2];

    options[0] = 0;          /*                               safe mode
(default) */
    options[1] = 0;          /*                       indirect recovery
(default) */

    ::set_param_vec(tag, pars.size(), pars.data());

    sparse_hess(tag, n, 0, x, &nnz, &rind, &cind, &values, options);

    printf("In sparse format:\n");
    for (i=0;i<nnz;i++)
        printf("%2d %2d %10.6f\n\n",rind[i],cind[i],values[i]);

    free(rind); rind = NULL;
    free(cind); cind = NULL;
    free(values); values = NULL;
}
//*************************************************************************************************

It prints out:


 f = 0.000000e+00


In sparse format:
 0  0   0.000000

 1  1   0.000000


But the hessian shouldn't have any elements.
Could anyone help me figure out the problem with my code?

Thanks for your help!

João Leal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/adol-c/attachments/20160623/9ca5609e/attachment.html>


More information about the ADOL-C mailing list