JuliaDiff / JuliaDiff/FiniteDifferences.jl

Symmetric double counts

Open
#164 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
318
Forks
32
PR merge metrics
No merged PRs in 30d

Description

Consider: we know that the derviative of any sum of a collection of ones similar to the input.
because it is sum(xs) = x[1] + x[2] + ....

However for Symmetric it is giving 2 for the anti-diagonal on a 2x2 matrix.

using FiniteDifferences
using LinearAlgebra

grad(central_fdm(5, 1), sum, Symmetric(ones(2,2)))[1]
#== out:
2×2 Symmetric{Float64, Matrix{Float64}}:
 1.0  2.0
 2.0  1.0
 ==#


grad(central_fdm(5, 1), sum, ones(2,2))[1]
#==
2×2 Matrix{Float64}:
 1.0  1.0
 1.0  1.0
==#

Similar issues occur for prod which came up in https://github.com/JuliaDiff/ChainRules.jl/pull/335/files

Something must be wrong with out we are defining to_vec.
https://github.com/JuliaDiff/FiniteDifferences.jl/blob/266d6faa8039c382d3fbe80f8ef0b91f6a09726c/src/to_vec.jl#L90-L96

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Symmetric and dense-matrix gradient examples from the issue, then inspect src/to_vec.jl around lines 90-96, where the issue identifies the suspected to_vec behavior. Compare the handling of Symmetric inputs with the expected sum and prod derivatives; done means the anti-diagonal is no longer double-counted and the shown examples produce the expected gradients.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.