Giter Club home page Giter Club logo

Comments (7)

Kolaru avatar Kolaru commented on July 30, 2024

Oh no. To solve this it looks like we need to depend on ForwardDiff, possibly through package extension.

from intervalarithmetic.jl.

OlivierHnt avatar OlivierHnt commented on July 30, 2024

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.

lbenet avatar lbenet commented on July 30, 2024

A side question: what is the result for a BareInterval?

from intervalarithmetic.jl.

OlivierHnt avatar OlivierHnt commented on July 30, 2024

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.

lbenet avatar lbenet commented on July 30, 2024

Nice 😄

from intervalarithmetic.jl.

agerlach avatar agerlach commented on July 30, 2024

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.

OlivierHnt avatar OlivierHnt commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.