Comments (8)
On v1.8 with the latest Integrals this outputs:
julia > dlb1, dub1, dp1 = Zygote.gradient(testf, lb, ub, p)
(-0.9092974268256817, -0.27941549819892586, -0.4091435516769757)
from integrals.jl.
I'm having the same issue in Julia 1.8.5. What version of Julia and versions of Zygote and Integrals was this working under?
from integrals.jl.
The example is incorrect. Corrected:
using Integrals, Zygote
f(x, p) = sum(sin.(p * x))
lb = 1.0
ub = 3.0
p = 2.0
function testf(lb, ub, p)
prob = IntegralProblem(f, lb, ub, p)
sin(solve(prob, QuadGKJL(), reltol = 1e-3, abstol = 1e-3)[1])
end
dlb1, dub1, dp1 = Zygote.gradient(testf, lb, ub, p)
The difference is f(x, p) = sum(sin.(p * x))
instead of f(x, p) = sum(sin.(p[1] * x))
. The OP's original example fails because p[1]
fails because p
is a scalar, not a vector. I don't know why Zygote throws that weird error, but that's an issue for Zygote.
If you have an example that' supposed to work, please open a new issue.
from integrals.jl.
? that's the problem though
julia> p = [2.0]
1-element Vector{Float64}:
2.0
julia> function testf(lb, ub, p)
prob = IntegralProblem(f, lb, ub, p)
sin(solve(prob, QuadGKJL(), reltol = 1e-3, abstol = 1e-3)[1])
end
testf (generic function with 1 method)
julia> dlb1, dub1, dp1 = Zygote.gradient(testf, lb, ub, p)
ERROR: BoundsError: attempt to access 0-element Vector{Any} at index []
Stacktrace:
[1] throw_boundserror(A::Vector{Any}, I::Tuple{})
@ Base ./abstractarray.jl:744
[2] checkbounds
@ ./abstractarray.jl:709 [inlined]
[3] _getindex
@ ./abstractarray.jl:1326 [inlined]
[4] getindex
@ ./abstractarray.jl:1294 [inlined]
[5] macro expansion
@ ~/.julia/packages/Zygote/SuKWp/src/lib/lib.jl:314 [inlined]
[6] (::Zygote.Jnew{Base.MethodList, Vector{Any}, false})(Δ::Nothing)
@ Zygote ~/.julia/packages/Zygote/SuKWp/src/lib/lib.jl:308
also Zygote can handle this:
julia> p = [2.0]
1-element Vector{Float64}:
2.0
julia> Zygote.gradient(f, 30, p)
(-1.9048259608303126, [-28.57238941245469])
julia> p = 2.0
2.0
julia> Zygote.gradient(f, 30, p)
(-1.9048259608303126, -28.57238941245469)
from integrals.jl.
Hi All, Thanks for the help with this.
Here is a simple example:
`
foo(x, p) = p + x
lb = 1.0
ub = 3.0
p = 2.0
function testf(lb, ub, p)
prob = IntegralProblem(foo, lb, ub, p)
solve(prob, QuadGKJL(), reltol = 1e-3, abstol = 1e-3)[1]
end
dlb1, dub1, dp1 = Zygote.gradient(testf, lb, ub, p)
`
I get "ERROR: BoundsError: attempt to access 0-element Vector{Any} at index []"
from integrals.jl.
Also, the example at
https://docs.juliahub.com/Integrals/QIwht/3.1.1/tutorials/differentiating_integrals/
creates the same error for Zygote, but works fine for ForwardDiff and and FiniteDiff (I had to replace CubaCuhre with HCubatureJL). This is true using either Integrals 3.1.1 (which is the version listed at that page) and 3.7.
from integrals.jl.
@ArnoStrouwen does that already have an issue?
from integrals.jl.
I think it is this issue #99?
from integrals.jl.
Related Issues (20)
- keyword arguments passed to specific solvers HOT 6
- Integrals with lb > ub HOT 1
- More types of infinity transformations HOT 2
- Add tests FastGaussQuadrature + AD
- Method definition overwrite of `solve(SciMLBase.IntegralProblem`.
- Integration over general domains
- Nested ForwardDiff.jacobian doesn't work for `AbstractCubatureJLAAlgorithm` subtypes
- Solving coupled system of linear Volterra integral equations of the second kind HOT 2
- Multiple/nested integration error tolerances HOT 2
- Broken inplace integrand for HCubatureJL HOT 8
- Quadrature routines for pre-sampled data HOT 3
- It would be nice to have a `progress` keyword for time estimation HOT 7
- Improve docstrings
- Inconsistent IntegralsCubature Interface
- Example from the first tutorial is broken HOT 5
- Interface error for VEGAS from [email protected]
- Warp MCIntegration.jl
- Issue when Nesting Integrals without Explicit Floats
- Factor out MonteCarloIntegration.jl into extension package HOT 2
- BoundsError: attempt to access Float64 at index [2] when `pi` is passed as limit HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from integrals.jl.