"Jacobian of gradient" question

25 views
Skip to first unread message

Evgeny Savenkov

unread,
Feb 10, 2018, 7:32:42 PM2/10/18
to algopy
Dear Sebastian!

Thank you for the greate tool! I am new to it and have a question. Is it possible to compute (algopy) Jacobian of (algopy) gradient? I mean I have to compute something like:

def pot(u):
    """
    pot is scalar
    """
    return u[0]**2 + u[1]**2 + u[2]**2

# Works fine, computes gradient of pot
def stress(u):
    """
    Returns vector with 3 components
    """
    u = algopy.UTPM.init_jacobian(u)
    stress = algopy.UTPM.extract_jacobian(pot(u))
    return stress

# Works fine, returns vector with, e.g., 5 components
def flux(u):
    """ """
    f = algopy.zeros((5,), dtype=u)
    s = stress(u)

    # Some non-trivial dependence of f on u
    f[0] = s[0]*s[0]
    f[1] = s[1]*s[1]
    f[2] = s[2]*s[2]
    f[3] = s[0]*s[1]
    f[4] = s[1]*s[2]
   
    return f

# Need to compute jacobian of flux w.r.t. u, which is 5 by 3 matrix
# ???


I went through documentation and examples but have not managed to find solution (although I think https://pythonhosted.org/algopy/examples/comparison_forward_reverse_mode.html is the most closed example for the problem)

Many thanks in advance!


Evgeny

Sebastian Walter

unread,
Feb 12, 2018, 2:55:58 AM2/12/18
to alg...@googlegroups.com
Hello Evgeny,

you are trying to compute nested derivatives.
This functionality exists in AlgoPy, but it is an experimental and largely untested feature.

Have you tried to run algopy.UTPM.extract_jacobian(flux(algopy.UTPM.init_jacobian(u)))?

Since this is an experimental feature, you should verify the correctness of the result, e.g., by using finite differences.

Best
Sebastian




--
You received this message because you are subscribed to the Google Groups "algopy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to algopy+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Evgeny Savenkov

unread,
Feb 12, 2018, 7:07:23 AM2/12/18
to algopy
Hellow, Sebastian,

Thank you! I have not tried yet. Somehow (without a try) I supposed it will fail and decided to ask in advance.

I will try and comment results here.

E.

понедельник, 12 февраля 2018 г., 10:55:58 UTC+3 пользователь Sebastian Walter написал:
To unsubscribe from this group and stop receiving emails from it, send an email to algopy+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages