Giter Club home page Giter Club logo

Comments (4)

michaelosthege avatar michaelosthege commented on June 19, 2024 1

Thanks for opening such a detailed issue!
I edited the formatting in your comment and added a link to that line.


I'm not familiar with the implementation, but is this a bug due to t_intervals and grads having different lengths and the for iterator never reaches the None element in the reversed(grads)?
Because inside that loop there's this if grad is not None: which appears to have been written for this t=0 element..

from sunode.

aarcher07 avatar aarcher07 commented on June 19, 2024

Great! Thank you for editing my post.

There is also another issue. At sufficiently small time evaluations, the gradient computations via the adjoint equations are inaccurate when compared to those of forward sensitivities.

Following the example above, if I evaluate the adjoint equation at time = 0, 5, 10 and grads = np.ones_like(yout) then I get that

  • grad_out_fwd = [29.633367875233063, -8.63361922455043, 10.2485995824757]
  • grad_out_adj = [ 8.08665182 -1.22041063 8.53419337].

However as in my original post, if I evaluate the adjoint equations at np.linspace(0, 10, 21), which includes time = 0, 5, 10, and zeros-pad grads at the time not equal to 0, 5, 10, then I get

  • grad_out_fwd = [29.633367875233063, -8.63361922455043, 10.2485995824757]
  • grad_out_adj = [27.71999675 -7.42137746 10.507334 ].

Thank you for looking to these issues!

from sunode.

aseyboldt avatar aseyboldt commented on June 19, 2024

@aarcher07 Thank you for reporting this, and sorry for the very late reply...

I think the problem you are seeing is due to a small mistake in the arguments to solve_backward. If I replace it by this, I get the same results as the forward solver:

# Instead of this
#solver.solve_backward(t0=tvals_expanded[-1], tend=tvals_expanded[0], tvals=tvals_expanded[1:-1],
#                      grads=grads, grad_out=grad_out, lamda_out=lambda_out)

# It should be this
solver.solve_backward(
    t0=tvals_expanded[-1],
    tend=tvals_expanded[0],
    tvals=tvals_expanded,
    grads=grads,
    grad_out=grad_out,
    lamda_out=lambda_out
)

grad_out_adj = -sens0 @ lambda_out + grad_out
print(grad_out_adj)

# Output

# from forward
# [29.633367875233063, -8.63361922455043, 10.2485995824757]

# from adjoint
# [29.63336772 -8.63361915 10.24859955]

The problem is that by passing in tvals=tvals_expanded[1:-1] we actually don't use the first two entries of grads, and the time points for those gradients don't match the correct tvals anymore.

from sunode.

aseyboldt avatar aseyboldt commented on June 19, 2024

I'm closing this because I think it was a problem in the example code, but feel free to reopen or comment if you don't agree or have questions.

from sunode.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.