Skip to content

Derivative of matrix inverse for diagonal matrix is not correct?  #490

Closed
@wwang2

Description

@wwang2

I am here to reporting some dubious results from the derivative of a matrix inversion for the diagonal matrix.

Package version: [f6369f11] ForwardDiff v0.10.14

A = [0.5 0 0 ; 0 0.5 0; 0 0 0.5]

ForwardDiff.gradient(A -> sum(inv(A)), A)

result:

3×3 Array{Float64,2}:    
 -4.0  -4.0  -4.0
  0.0  -4.0  -4.0
  0.0   0.0  -4.0

However, the analytical result should be:

-inv(A) * ones(3,3) * inv(A)

result:

3×3 Array{Float64,2}:
 -4.0  -4.0  -4.0
 -4.0  -4.0  -4.0
 -4.0  -4.0  -4.0

The Zygote gradient function

Zygote.gradient(A -> sum(inv(A)), A)[1]

result:

3×3 Array{Float64,2}:
 -4.0  -4.0  -4.0
 -4.0  -4.0  -4.0
 -4.0  -4.0  -4.0

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

    Issue actions