-
Notifications
You must be signed in to change notification settings - Fork 146
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
Nested derivate functions #31
Comments
This is a really good use case, thanks for sharing. |
Rereading your code, I realize that using ForwardDiff
f1(s) = (s/3)^2
f2(x) = x[1]^2 + exp(3*x[2]/sqrt(4))
function f(x)
g = forwarddiff_gradient(f2, Float64, fadtype=:typed, n=2)
return f1(x[1]) + g(x)
end
j = forwarddiff_jacobian(f, Float64, fadtype=:typed, n=2)
j([-1., 2.0]) I'm not sure whether that will actually work or not - it seems the old code uses the same implementation to take the gradient as it does the Jacobian. The #27 implementation, however, handles this fine: julia> using ForwardDiff
julia> f1(s) = (s/3)^2;
julia> f2(x) = x[1]^2 + exp(3*x[2]/sqrt(4));
julia> f(x) = f1(x[1]) + gradient(f2, x, Partials{2});
julia> j = jacobian_func(f, Partials{2}, mutates=false);
julia> j([-1, 2.0])
2x2 Array{Float64,2}:
1.77778 0.0
-0.222222 45.1925 |
Thanks for answering so soon! I couldn't the example code working but I'll get the idea you've implemented it in #27 and if it's coming within couple of weeks I can live with that. My model converges quite nicely with newton at least in 1D solution even if the jacobian might not be correctly evaluated. |
This now fixed on |
👍 |
Hi, I got my code working with the help of last issue: #30. Though I found a another example how I would like to make my code to work
Like last example:
ended up with error message:
I already found a workaround, but Im not sure should it work like this:
which gave me a hessia as expected:
note: I'm working with finite element material models, which happen to have this kind of functions
The text was updated successfully, but these errors were encountered: