confused by this root finding example
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 32/100
Línea de trabajo
Reproduce los puntos de entrada MWE g1, g2 y ForwardDiff.derivative utilizando las llamadas a Roots, ForwardDiff y FiniteDiff mostradas en la issue. Compara cómo afectan los dos límites de find_zero a la diferenciación y determina si las derivadas diferentes son esperables; se considera terminado cuando se documenta la causa o se identifica una corrección específica.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I have some code which calls a root finding step, via the Roots package that I'd like to be able to differentiate. It appears that whether ForwardDiff "works" in this setting depends on some subtlety that I don't quite understand.
For an MWE, consider finding the (unique) root of the cubic function f(x, k) = (x-k)^3 which has a root at x = k. Let g1(k) = find_zero(x -> f(x, k), [k-1.0,k+1.0]) and similarly let g2(k) = find_zero(x -> f(x, k), [10.0,+10.0]). Note that for values of k between -10 to +10, g1(k) == g2(k). In this range, the only difference between g1 and g2 is that the root finding step in g1 is "aware" of the value of k to look for, via the bounds I have provided, whereas it is ignorant of them in g2. For values of k in this range, the derivatives of g1 and g2 are identical, and equal to 1.0. However, I am seeing that ForwardDiff thinks the derivative of g2 is zero, while it finds the derivative of g1 to be 1.0:
Using Roots, ForwardDiff, FiniteDiff
g0(x,k) = (x-k)^3
g1(k) = find_zero(x -> g0(x,k), [-10.0, +10.0])
g2(k) = find_zero(x -> g0(x,k), [-1.0 * k, +1.0 * k])
Julia reports that the functions are the same, and do vary with the input in the expected way:
ulia> g1(3)
3.0
julia> g2(3)
3.0
julia> g1(4)
4.0
julia> g2(4)
4.0
However, the ForwardDiff gradients are different:
julia> ForwardDiff.derivative(g1, 3.0)
0.0
julia> ForwardDiff.derivative(g2, 3.0)
1.0
Note that FiniteDiff works fine here (up to numerical approximation):
julia> FiniteDiff.finite_difference_derivative(g1, 3.0)
0.9999999999991082
julia> FiniteDiff.finite_difference_derivative(g2, 3.0)
0.9999999999991082
Thanks in advance for any suggestions the ForwardDiff team has in understanding this difference.
- Lenguaje dominante
- Julia
- Estrellas
- 1k
- Forks
- 162
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de JuliaDiff/ForwardDiff.jl
-
missing floatmin, floatmax, and issubnormal for DualPosiblemente ocupada @devmotion la tomó hace 16 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
JuliaDiff/ForwardDiff.jl#852 · 6 comentarios ·
-
`fma` and `muladd` ignore NaN-safe modePosiblemente ocupada @devmotion la tomó hace 2 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
JuliaDiff/ForwardDiff.jl#860 ·
-
Enable NaN-safe mode by defaultPosiblemente ocupada @devmotion la tomó hace 4 días. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
JuliaDiff/ForwardDiff.jl#857 · 1 reacción ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
JuliaDiff/ForwardDiff.jl#854 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 75/100
JuliaDiff/ForwardDiff.jl#849 ·
Todos los issues de JuliaDiff/ForwardDiff.jl
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
JuliaGPU/KernelAbstractions.jl#897 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
oscar-system/GAP.jl#1455 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
JuliaAI/MLJTransforms.jl#85 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
SciML/OrdinaryDiffEq.jl#4875 ·
Los mantenedores suelen responder en 4 días