Complex Differentiation
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 30/100
Direzione di ricerca
Inizia esaminando gli entry point menzionati di ForwardDiff derivative, can_dual e Partials e i casi di test esistenti. Verifica se la sostituzione dei vincoli Real con Number supporta le funzioni complesse analitiche rifiutando al contempo le operazioni non analitiche. Il lavoro è completo quando i test esistenti passano e i test aggiunti per le funzioni complesse coprono sia le derivate riuscite sia gli errori attesi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I'd really like to be able to differentiate complex functions with ForwardDiff. For almost all analytic functions, the derivative can be taken in the same way as in the real case, so Julia's dynamic type system should make complex diferentiation work out of the box. It seems to me that the only reason it doesn't is because many functions in ForwardDiff accept Real arguments, but if we simply changed these to accept Numbers then we should be most of the way there. Functions that are not analytic such as real, imag, abs, conj, abs2, reim should all return errors when their derivatives are taken at a complex input. For example, consider these two functions:
f(z) = z^2
g(z) = Complex(real(z)^2 - imag(z)^2, 2 * real(z) * imag(z))
These functions are equal and both analytic, but it is not obvious by looking at g that it is analytic. In my opinion, it would be acceptable if derivative(f, im) worked while derivative(g, im) threw an error.
I already started experimenting with this. I copied the definitions of several functions in ForwardDiff and just replaced Real with Complex, like so:
ForwardDiff.can_dual(::Type{Complex{T}}) where {T<:Real} = true
@inline function ForwardDiff.derivative(f::F, x::R) where {F,R<:Complex}
T = typeof(Tag(f, R))
return extract_derivative(T, f(Dual{T}(x, one(x))))
end
@inline function Base.:*(partials::Partials, x::Complex)
return Partials(scale_tuple(partials.values, x))
end
@inline function Base.:/(partials::Partials, x::Complex)
return Partials(div_tuple_by_scalar(partials.values, x))
end
@inline Base.:*(x::Complex, partials::Partials) = partials * x
@inline Base.:*(partials::Partials{0,V}, x::Complex) where {V} = Partials{0,promote_type(V, typeof(x))}(tuple())
@inline Base.:*(x::Complex, partials::Partials{0,V}) where {V} = Partials{0,promote_type(V, typeof(x))}(tuple())
@inline Base.:/(partials::Partials{0,V}, x::Complex) where {V} = Partials{0,promote_type(V, typeof(x))}(tuple())
This was enough for me to correctly differentiate sin. I expect that if we just do this throughout ForwardDiff (and replace the Real definitions with Number, instead of adding Complex definitions like I did here), then we'll be most of the way there. Here's my plan:
- Find and replace
RealwithNumberthroughout the repository - Tweak things until all the test cases pass
- Add test cases for complex functions
I'm tempted to actually do this and make a pull request as soon as I have some time to do so.
- Lingua principale
- Julia
- Stelle
- 80
- Fork
- 28
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JuliaDiff/DualNumbers.jl
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
JuliaDiff/DualNumbers.jl#94 · 2 commenti ·
-
div() and rem()Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
JuliaDiff/DualNumbers.jl#93 ·
-
bitmix not definedAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
JuliaDiff/DualNumbers.jl#88 ·
-
Should we export ϵ ≡ ε?Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
JuliaDiff/DualNumbers.jl#87 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
JuliaDiff/DualNumbers.jl#81 ·
Tutte le issue di JuliaDiff/DualNumbers.jl
Issue simili
-
`ShallowWaterModel` allocates ~9 KiB per grid point per RK3 stage on the CPUForse già presa @ali-ramadhan l’ha presa oggi. Apertaperformance 🏍️
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
CliMA/Oceananigans.jl#6421 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
NCAR/musica#1118 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
`AMSGrad` state starts at `epsilon` instead of zero, so zero gradients move parameters and small gradients are dampedForse già presa @parth-patel010 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
FluxML/Optimisers.jl#247 · 1 commento ·
-
README should say that row and column order must matchForse già presa @SAUMYARSH l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
OpenFUSIONToolkit/GPEC#644 ·
I maintainer di solito rispondono entro 3 giorni