Giter Club home page Giter Club logo

betterexp.jl's People

Contributors

oscardssmith avatar simonbyrne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

simonbyrne

betterexp.jl's Issues

No method for ForwardDiff.Dual

Thanks for implementing this! This error sorta confuses me. I would have thought the AD would go through into the meat of your exp implementation.

ERROR: MethodError: no method matching exp(::ForwardDiff.Dual{ForwardDiff.Tag{TravelingWaveSimulationsPlotting.var"#loss#27"{TravelingWaveSimulationsPlotting.var"#sigmoid_fn#26"{Float64,Float64}},Float64},Float64,2})
You may have intended to import Base.exp
Closest candidates are:
  exp(::T) where T<:Float64 at /home/graham/.julia/packages/BetterExp/DaCOJ/src/exp.jl:108
  exp(::T) where T<:Float32 at /home/graham/.julia/packages/BetterExp/DaCOJ/src/exp.jl:131

Use a minimax approximation

You can further reduce the polynomial error using minimax polynomials instead of Taylor series. Using the Remez.jl package:

using Remez
N,D,E,X = ratfn_minimax(expm1, (-1/512,1/512), 4, 0)

and rounding the first coefficient to zero gives the coefficients:

 P = (0.0, 0.9999999999999621, 0.49999999999998357, 0.16666670640310027, 0.04166667593850114)

This has maximal approximation error on the interval [-1/512,1/512] of 1.5e-17, vs 2.1e-16 of the Taylor series.

exp at ±Inf

Thanks for working on this problem!

Not sure if you are aware, but I wanted to call your attention to a difference in behavior with Base.exp at the infinities. The following goes for both Float64 and Float32. Whereas Base.exp returns 0.0 and Inf at respectively -Inf and Inf, BetterExp.exp returns NaN in both cases.

julia> using BetterExp

# different
julia> Base.exp(-Inf)
0.0

julia> Base.exp(Inf)
Inf

julia> BetterExp.exp(-Inf)
NaN

julia> BetterExp.exp(Inf)
NaN

# this seems fine however
julia> BetterExp.exp(-999.0) == Base.exp(-999.0) == 0.0
true

julia> BetterExp.exp(999.0) == Base.exp(999.0) == Inf
true

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.