Giter Site home page Giter Site logo

Comments (9)

mohamed82008 avatar mohamed82008 commented on July 20, 2024 1

Done, #20. The main improvement came from replacing log(1/x) with -log(x) thus eliminating an unnecessary division. New benchmarks:

julia> @btime invlink_simplex($y);
39.384 μs (1 allocation: 7.94 KiB)

julia> @btime invlink($d, $y);
39.020 μs (1 allocation: 7.94 KiB)                                                                                                                                                                                                                                                                                          

from bijectors.jl.

cpfiffer avatar cpfiffer commented on July 20, 2024

It looks to me like it's stable, but Mohamed the Master of Type Stability probably has a far better eye for that than me.

from bijectors.jl.

mohamed82008 avatar mohamed82008 commented on July 20, 2024

Hi @trappmartin !

Your implementation looks type stable but I think we will run into numerical issues when inverting this. The main numerical stability problems were from link, invlink was just modified accordingly to be its inverse. I do think however there is a performance issue in Bijectors. I looked into it, and it seems the @debug sentences are causing some type instability. When removing them, and benchmarking I get:

julia> @btime invlink_simplex($y);
39.384 μs (1 allocation: 7.94 KiB)

julia> @btime invlink($d, $y);
43.395 μs (1 allocation: 7.94 KiB)

I assume the extra time is from the extra epsilon arithmetic that is done. The real difference is probably more when you use @inbounds. So I guess what it boils down to is if we are willing to throw away the inverse property between link and invlink, then we can gain some extra performance with your implementation of invlink.

from bijectors.jl.

mohamed82008 avatar mohamed82008 commented on July 20, 2024

I will also make a PR to fix the @debug issues.

from bijectors.jl.

trappmartin avatar trappmartin commented on July 20, 2024

Sounds good. I wasn’t aiming for performance with my implementation but was surprised that the invlink is so much slower.

from bijectors.jl.

trappmartin avatar trappmartin commented on July 20, 2024

Maybe as a side note, it might be good to have internal functions that do not require to pass a distribution object. This would allow a knowledgeable user to use the transformations without instantiating a Distributions object. Similar to the StatsFuns package.

from bijectors.jl.

trappmartin avatar trappmartin commented on July 20, 2024

One last note. I think the invlink should be at least as fast as my code as I don’t optimise anything and invlink looks rather tuned. Your test shows that even after removing the @debug the invlink is still slower. I guess we should think about improving the code as this gets called frequently during sampling.

from bijectors.jl.

mohamed82008 avatar mohamed82008 commented on July 20, 2024

@trappmartin The slowdown is from the epsilons to make invlink a proper inverse of the numerically stable link. Are you proposing making invlink as fast as possible even if it is not a good inverse of the numerically stable link?

from bijectors.jl.

trappmartin avatar trappmartin commented on July 20, 2024

No, I propose we try to get to code faster while keeping it numerical stable.

from bijectors.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.