Comments (7)
Oh no. To solve this it looks like we need to depend on ForwardDiff, possibly through package extension.
from intervalarithmetic.jl.
For the forthcoming 0.22 release, I have added DiffRules.jl as a weak dependency (so this requires Julia v1.9) and defined _abs_deriv
for decorated intervals only.
This yields
julia> using IntervalArithmetic, ForwardDiff
julia> ForwardDiff.derivative(abs, interval(0)) # at 0, derivative is 0 -> trivial interval
[0.0, 0.0]_trv
julia> ForwardDiff.derivative(abs, interval(1, 2)) # 0 not in the interval -> common interval
[1.0, 1.0]_com
julia> ForwardDiff.derivative(abs, interval(0, 2)) # 0 in the interval -> trivial interval
[0.0, 1.0]_trv
julia> ForwardDiff.derivative(abs, interval(-1, 0)) # 0 in the interval -> trivial interval
[-1.0, 0.0]_trv
julia> ForwardDiff.derivative(abs, interval(-1, 1)) # 0 in the interval -> trivial interval
[-1.0, 1.0]_trv
julia> ForwardDiff.derivative(abs, interval(-2, -1)) # 0 not in the interval -> common interval
[-1.0, -1.0]_com
@agerlach, in our last discussion you mentioned how useful it is in optimisation to set the derivative of abs
to 0
at 0
. Does this correctly address the issue?
Note that the trivial decoration (trv
) means that the resulting interval carries no meaningful information anymore. It will propagate through subsequent operations:
interval(1) + ForwardDiff.derivative(abs, interval(-1, 1)) # also has `trv` decoration
[0.0, 2.0]_trv
The use of the trivial decoration was suggested to us by @lbenet after discussing with Nathalie Revol, who is involved in the IEEE Std 1788-2015.
EDIT: you can now try this, by using the PR #593.
from intervalarithmetic.jl.
A side question: what is the result for a BareInterval
?
from intervalarithmetic.jl.
It throws an error. It appears that ForwardDiff
requires a subtype of Real
:
julia> ForwardDiff.derivative(abs, bareinterval(0))
ERROR: MethodError: no method matching derivative(::typeof(abs), ::BareInterval{Float64})
Closest candidates are:
derivative(::F, ::R) where {F, R<:Real}
@ ForwardDiff ~/.julia/packages/ForwardDiff/PcZ48/src/derivative.jl:12
derivative(::Any, ::AbstractArray)
@ ForwardDiff ~/.julia/packages/ForwardDiff/PcZ48/src/derivative.jl:72
derivative(::Any, ::AbstractArray, ::Real)
@ ForwardDiff ~/.julia/packages/ForwardDiff/PcZ48/src/derivative.jl:25
...
Stacktrace:
[1] top-level scope
@ REPL[30]:1
from intervalarithmetic.jl.
Nice 😄
from intervalarithmetic.jl.
This behavior looks correct from the sub-differential perspective and correct the issue in OP.
Can you elaborate on what you mean by "decorated intervals only". I see that the returned value is decorated, but does this add requires to the input type? Also, does this lead to type-instability?
from intervalarithmetic.jl.
It requires the input to be a decorated interval, which is now simply an Interval
struct since the PR #590.
No it should not lead to type-instability because it can only accept and return an Interval
.
from intervalarithmetic.jl.
Related Issues (20)
- Failure of `Interval{T}(x::AbstractIrrational)` HOT 7
- incorrect comparison for ieee standard HOT 1
- Make sure that the documentation is correct HOT 1
- Replacing CRlibm with CORE-MATH HOT 7
- Revive `@interval`
- constants in `@constraint` not working HOT 6
- "one" on complex intervals returns wrong value HOT 1
- Plotting intervals after removal of `IntervalBox` HOT 4
- Don't write inside of the package dir
- Non-thread safe use of `setrounding` HOT 11
- Incorrect rounding for extreme irrationals HOT 1
- Avoid `convert` to `Interval` in `^` HOT 23
- `quadrant` is not thread-safe
- Finding quadrants is flawed
- Should `intersect_interval` (or `hull`) return always `trv` decoration? HOT 7
- Compatibility with NaNMath.jl? HOT 1
- Compatibility with SparseArrays HOT 2
- Investigate incorporating testing as described in arxiv.org/abs/2205.11837 HOT 2
- Clarification on 'NG' Decoration HOT 2
- Warning seriously (using Logging.jl and with user settings)
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 intervalarithmetic.jl.