-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Description
I am interested in taking the derivative of a polynomial with respect to its coefficients. When the coefficients are such that all terms of order
Here is an example:
using Polynomials
using ForwardDiff
f(x) = Polynomial(x)(0.5)
∇f(x) = ForwardDiff.gradient(f, x)
true_∇f(x) = 0.5.^(0:length(x)-1)
all_params = [[1.0, 2.0, 3.0], [1.0, 0.0, 3.0], [1.0, 0.0, 0.0]]
for param in all_params
println("Params are $(param).")
println("Gradient from ForwardDiff: $(∇f(param))")
println("True gradient: $(true_∇f(param))")
println("")
end
The output from this example is below. Note the issue in the final example.
Params are [1.0, 2.0, 3.0].
Gradient from ForwardDiff: [1.0, 0.5, 0.25]
True gradient: [1.0, 0.5, 0.25]
Params are [1.0, 0.0, 3.0].
Gradient from ForwardDiff: [1.0, 0.5, 0.25]
True gradient: [1.0, 0.5, 0.25]
Params are [1.0, 0.0, 0.0].
Gradient from ForwardDiff: [1.0, 0.0, 0.0]
True gradient: [1.0, 0.5, 0.25]
Is there a way to avoid this issue?
Metadata
Metadata
Assignees
Labels
No labels