JuliaMath / JuliaMath/QuadGK.jl
Autodiff of `quadgk`
- Dominant language
- Julia
- Stars
- 314
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
Thank you for a great package!
I would like to use Zygote on `quadgk` but below is a self-contained example, where it does not work because `quadgk` calls `setindex!`. Can I do anything to work around this? I coded up a small example of differentiating `quadgk` of a constant function and it did work so it seems that there is hope for Zygote and QuadGK to play together nicely.
```
using Zygote, QuadGK
"P(0 2.
return 0.
elseif x < 1.
return exp(c)*(x-c)
elseif x < 1. + c
return exp(c)*(1-c)
else
return exp(c)*(2-x)
end
end
function D(c)
exp(c)*(1-c)
end
function W(c1, c2)
val, acc = quadgk(t -> F(c1, t)*f(c2, t), c1, 2)
val
end
function prob_of_win(c1, c2)
((1-D(c1))*D(c2) + W(c2, c1))/(D(c1) + D(c2) - D(c1)*D(c2))
end
gradient(prob_of_win, 0.25, 0.25) # ERROR: Mutating arrays is not supported -- called setindex!(Vector{QuadGK.Segment{Float64, Float64, Float64}}, ...)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.