Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous Hessian on second evaluation #24

Open
dpo opened this issue Jul 10, 2016 · 3 comments
Open

Erroneous Hessian on second evaluation #24

dpo opened this issue Jul 10, 2016 · 3 comments

Comments

@dpo
Copy link

dpo commented Jul 10, 2016

I'm having an issue where the first (sparse) Hessian evaluation is correct, but the second is not. I'm not sure if it's an Adol-C issue or a pyadolc issue. I'm using ColPack 1.0.9 and Adol-C 2.6.0 on OSX. Here's a minimum working example:

import adolc
import numpy as np

def rosenbrock(x):
    return np.sum(100 * (x[1:] - x[:-1]**2)**2 + (1 - x[:-1])**2)

nvar = 5
x = -np.ones(nvar)

# trace function value
obj_trace_id = 1
adolc.trace_on(obj_trace_id)
ax = adolc.adouble(x)
adolc.independent(ax)
y = rosenbrock(ax)
adolc.dependent(y)
adolc.trace_off()

# evaluate gradient
g = adolc.gradient(obj_trace_id, x)

# evaluate sparse hessian
options = np.zeros(2, dtype=int)
nnz, rind0, cind0, values0 =  \
    adolc.colpack.sparse_hess_no_repeat(obj_trace_id,
                                        x, options=options)
print "rind: ", rind0
print "cind: ", cind0
print "vals: ", values0

# evaluate sparse hessian again
nnz, rind, cind, values =  \
    adolc.colpack.sparse_hess_repeat(obj_trace_id,
                                     x,
                                     rind0,
                                     cind0,
                                     values0)

print "rind: ", rind
print "cind: ", cind
print "vals: ", values

Here is the output I receive:

rind:  [0 0 1 1 2 2 3 3 4]
cind:  [0 1 1 2 2 3 3 4 4]
vals:  [ 1602.   400.  1802.   400.  1802.   400.  1802.   400.   200.]
rind:  [0 0 1 1 2 2 3 3 4]
cind:  [0 1 1 2 2 3 3 4 4]
vals:  [ 1602.   400.  1802.   800.  1802.   800.  1802.   400.   200.]

On the second sparse Hessian evaluation, certain off-diagonals changed. Can you reproduce this issue?

@dpo
Copy link
Author

dpo commented Jul 10, 2016

I get the same results with ColPack 1.0.10 and Adol-C 2.6.1. I noticed that some pyadolc tests are failing; not sure if it's related: https://gist.github.com/e01e5d6348c84f816b71fdea7161153f

@b45ch1
Copy link
Owner

b45ch1 commented Jul 13, 2016

Hi Dominique,

I can reproduce the error with ADOL-C-2.6.0 and ColPack-1.0.9.

adolc/colpack/wrapped_functions.py:119: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if options == None:
rind:  [0 0 1 1 2 2 3 3 4]
cind:  [0 1 1 2 2 3 3 4 4]
vals:  [ 1602.   400.  1802.   400.  1802.   400.  1802.   400.   200.]
rind:  [0 0 1 1 2 2 3 3 4]
cind:  [0 1 1 2 2 3 3 4 4]
vals:  [ 1602.   400.  1802.   800.  1802.   800.  1802.   400.   200.]

The error does not appear if you use options[:] = 0,1.

/home/swalter/projects/pyadolc/build/lib.linux-x86_64-2.7/adolc/colpack/wrapped_functions.py:119: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if options == None:
rind:  [0 0 1 1 2 2 3 3 4]
cind:  [0 1 1 2 2 3 3 4 4]
vals:  [ 1602.   400.  1802.   400.  1802.   400.  1802.   400.   200.]
rind:  [0 0 1 1 2 2 3 3 4]
cind:  [0 1 1 2 2 3 3 4 4]
vals:  [ 1602.   400.  1802.   400.  1802.   400.  1802.   400.   200.]

#15 seems to be related. Back then, the error resided in ADOL-C/Colpack, not in pyadolc. Unfortunately, I don't have time to look into it right now. You may want to involve the ADOL-C maintainers.

Regarding the errors in the tests:
I cannot reproduce the errors in the tests. Are the errors in adolc.test() reproducible on your machine?

@dpo
Copy link
Author

dpo commented Jul 14, 2016

Many thanks Sebastian! The options you give work for me. I'll be in touch with the Adol-C folks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants