Skip to content

use HessianConfig to calculate gradients? #734

Open
@longemen3000

Description

@longemen3000

Hello,

Recently i came across with a problem in which already had a hessian cache, (HessianConfig + DiffResults.HessianResult), but it seems there aren't any methods for calculating for using HessianConfig (and HessianResult) when calculating gradients (of the same function with the same number and type of arguments).

I did this dirty hack to allow calculating gradients with HessianConfig + HessianResult:

hresult,hconfig = cache    
h_jconfig = hconfig.jacobian_config
seeds = h_jconfig.seeds
duals = h_jconfig.duals[1]
gconfig = ForwardDiff.GradientConfig{Nothing,eltype(aux),length(seeds),typeof(duals)}(seeds,duals)
gresult = ForwardDiff.MutableDiffResult(result.value,(result.derivs[1],))

It works for me, but it could be generalized (by passing the adequate function argument, for example)

It would be much easier to just do ForwardDiff.gradient!(hresult,f,x,hconfig) instead.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @longemen3000

        Issue actions

          use `HessianConfig` to calculate gradients? · Issue #734 · JuliaDiff/ForwardDiff.jl