-
Notifications
You must be signed in to change notification settings - Fork 53
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
Explicit tensor expression #163
Comments
Hi! Thanks for the interest in the package and the questions. Regarding how it works, take a look in the documentation, specifically in the background. Though not all details are given, the essence of the philosophy is outlined. If that is not clear enough, please open issues for that. About the hessian, yes, there is a function that does that, julia> using TaylorSeries
julia> rosenbrock(x) = (1 - x[1])^2 + 100(x[2] - x[1]^2)^2
rosenbrock (generic function with 1 method)
julia> x, y = set_variables("x y") # define the independent variables
2-element Array{TaylorSeries.TaylorN{Float64},1}:
1.0 x + 𝒪(‖x‖⁷)
1.0 y + 𝒪(‖x‖⁷)
julia> rr = rosenbrock([x, y]) # expansion of the Rosenbrock function around [0,0]
1.0 - 2.0 x + 1.0 x² + 100.0 y² - 200.0 x² y + 100.0 x⁴ + 𝒪(‖x‖⁷)
julia> hessian(rr) # evaluate the Hessian at [0,0]
2×2 Array{Float64,2}:
2.0 0.0
0.0 200.0
julia> hessian(rr, [1.0,1.0]) # evaluate the Hessian at [1.0,1.0]
2×2 Array{Float64,2}:
802.0 -400.0
-400.0 200.0 Be aware that Let me know if this helps... EDIT: Forgot to include the line defining the independent variables |
Thanks for your answer! Thanks a lot for the example it helped put a lot of the documentation in context for me! (I am not a very good programmer, so I can get lost in the documentation very easily). That's exactly what I am looking for! Do you think it's possible to extract the 3rd-degree derivative (i.e. the tensor which would be a 2x2x2 Array)? Thanks again for your help! |
(Note that I corrected the code of my previous answer.) The answer is yes, but you have to deal with the way you actually define the tensor. Essentially, what you are asking is all possible third order partial derivatives (third order terms), which you can see are already in julia> rr
1.0 - 2.0 x + 1.0 x² + 100.0 y² - 200.0 x² y + 100.0 x⁴ + 𝒪(‖x‖⁷)
julia> rr[3]
- 200.0 x² y
julia> typeof(ans)
TaylorSeries.HomogeneousPolynomial{Float64} I think from here, you just have to set-up the way you define the 2x2x2 tensor. |
Thank you very much! Really appreciate your help! |
I just implemented a more general partial derivation; see #164. Perhaps it is useful. Comments are welcome! |
Partial derivation has been added in #164, and merged to master. |
Shall I close this, @Goysa2? |
Hi, I do not fully understand how this package works.
I was wondering if it's possible to only extract the hessian or tensor at a specific iteration?
I used the Rosenbrock function as an example:
rosenbrock(x) = (1 - x[1])^2 + 100(x[2] - x[1]^2)^2
I understand how to get the value of (1/2)*(x-x0)^t * hessian of f at x * (x-x0) using the Taylor expand command.
(I do
taylor_expand(rosenbrock,[0.0, 0.0])[2]([1.0, 1.0])
which gives me the expected value).What I would want is only the Hessian matrix at a specific point. Or even better the tensor at a specific point.
Is it possible to do that?
Thank you very much for your help!
The text was updated successfully, but these errors were encountered: