-
Notifications
You must be signed in to change notification settings - Fork 26
Supporting second derivatives #15
Comments
Off the top of my head, those are indeed the only items that strike me as being required.
Ouch, that's a bug. Nice catch! It's more than a little scary that hasn't been caught before. Looking at the tests, that seems to be something that is not even checked. Fix coming shortly. |
Oh, and it would be fine to tackle the 2nd derivative first for the case you care about. It would be nice to have the other cases too eventually, but I think we could merge your PR without them. |
Also, re I assume that the correct method to derive the corresponding expressions for the hessian is to simply derive once more the function |
In this case it's the email that was wrong, sorry about that. Here the method was tested against an analytically-exact answer. And you're right about the approach for the Hessian. |
Great - that means one less bug to worry about =) I've come across another problem that I'm not really sure what would be the best way to tackle. I've got it working for functions of one variable, but I'm not sure how to make it work for functions of more than one. Basically, the problem boils down to the fact that the approach you use for the gradient is easily generalized to second order derivatives in one direction, taking care of the hessian's diagonal, but I don't see how to evaluate the off-diagonal elements, i.e. cross-derivatives. Is there a smart way to re-use the one-dimensional case here as well, that I'm not seeing? |
Nvm - I think I figured it out. Submitting a PR in a few minutes... |
Thanks! I hadn't quite gotten here yet, glad to know that you figured it out on your own. |
What I ended up doing was to use the gradient coefficients in both the relevant dimensions, while using the hessian coefficients only for diagonal elements. It seems to pass the tests :P As #17 is now submitted, I think discussion can continue there. |
As indicated on the julia-dev mailing list I would find it immensly useful if support was implemented for cubic spline interpolation and second order derivatives. I've started working on the latter, but I keep running into things I want to ask about, so I'll try to post questions here as they pop up. When I start working on cubic spline interpolation, I'll file a separate, similar issue for that purpose.
If I've understood correctly, these are the things that need to be implemented in order to have second order derivatives:
hcoef1d::Vector{Vector{T}}
onInterpGridCoefs{T, IT<:InterpType}
. This field should work exactly as e.g.gcoef1d
, so initialization code etc for that field could in principle be straight-off duplicated.set_hessian_coordinate
that does, in principle, exactly the same thing asset_gradient_coordinate
but for the new fieldinterp_hcoefs_1d
that does basically the same thing asinterp_gcoefs_1d
, but for the hessian.valgradhess
corresponding tovalgrad
, which returns a tuplevalue, gradient, hessian
Question 1: Is my understanding correct, that if these things are implemented correctly then the existing functions for interpolation etc can do the heavy lifting for evaluating second derivatives as well?
Question 2: In lines 577-602 of src/interp.jl, three methods each for
interp_coefs_1d
andinter_gcoefs_1d
are defined, which seem to correspond to the three interpolation methods currently implemented (nearest, linear, quadratic). However, all of thegcoef
methods are for quadratic interpolation, and overwrite eachother, producing the following results:Is this intentional, or a bug? What behavior should really be implemented for the hessian? The fact that the quadratic interpolation is only regular in C1 suggests to me that second order derivation isn't even really interesting in this case - maybe I should tackle cubic interpolation first, and return to this when that is done?
Thanks a lot for your input.
The text was updated successfully, but these errors were encountered: